Fix wipe of unaligned qcow2 image [was add blkdebug tests]
v8 cover Fix wipe of unaligned qcow2 image [was add blkdebug tests]
Available as a tag at:
git fetch git://repo.or.cz/qemu/ericb.git nbd-blkdebug-v8
(which is somewhat of a misnomer for this current version of the series, but historically correct)
v6 was:
https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg01562.html
v7 was:
https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg06175.html
Since then: reorder patches 2 and 3, and update commit messages to match
001/3:[----] [--] 'iotests: fix 097 when run with qcow' 002/3:[0002] [FC] 'qcow2: Discard unaligned tail when wiping image' 003/3:[0002] [FC] 'iotests: Improve image-clear tests on non-aligned image'
Daniel P. Berrange (1):
iotests: fix 097 when run with qcow
Eric Blake (2):
qcow2: Discard unaligned tail when wiping image
iotests: Improve image-clear tests on non-aligned image
block/qcow2-cluster.c | 10 +-- tests/qemu-iotests/097 | 27 +++---- tests/qemu-iotests/097.out | 180 ++++++++++++--------------------------------- tests/qemu-iotests/176 | 131 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/176.out | 150 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 6 files changed, 345 insertions(+), 154 deletions(-) create mode 100755 tests/qemu-iotests/176 create mode 100644 tests/qemu-iotests/176.out
Signature · 1 line
2.9.3
PATCH v8 2/3 qcow2: Discard unaligned tail when wiping image
There is a subtle difference between the fast (qcow2v3 with no extra data) and slow path (qcow2v2 format [aka 0.10], or when a snapshot is present) of qcow2_make_empty(). The slow path fails to discard the final (partial) cluster of an unaligned image.
The problem stems from the fact that qcow2_discard_clusters() was silently ignoring sub-cluster head and tail on unaligned requests. A quick audit of all callers shows that qcow2_snapshot_create() has always passed a cluster-aligned request since the call was added in commit 1ebf561; qcow2_co_pdiscard() has passed a cluster-aligned request since commit ecdbead taught the block layer about preferred discard alignment; and qcow2_make_empty() was fixed to pass an aligned start (but not necessarily end) in commit a3e1505.
Asserting that the start is always aligned also points out that we now have a dead check: rounding the end offset down can never result in a value less than the aligned start offset (the check was rendered dead with commit ecdbead). Meanwhile, we do not want to round the end cluster down in the one case of the end offset matching the (unaligned) file size - that final partial cluster should still be discarded.
With those fixes in place, the fast and slow paths are back in sync at discarding an entire image; the next patch will update qemu-iotests to ensure we don't regress.
Note that bdrv_co_pdiscard ignores ALL partial cluster requests, including the partial cluster at the end of an image; it can be argued that the partial cluster at the end should be special-cased so that a guest issuing discard requests at proper alignments everywhere else can likewise empty the entire image. But that optimization is left for another day.
---
v8: swap patch order
v7: new patch
--- block/qcow2-cluster.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
block/qcow2-cluster.c +4 -6
@@ -1519,12 +1519,10 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset, end_offset = offset + (nb_sectors <<BDRV_SECTOR_BITS ); -/* Round start up and end down */ - offset =align_offset (offset, s->cluster_size); - end_offset =start_of_cluster (s, end_offset); - -if (offset > end_offset) { -return 0 ; +/* The caller must cluster-align start; round end down except at EOF */ +assert (QEMU_IS_ALIGNED (offset, s->cluster_size)); +if (end_offset != bs->total_sectors *BDRV_SECTOR_SIZE ) { + end_offset =start_of_cluster (s, end_offset); } nb_clusters =size_to_clusters (s, end_offset - offset);
Signature · 1 line
2.9.3
PATCH v8 1/3 iotests: fix 097 when run with qcow
In reply to Eric BlakeFrom: "Daniel P. Berrange" <[email protected]>
The previous commit:
commit a3e1505daec31ef56f0489f8c8fff1b8e4ca92bd
Author: Eric Blake <[email protected]>
Date: Mon Dec 5 09:49:34 2016 -0600
qcow2: Don't strand clusters near 2G intervals during commit
extended the 097 test case so that it did two passes, once with an internal snapshot, once without.
qcow (v1) does not support internal snapshots, so this change broke test 097 when run against qcow.
This splits 097 in two, creating a new 176 that tests the internal snapshot codepath, effectively putting 097 back to its content before the above commit.
Message-Id: <[email protected]>
--- tests/qemu-iotests/097 | 10 +--- tests/qemu-iotests/097.out | 125 ++------------------------------------------ tests/qemu-iotests/176 | 126 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/176.out | 119 ++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 5 files changed, 251 insertions(+), 130 deletions(-) create mode 100755 tests/qemu-iotests/176 create mode 100644 tests/qemu-iotests/176.out
tests/qemu-iotests/097 +1 -9
@@ -56,26 +56,19 @@ _supported_os Linux # 3: Two-layer backing chain, commit to lower backing file # (in this case, the top image will implicitly stay unchanged) # -# Each pass is run twice, since qcow2 has different code paths for cleaning -# an image depending on whether it has a snapshot. -# # 020 already tests committing, so this only tests whether image chains are # working properly and that all images above the base are emptied; therefore, # no complicated patterns are necessary. Check near the 2G mark, as qcow2 # has been buggy at that boundary in the past. for i in 0 1 2 3; do -for j in 0 1; do echo -echo "=== Test pass $i.$j ===" +echo "=== Test pass $i ===" echo TEST_IMG="$TEST_IMG.base" _make_test_img 2100M TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" 2100M _make_test_img -b "$TEST_IMG.itmd" 2100M -if [ $j -eq 0 ]; then - $QEMU_IMG snapshot -c snap "$TEST_IMG" -fi $QEMU_IO -c 'write -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c 'write -P 2 0x7ffe0000 128k' "$TEST_IMG.itmd" | _filter_qemu_io
@@ -121,7 +114,6 @@ $QEMU_IMG map "$TEST_IMG.itmd" | _filter_qemu_img_map $QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map done -done # success, all done
tests/qemu-iotests/097.out +4 -121
148 lines not on this page · raw message
tests/qemu-iotests/176 new file +126 -0
126 lines not on this page · raw message
tests/qemu-iotests/176.out new file +119 -0
119 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -168,3 +168,4 @@ 173 rw auto 174 auto 175 auto quick +176 rw auto backing
Signature · 1 line
2.9.3
PATCH v8 3/3 iotests: Improve image-clear tests on non-aligned image
In reply to Eric BlakeTweak 097 and 176 to operate on an image that is not cluster-aligned, to give further coverage of clearing out an entire image, including the recent fix to eliminate the difference between fast path (97) and slow (176) for qcow2. Also tested on qcow (97 only, since qcow lacks snapshots).
---
v8: reorder patches
v7: also write data in the unaligned cluster, and document bug it exposes
v6: new patch
--- tests/qemu-iotests/097 | 17 +++++++++----- tests/qemu-iotests/097.out | 55 ++++++++++++++++++++++++++++++++++++---------- tests/qemu-iotests/176 | 17 +++++++++----- tests/qemu-iotests/176.out | 55 ++++++++++++++++++++++++++++++++++++---------- 4 files changed, 108 insertions(+), 36 deletions(-)
tests/qemu-iotests/097 +11 -6
@@ -66,13 +66,15 @@ echo echo "=== Test pass $i ===" echo -TEST_IMG="$TEST_IMG.base" _make_test_img 2100M -TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" 2100M -_make_test_img -b "$TEST_IMG.itmd" 2100M +len=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned +TEST_IMG="$TEST_IMG.base" _make_test_img $len +TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len +_make_test_img -b "$TEST_IMG.itmd" $len -$QEMU_IO -c 'write -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io -$QEMU_IO -c 'write -P 2 0x7ffe0000 128k' "$TEST_IMG.itmd" | _filter_qemu_io -$QEMU_IO -c 'write -P 3 0x7fff0000 64k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io +$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io if [ $i -lt 3 ]; then if [ $i == 0 ]; then
@@ -90,11 +92,13 @@ if [ $i -lt 3 ]; then # Bottom should be unchanged $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io + $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io # Intermediate should contain changes from top $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io + $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io # And in pass 0, the top image should be empty, whereas in both other passes # it should be unchanged (which is both checked by qemu-img map)
@@ -105,6 +109,7 @@ else $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io + $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io # Both top and intermediate should be unchanged fi
tests/qemu-iotests/097.out +43 -12
160 lines not on this page · raw message
tests/qemu-iotests/176 +11 -6
@@ -69,14 +69,16 @@ echo echo "=== Test pass $i ===" echo -TEST_IMG="$TEST_IMG.base" _make_test_img 2100M -TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" 2100M -_make_test_img -b "$TEST_IMG.itmd" 2100M +len=$((2100 * 1024 * 1024 + 512)) # larger than 2G, and not cluster aligned +TEST_IMG="$TEST_IMG.base" _make_test_img $len +TEST_IMG="$TEST_IMG.itmd" _make_test_img -b "$TEST_IMG.base" $len +_make_test_img -b "$TEST_IMG.itmd" $len $QEMU_IMG snapshot -c snap "$TEST_IMG" -$QEMU_IO -c 'write -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io -$QEMU_IO -c 'write -P 2 0x7ffe0000 128k' "$TEST_IMG.itmd" | _filter_qemu_io -$QEMU_IO -c 'write -P 3 0x7fff0000 64k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 1 0x7ffd0000 192k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -P 2 0x7ffe0000 128k" "$TEST_IMG.itmd" | _filter_qemu_io +$QEMU_IO -c "write -P 3 0x7fff0000 64k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 4 $(($len - 512)) 512" "$TEST_IMG" | _filter_qemu_io if [ $i -lt 3 ]; then if [ $i == 0 ]; then
@@ -94,11 +96,13 @@ if [ $i -lt 3 ]; then # Bottom should be unchanged $QEMU_IO -c 'read -P 1 0x7ffd0000 192k' "$TEST_IMG.base" | _filter_qemu_io + $QEMU_IO -c "read -P 0 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io # Intermediate should contain changes from top $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.itmd" | _filter_qemu_io + $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.itmd" | _filter_qemu_io # And in pass 0, the top image should be empty, whereas in both other passes # it should be unchanged (which is both checked by qemu-img map)
@@ -109,6 +113,7 @@ else $QEMU_IO -c 'read -P 1 0x7ffd0000 64k' "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c 'read -P 2 0x7ffe0000 64k' "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c 'read -P 3 0x7fff0000 64k' "$TEST_IMG.base" | _filter_qemu_io + $QEMU_IO -c "read -P 4 $((len - 512)) 512" "$TEST_IMG.base" | _filter_qemu_io # Both top and intermediate should be unchanged fi
tests/qemu-iotests/176.out +43 -12
160 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 24 lines · Eric Blake
Available as a tag at:
git fetchgit://repo.or.cz/qemu/ericb.gitnbd-blkdebug-v8(which is somewhat of a misnomer for this current version of the series, but historically correct)
v6 was:
https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg01562.html
v7 was:
https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg06175.htmlSince then: reorder patches 2 and 3, and update commit messages to match
001/3:[----] [--] 'iotests: fix 097 when run with qcow' 002/3:[0002] [FC] 'qcow2: Discard unaligned tail when wiping image' 003/3:[0002] [FC] 'iotests: Improve image-clear tests on non-aligned image'
Daniel P. Berrange (1):
iotests: fix 097 when run with qcowEric Blake (2):
qcow2: Discard unaligned tail when wiping image
iotests: Improve image-clear tests on non-aligned image
Quoted 9 lines
block/qcow2-cluster.c | 10 +-- tests/qemu-iotests/097 | 27 +++---- tests/qemu-iotests/097.out | 180 ++++++++++++--------------------------------- tests/qemu-iotests/176 | 131 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/176.out | 150 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 6 files changed, 345 insertions(+), 154 deletions(-) create mode 100755 tests/qemu-iotests/176 create mode 100644 tests/qemu-iotests/176.out
Thanks a lot, applied to my block branch:
https://github.com/XanClic/qemu/commits/block
Max