|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] libs/guest: Avoids using 2 indexes in process_page_data()
commit 42ef7f610653d743bf8c04f9bbe26239148ac84f
Author: Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
AuthorDate: Fri Jun 19 14:04:52 2026 +0100
Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Jul 8 15:35:45 2026 +0100
libs/guest: Avoids using 2 indexes in process_page_data()
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>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Acked-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
tools/libs/guest/xg_sr_restore.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_restore.c
index e148fc594a..458eaa5992 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 int nr_pages = 0;
if ( !mfns || !map_errs )
{
@@ -279,12 +277,17 @@ static int process_page_data(struct xc_sr_context *ctx,
unsigned int count,
goto err;
}
- for ( i = 0; i < count; ++i )
+ for ( unsigned int 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 +305,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 int 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 +337,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;
}
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |