|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 7/9] libs/guest: avoids using 2 indexes
From: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
Simplify code, after the first scan of the various arrays we don't need to
keep original types and PFNs but only the ones having data.
Signed-off-by: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
---
tools/libs/guest/xg_sr_restore.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_restore.c
index e148fc594a73..fb46142d8729 100644
--- a/tools/libs/guest/xg_sr_restore.c
+++ b/tools/libs/guest/xg_sr_restore.c
@@ -260,9 +260,7 @@ static int process_page_data(struct xc_sr_context *ctx,
unsigned int count,
int *map_errs = malloc(count * sizeof(*map_errs));
int rc;
void *mapping = NULL, *guest_page = NULL;
- unsigned int i, /* i indexes the pfns from the record. */
- j, /* j indexes the subset of pfns we decide to map. */
- nr_pages = 0;
+ unsigned nr_pages;
if ( !mfns || !map_errs )
{
@@ -279,12 +277,18 @@ static int process_page_data(struct xc_sr_context *ctx,
unsigned int count,
goto err;
}
- for ( i = 0; i < count; ++i )
+ nr_pages = 0;
+ for ( unsigned i = 0; i < count; ++i )
{
ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]);
- if ( page_type_has_stream_data(types[i]) )
- mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]);
+ if ( !page_type_has_stream_data(types[i]) )
+ continue;
+
+ mfns[nr_pages] = ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]);
+ pfns[nr_pages] = pfns[i];
+ types[nr_pages] = types[i];
+ nr_pages++;
}
/* Nothing to do? */
@@ -302,16 +306,13 @@ static int process_page_data(struct xc_sr_context *ctx,
unsigned int count,
goto err;
}
- for ( i = 0, j = 0; i < count; ++i )
+ for ( unsigned i = 0; i < nr_pages; ++i )
{
- if ( !page_type_has_stream_data(types[i]) )
- continue;
-
- if ( map_errs[j] )
+ if ( map_errs[i] )
{
rc = -1;
ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32")
failed with %d",
- pfns[i], mfns[j], types[i], map_errs[j]);
+ pfns[i], mfns[i], types[i], map_errs[i]);
goto err;
}
@@ -337,7 +338,6 @@ static int process_page_data(struct xc_sr_context *ctx,
unsigned int count,
memcpy(guest_page, page_data, PAGE_SIZE);
}
- ++j;
guest_page += PAGE_SIZE;
page_data += PAGE_SIZE;
}
--
2.54.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |