Before the previous commit, issuing 'discard' and 'write -z -u' operations with discard-no-unref=on option enabled led to data corruption. Add a test to cover this case.
Signed-off-by: Andrey Drobyshev <[email protected]> --- tests/qemu-iotests/290 | 16 ++++++++++++++++ tests/qemu-iotests/290.out | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/tests/qemu-iotests/290 b/tests/qemu-iotests/290 index 152fd7c5d1f..049a0ef7f13 100755 --- a/tests/qemu-iotests/290 +++ b/tests/qemu-iotests/290 @@ -124,6 +124,22 @@ $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map echo "# Output of qemu-img map for the image with kept reference" $QEMU_IMG map --output=json "$NOUNREF_IMG" | _filter_qemu_img_map +echo +echo "### Discard with 'discard-no-unref' on a cluster shared with a snapshot" +echo + +_make_test_img 128k +$QEMU_IO -c 'write -q -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -c snap "$TEST_IMG" +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \ +$QEMU_IO -c 'discard -q 0 64k' -c 'write -q -z -u 64k 64k' --image-opts \ + "driver=$IMGFMT,file.filename=$TEST_IMG,discard-no-unref=on" \ + | _filter_qemu_io +$QEMU_IO -c 'read -q -P 0 0 128k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -a snap "$TEST_IMG" +$QEMU_IO -c 'read -q -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io +_check_test_img + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/290.out b/tests/qemu-iotests/290.out index f790feae81a..aa5d164fa9f 100644 --- a/tests/qemu-iotests/290.out +++ b/tests/qemu-iotests/290.out @@ -86,4 +86,9 @@ Images are identical. # Output of qemu-img map for the image with kept reference [{ "start": 0, "length": 65536, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, { "start": 65536, "length": 65536, "depth": 0, "present": true, "zero": true, "data": false, "compressed": false, "offset": OFFSET}] + +### Discard with 'discard-no-unref' on a cluster shared with a snapshot + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 +No errors were found on the image. *** done -- 2.47.1
