@@ -217,6 +217,8 @@ struct xc_sr_save_arrays {
xen_pfn_t mfns[MAX_BATCH_SIZE];
/* write_batch: Types of the batch pfns. */
xen_pfn_t types[MAX_BATCH_SIZE];
+ /* write_batch: Errors from attempting to map the gfns. */
+ int errors[MAX_BATCH_SIZE];
};
struct xc_sr_restore_arrays {
@@ -92,7 +92,7 @@ static int write_batch(struct xc_sr_context *ctx)
void *guest_mapping = NULL;
void **guest_data = NULL;
void **local_pages = NULL;
- int *errors = NULL, rc = -1;
+ int *errors = ctx->save.m->errors, rc = -1;
unsigned int i, p, nr_pages = 0, nr_pages_mapped = 0;
unsigned int nr_pfns = ctx->save.nr_batch_pfns;
void *page, *orig_page;
@@ -105,8 +105,6 @@ static int write_batch(struct xc_sr_context *ctx)
assert(nr_pfns != 0);
- /* Errors from attempting to map the gfns. */
- errors = malloc(nr_pfns * sizeof(*errors));
/* Pointers to page data to send. Mapped gfns or local allocations. */
guest_data = calloc(nr_pfns, sizeof(*guest_data));
/* Pointers to locally allocated pages. Need freeing. */
@@ -114,7 +112,7 @@ static int write_batch(struct xc_sr_context *ctx)
/* iovec[] for writev(). */
iov = malloc((nr_pfns + 4) * sizeof(*iov));
- if ( !errors || !guest_data || !local_pages || !iov )
+ if ( !guest_data || !local_pages || !iov )
{
ERROR("Unable to allocate arrays for a batch of %u pages",
nr_pfns);
@@ -271,7 +269,6 @@ static int write_batch(struct xc_sr_context *ctx)
free(iov);
free(local_pages);
free(guest_data);
- free(errors);
return rc;
}
Remove allocation from hotpath, move errors array into preallocated space. Signed-off-by: Olaf Hering <olaf@aepfle.de> --- tools/libs/guest/xg_sr_common.h | 2 ++ tools/libs/guest/xg_sr_save.c | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-)