|
|
a83cc2 |
From 5e8f99ea87409e1423c2e1c5e445003cf4a032a9 Mon Sep 17 00:00:00 2001
|
|
|
a83cc2 |
From: Eric Blake <eblake@redhat.com>
|
|
|
a83cc2 |
Date: Fri, 6 Aug 2021 15:07:48 -0400
|
|
|
a83cc2 |
Subject: [PATCH 25/39] qemu-img: Fail fast on convert --bitmaps with
|
|
|
a83cc2 |
inconsistent bitmap
|
|
|
a83cc2 |
MIME-Version: 1.0
|
|
|
a83cc2 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a83cc2 |
Content-Transfer-Encoding: 8bit
|
|
|
a83cc2 |
|
|
|
a83cc2 |
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
a83cc2 |
RH-MergeRequest: 35: Synchronize with RHEL-AV 8.5 release 28 to RHEL 9
|
|
|
a83cc2 |
RH-Commit: [2/4] 3fd8d357c3a365d4bc142b3d339745e5b15c5894 (mrezanin/centos-src-qemu-kvm)
|
|
|
a83cc2 |
RH-Bugzilla: 1957194
|
|
|
a83cc2 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
a83cc2 |
|
|
|
a83cc2 |
Waiting until the end of the convert operation (a potentially
|
|
|
a83cc2 |
time-consuming task) to finally detect that we can't copy a bitmap is
|
|
|
a83cc2 |
bad, comparing to failing fast up front. Furthermore, this prevents
|
|
|
a83cc2 |
us from leaving a file behind with a bitmap that is not marked as
|
|
|
a83cc2 |
inconsistent even though it does not have sane contents.
|
|
|
a83cc2 |
|
|
|
a83cc2 |
This fixes the problems exposed in the previous patch to the iotest:
|
|
|
a83cc2 |
it adds a fast failure up front, and even if we don't fail early, it
|
|
|
a83cc2 |
ensures that any bitmap we add but do not properly populate is removed
|
|
|
a83cc2 |
again rather than left behind incomplete.
|
|
|
a83cc2 |
|
|
|
a83cc2 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
a83cc2 |
Message-Id: <20210709153951.2801666-3-eblake@redhat.com>
|
|
|
a83cc2 |
[eblake: add a hint to the warning message, simplify name computation]
|
|
|
a83cc2 |
Reviewed-by: Nir Soffer <nsoffer@redhat.com>
|
|
|
a83cc2 |
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
|
|
|
a83cc2 |
(cherry picked from commit 74a4320f30632fa539507861b3835698282e462e)
|
|
|
a83cc2 |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
a83cc2 |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
a83cc2 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
a83cc2 |
---
|
|
|
a83cc2 |
qemu-img.c | 29 +++++++++++++++++--
|
|
|
a83cc2 |
tests/qemu-iotests/tests/qemu-img-bitmaps | 3 +-
|
|
|
a83cc2 |
tests/qemu-iotests/tests/qemu-img-bitmaps.out | 21 ++------------
|
|
|
a83cc2 |
3 files changed, 30 insertions(+), 23 deletions(-)
|
|
|
a83cc2 |
|
|
|
a83cc2 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
a83cc2 |
index babb5573ab..7684684bfa 100644
|
|
|
a83cc2 |
--- a/qemu-img.c
|
|
|
a83cc2 |
+++ b/qemu-img.c
|
|
|
a83cc2 |
@@ -2098,6 +2098,29 @@ static int convert_do_copy(ImgConvertState *s)
|
|
|
a83cc2 |
return s->ret;
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
|
|
|
a83cc2 |
+/* Check that bitmaps can be copied, or output an error */
|
|
|
a83cc2 |
+static int convert_check_bitmaps(BlockDriverState *src)
|
|
|
a83cc2 |
+{
|
|
|
a83cc2 |
+ BdrvDirtyBitmap *bm;
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
+ if (!bdrv_supports_persistent_dirty_bitmap(src)) {
|
|
|
a83cc2 |
+ error_report("Source lacks bitmap support");
|
|
|
a83cc2 |
+ return -1;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+ FOR_EACH_DIRTY_BITMAP(src, bm) {
|
|
|
a83cc2 |
+ if (!bdrv_dirty_bitmap_get_persistence(bm)) {
|
|
|
a83cc2 |
+ continue;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+ if (bdrv_dirty_bitmap_inconsistent(bm)) {
|
|
|
a83cc2 |
+ error_report("Cannot copy inconsistent bitmap '%s'",
|
|
|
a83cc2 |
+ bdrv_dirty_bitmap_name(bm));
|
|
|
a83cc2 |
+ error_printf("Try 'qemu-img bitmap --remove' to delete it\n");
|
|
|
a83cc2 |
+ return -1;
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+ }
|
|
|
a83cc2 |
+ return 0;
|
|
|
a83cc2 |
+}
|
|
|
a83cc2 |
+
|
|
|
a83cc2 |
static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst)
|
|
|
a83cc2 |
{
|
|
|
a83cc2 |
BdrvDirtyBitmap *bm;
|
|
|
a83cc2 |
@@ -2124,6 +2147,7 @@ static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst)
|
|
|
a83cc2 |
&err;;
|
|
|
a83cc2 |
if (err) {
|
|
|
a83cc2 |
error_reportf_err(err, "Failed to populate bitmap %s: ", name);
|
|
|
a83cc2 |
+ qmp_block_dirty_bitmap_remove(dst->node_name, name, NULL);
|
|
|
a83cc2 |
return -1;
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
@@ -2549,9 +2573,8 @@ static int img_convert(int argc, char **argv)
|
|
|
a83cc2 |
ret = -1;
|
|
|
a83cc2 |
goto out;
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
- if (!bdrv_supports_persistent_dirty_bitmap(blk_bs(s.src[0]))) {
|
|
|
a83cc2 |
- error_report("Source lacks bitmap support");
|
|
|
a83cc2 |
- ret = -1;
|
|
|
a83cc2 |
+ ret = convert_check_bitmaps(blk_bs(s.src[0]));
|
|
|
a83cc2 |
+ if (ret < 0) {
|
|
|
a83cc2 |
goto out;
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
}
|
|
|
a83cc2 |
diff --git a/tests/qemu-iotests/tests/qemu-img-bitmaps b/tests/qemu-iotests/tests/qemu-img-bitmaps
|
|
|
a83cc2 |
index 409c4497a3..09c3d395d1 100755
|
|
|
a83cc2 |
--- a/tests/qemu-iotests/tests/qemu-img-bitmaps
|
|
|
a83cc2 |
+++ b/tests/qemu-iotests/tests/qemu-img-bitmaps
|
|
|
a83cc2 |
@@ -140,11 +140,10 @@ $QEMU_IO -c abort "$TEST_IMG" 2>/dev/null
|
|
|
a83cc2 |
$QEMU_IMG bitmap --add "$TEST_IMG" b4
|
|
|
a83cc2 |
$QEMU_IMG bitmap --remove "$TEST_IMG" b1
|
|
|
a83cc2 |
_img_info --format-specific | _filter_irrelevant_img_info
|
|
|
a83cc2 |
+# Proof that we fail fast if bitmaps can't be copied
|
|
|
a83cc2 |
echo
|
|
|
a83cc2 |
$QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG" "$TEST_IMG.copy" &&
|
|
|
a83cc2 |
echo "unexpected success"
|
|
|
a83cc2 |
-# Bug - even though we failed at conversion, we left a file around with
|
|
|
a83cc2 |
-# a bitmap marked as not corrupt
|
|
|
a83cc2 |
TEST_IMG=$TEST_IMG.copy _img_info --format-specific \
|
|
|
a83cc2 |
| _filter_irrelevant_img_info
|
|
|
a83cc2 |
|
|
|
a83cc2 |
diff --git a/tests/qemu-iotests/tests/qemu-img-bitmaps.out b/tests/qemu-iotests/tests/qemu-img-bitmaps.out
|
|
|
a83cc2 |
index 543b028da6..1e32833bf1 100644
|
|
|
a83cc2 |
--- a/tests/qemu-iotests/tests/qemu-img-bitmaps.out
|
|
|
a83cc2 |
+++ b/tests/qemu-iotests/tests/qemu-img-bitmaps.out
|
|
|
a83cc2 |
@@ -144,22 +144,7 @@ Format specific information:
|
|
|
a83cc2 |
granularity: 65536
|
|
|
a83cc2 |
corrupt: false
|
|
|
a83cc2 |
|
|
|
a83cc2 |
-qemu-img: Failed to populate bitmap b0: Bitmap 'b0' is inconsistent and cannot be used
|
|
|
a83cc2 |
-Try block-dirty-bitmap-remove to delete this bitmap from disk
|
|
|
a83cc2 |
-image: TEST_DIR/t.IMGFMT.copy
|
|
|
a83cc2 |
-file format: IMGFMT
|
|
|
a83cc2 |
-virtual size: 10 MiB (10485760 bytes)
|
|
|
a83cc2 |
-cluster_size: 65536
|
|
|
a83cc2 |
-Format specific information:
|
|
|
a83cc2 |
- bitmaps:
|
|
|
a83cc2 |
- [0]:
|
|
|
a83cc2 |
- flags:
|
|
|
a83cc2 |
- name: b0
|
|
|
a83cc2 |
- granularity: 65536
|
|
|
a83cc2 |
- [1]:
|
|
|
a83cc2 |
- flags:
|
|
|
a83cc2 |
- [0]: auto
|
|
|
a83cc2 |
- name: b4
|
|
|
a83cc2 |
- granularity: 65536
|
|
|
a83cc2 |
- corrupt: false
|
|
|
a83cc2 |
+qemu-img: Cannot copy inconsistent bitmap 'b0'
|
|
|
a83cc2 |
+Try 'qemu-img bitmap --remove' to delete it
|
|
|
a83cc2 |
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT.copy': Could not open 'TEST_DIR/t.IMGFMT.copy': No such file or directory
|
|
|
a83cc2 |
*** done
|
|
|
a83cc2 |
--
|
|
|
a83cc2 |
2.27.0
|
|
|
a83cc2 |
|