aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Drobyshev <andrey.drobyshev@virtuozzo.com>2023-09-19 19:57:57 +0300
committerMichael Tokarev <mjt@tls.msk.ru>2023-11-02 15:04:24 +0300
commit1e67bd7c217eac41518b752074125be89f70b81d (patch)
tree1635230e4df1ccc2bb162cb15135cfe0b1e3440d
parent6367e823caead19cfbe5ba0724a93691b65c257d (diff)
qemu-img: rebase: stop when reaching EOF of old backing file
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> Message-ID: <20230919165804.439110-2-andrey.drobyshev@virtuozzo.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> (cherry picked from commit 8b097fd6b06ec295faefd4f30f96f8709abc9605) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
-rw-r--r--qemu-img.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/qemu-img.c b/qemu-img.c
index a9b3a8103c..2c32d9da4e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3753,6 +3753,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
@@ -3765,9 +3767,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;
+ }
}
/*