[PATCH v6 17/25] parallels: do not trust the bitmaps of an image which was not closed
"Denis V. Lunev" <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu.block,gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
From: Denis V. Lunev <[email protected]> The inuse magic in the header says that the image was not closed correctly. The bitmaps stored in the Format Extension are then stale by definition: they were written by the last inactivation, and every write which happened after it is missing from them. Nothing said so, the bitmaps were loaded and handed out as valid, and an incremental backup taken from one of them would silently miss the data written after the last clean close. Mark them inconsistent, as qcow2 does for a bitmap whose in-use flag survived a crash. Using such a bitmap fails with an error naming it, so the loss is reported to whoever tries to rely on it instead of being discovered later in a backup. parallels_save_bitmap() already skips an inconsistent bitmap, so it is not written back. The format has no per bitmap flag to record that the contents are unusable, so keeping it would present it as valid again on the next open. Say what happens, as the bitmap disappears from the image and 'qemu-img bitmap --remove' would report it as missing afterwards. The image data itself is unaffected: it is repaired at open as before, and only the bitmaps are dropped. Cc: Stefan Hajnoczi <[email protected]> Signed-off-by: Denis V. Lunev <[email protected]> --- block/parallels-ext.c | 13 +++++++-- tests/qemu-iotests/tests/parallels-checks | 27 +++++++++++++++++++ tests/qemu-iotests/tests/parallels-checks.out | 17 ++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/block/parallels-ext.c b/block/parallels-ext.c index 17445d183b..b7fac2514a 100644 --- a/block/parallels-ext.c +++ b/block/parallels-ext.c @@ -335,6 +335,9 @@ parallels_parse_format_extension(BlockDriverState *bs, uint8_t *ext_cluster, goto fail; } bdrv_dirty_bitmap_set_persistence(bitmap, true); + if (s->header_unclean) { + bdrv_dirty_bitmap_set_inconsistent(bitmap); + } bitmaps = g_slist_append(bitmaps, bitmap); break; @@ -417,8 +420,14 @@ static int GRAPH_RDLOCK parallels_save_bitmap(BlockDriverState *bs, QemuUUID uuid; int ret = 0; - if (!bdrv_dirty_bitmap_get_persistence(bitmap) || - bdrv_dirty_bitmap_inconsistent(bitmap)) { + if (!bdrv_dirty_bitmap_get_persistence(bitmap)) { + return 0; + } + + /* The format has no way to mark a stored bitmap unusable */ + if (bdrv_dirty_bitmap_inconsistent(bitmap)) { + warn_report("Dropping inconsistent bitmap %s", + bdrv_dirty_bitmap_name(bitmap)); return 0; } diff --git a/tests/qemu-iotests/tests/parallels-checks b/tests/qemu-iotests/tests/parallels-checks index 6f60fda62b..916d423a64 100755 --- a/tests/qemu-iotests/tests/parallels-checks +++ b/tests/qemu-iotests/tests/parallels-checks @@ -414,6 +414,33 @@ _check_test_img # Clear image _make_test_img $SIZE +echo "== TEST BITMAP OF AN IMAGE WHICH WAS NOT CLOSED ==" + +INUSE_OFFSET=44 + +echo "== add a persistent dirty bitmap and dirty it ==" +$QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG" $BITMAP 2>&1 | _filter_testdir +{ $QEMU_IO -c "write -P 0x11 0 65536" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== pretend the image was not closed correctly ==" +poke_file "$TEST_IMG" "$INUSE_OFFSET" "\x59\x6e\x6f\x74" + +echo "== a read-only open still reports it, it is only inconsistent ==" +$QEMU_IMG info -f $IMGFMT "$TEST_IMG" | grep -q "$BITMAP" \ + && echo "still reported" + +echo "== the bitmap is stale, so it can not be used and is dropped ==" +$QEMU_IMG bitmap --clear -f $IMGFMT "$TEST_IMG" $BITMAP 2>&1 | _filter_testdir + +echo "== the name is free again ==" +$QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG" $BITMAP 2>&1 | _filter_testdir + +echo "== guest data was never in doubt ==" +{ $QEMU_IO -r -c "read -P 0x11 0 65536" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +# Clear image +_make_test_img $SIZE + echo "== TEST A DUPLICATE IN THE LAST ALLOCATED BAT ENTRY ==" echo "== write two clusters ==" diff --git a/tests/qemu-iotests/tests/parallels-checks.out b/tests/qemu-iotests/tests/parallels-checks.out index d40f865868..4dfadd68d6 100644 --- a/tests/qemu-iotests/tests/parallels-checks.out +++ b/tests/qemu-iotests/tests/parallels-checks.out @@ -268,6 +268,23 @@ read 65536/65536 bytes at offset 0 file size: 2097152 No errors were found on the image. Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 +== TEST BITMAP OF AN IMAGE WHICH WAS NOT CLOSED == +== add a persistent dirty bitmap and dirty it == +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== pretend the image was not closed correctly == +== a read-only open still reports it, it is only inconsistent == +still reported +== the bitmap is stale, so it can not be used and is dropped == +Repairing image was not closed correctly +qemu-img: Operation clear on bitmap b2c9e1a4-5d3f-4e8b-9a7c-6f0d1e2b3a45 failed: Bitmap 'b2c9e1a4-5d3f-4e8b-9a7c-6f0d1e2b3a45' is inconsistent and cannot be used +Try block-dirty-bitmap-remove to delete this bitmap from disk +qemu-img: warning: Dropping inconsistent bitmap b2c9e1a4-5d3f-4e8b-9a7c-6f0d1e2b3a45 +== the name is free again == +== guest data was never in doubt == +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 == TEST A DUPLICATE IN THE LAST ALLOCATED BAT ENTRY == == write two clusters == wrote 1048576/1048576 bytes at offset 0 -- 2.53.0