[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/8] qemu-img: rebase: stop when reaching EOF of old backing f
From: |
Andrey Drobyshev |
Subject: |
[PATCH v2 1/8] qemu-img: rebase: stop when reaching EOF of old backing file |
Date: |
Fri, 15 Sep 2023 19:20:09 +0300 |
In case when we're rebasing within one backing chain, and when target image
is larger than old backing file, bdrv_is_allocated_above() ends up setting
*pnum = 0. As a result, target offset isn't getting incremented, and we
get stuck in an infinite for loop. Let's detect this case and proceed
further down the loop body, as the offsets beyond the old backing size need
to be explicitly zeroed.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
---
qemu-img.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/qemu-img.c b/qemu-img.c
index a48edb7101..50660ba920 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3805,6 +3805,8 @@ static int img_rebase(int argc, char **argv)
}
if (prefix_chain_bs) {
+ uint64_t bytes = n;
+
/*
* If cluster wasn't changed since prefix_chain, we don't need
* to take action
@@ -3817,9 +3819,18 @@ static int img_rebase(int argc, char **argv)
strerror(-ret));
goto out;
}
- if (!ret) {
+ if (!ret && n) {
continue;
}
+ if (!n) {
+ /*
+ * If we've reached EOF of the old backing, it means that
+ * offsets beyond the old backing size were read as zeroes.
+ * Now we will need to explicitly zero the cluster in
+ * order to preserve that state after the rebase.
+ */
+ n = bytes;
+ }
}
/*
--
2.39.3
- [PATCH v2 0/8] qemu-img: rebase: add compression support, Andrey Drobyshev, 2023/09/15
- [PATCH v2 7/8] qemu-img: add compression option to rebase subcommand, Andrey Drobyshev, 2023/09/15
- [PATCH v2 2/8] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size, Andrey Drobyshev, 2023/09/15
- [PATCH v2 1/8] qemu-img: rebase: stop when reaching EOF of old backing file,
Andrey Drobyshev <=
- [PATCH v2 8/8] iotests: add tests for "qemu-img rebase" with compression, Andrey Drobyshev, 2023/09/15
- [PATCH v2 4/8] qemu-img: add chunk size parameter to compare_buffers(), Andrey Drobyshev, 2023/09/15
- [PATCH v2 5/8] qemu-img: rebase: avoid unnecessary COW operations, Andrey Drobyshev, 2023/09/15