From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH v6 15/16] libxc/restore: introduce setup() and cleanup() on restore Date: Thu, 14 May 2015 10:01:23 +0100 Message-ID: <55546463.8060202@citrix.com> References: <1431593718-4828-1-git-send-email-yanghy@cn.fujitsu.com> <1431593718-4828-16-git-send-email-yanghy@cn.fujitsu.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1431593718-4828-16-git-send-email-yanghy@cn.fujitsu.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Yang Hongyang , xen-devel@lists.xen.org Cc: wei.liu2@citrix.com, ian.campbell@citrix.com, wency@cn.fujitsu.com, guijianfeng@cn.fujitsu.com, yunhong.jiang@intel.com, eddie.dong@intel.com, rshriram@cs.ubc.ca, ian.jackson@eu.citrix.com List-Id: xen-devel@lists.xenproject.org On 14/05/15 09:55, Yang Hongyang wrote: > introduce setup() and cleanup() which subsume the > ctx->restore.ops.{setup,cleanup}() calls and also > do memory alloc/free. > > Signed-off-by: Yang Hongyang > CC: Andrew Cooper > CC: Ian Campbell > CC: Ian Jackson > CC: Wei Liu Reviewed-by: Andrew Cooper > --- > tools/libxc/xc_sr_restore.c | 48 ++++++++++++++++++++++++++++++++------------- > 1 file changed, 34 insertions(+), 14 deletions(-) > > diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c > index 8022c3d..2345f66 100644 > --- a/tools/libxc/xc_sr_restore.c > +++ b/tools/libxc/xc_sr_restore.c > @@ -510,6 +510,38 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) > return rc; > } > > +static int setup(struct xc_sr_context *ctx) > +{ > + xc_interface *xch = ctx->xch; > + int rc; > + > + rc = ctx->restore.ops.setup(ctx); > + if ( rc ) > + goto err; > + > + ctx->restore.max_populated_pfn = (32 * 1024 / 4) - 1; > + ctx->restore.populated_pfns = bitmap_alloc( > + ctx->restore.max_populated_pfn + 1); > + if ( !ctx->restore.populated_pfns ) > + { > + ERROR("Unable to allocate memory for populated_pfns bitmap"); > + rc = -1; > + goto err; > + } > + > + err: > + return rc; > +} > + > +static void cleanup(struct xc_sr_context *ctx) > +{ > + xc_interface *xch = ctx->xch; > + > + free(ctx->restore.populated_pfns); > + if ( ctx->restore.ops.cleanup(ctx) ) > + PERROR("Failed to clean up"); > +} > + > #ifdef XG_LIBXL_HVM_COMPAT > extern int read_qemu(struct xc_sr_context *ctx); > #endif > @@ -524,19 +556,10 @@ static int restore(struct xc_sr_context *ctx) > > IPRINTF("Restoring domain"); > > - rc = ctx->restore.ops.setup(ctx); > + rc = setup(ctx); > if ( rc ) > goto err; > > - ctx->restore.max_populated_pfn = (32 * 1024 / 4) - 1; > - ctx->restore.populated_pfns = bitmap_alloc( > - ctx->restore.max_populated_pfn + 1); > - if ( !ctx->restore.populated_pfns ) > - { > - ERROR("Unable to allocate memory for populated_pfns bitmap"); > - goto err; > - } > - > do > { > rc = read_record(ctx, &rec); > @@ -571,10 +594,7 @@ static int restore(struct xc_sr_context *ctx) > PERROR("Restore failed"); > > done: > - free(ctx->restore.populated_pfns); > - rc = ctx->restore.ops.cleanup(ctx); > - if ( rc ) > - PERROR("Failed to clean up"); > + cleanup(ctx); > > if ( saved_rc ) > {