From 048c5fd1bfc787adcb1b726ce997e87fe44545fd Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 6 Apr 2017 20:37:09 -0500 Subject: qcow2: Allow discard of final unaligned cluster As mentioned in commit 0c1bd46, we ignored requests to discard the trailing cluster of an unaligned image. While discard is an advisory operation from the guest standpoint, (and we are therefore free to ignore any request), our qcow2 implementation exploits the fact that a discarded cluster reads back as 0. As long as we discard on cluster boundaries, we are fine; but that means we could observe non-zero data leaked at the tail of an unaligned image. Enhance iotest 66 to cover this case, and fix the implementation to honor a discard request on the final partial cluster. Signed-off-by: Eric Blake Message-id: 20170407013709.18440-1-eblake@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/066 | 12 +++++++----- tests/qemu-iotests/066.out | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066 index 364166d..c2116a3 100755 --- a/tests/qemu-iotests/066 +++ b/tests/qemu-iotests/066 @@ -42,16 +42,18 @@ _supported_fmt qcow2 _supported_proto generic _supported_os Linux +# Intentionally create an unaligned image IMGOPTS="compat=1.1" -IMG_SIZE=64M +IMG_SIZE=$((64 * 1024 * 1024 + 512)) echo -echo "=== Testing snapshotting an image with zero clusters ===" +echo "=== Testing cluster discards ===" echo _make_test_img $IMG_SIZE -# Write some normal clusters, zero them (creating preallocated zero clusters) -# and discard those -$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "discard 0 256k" "$TEST_IMG" \ +# Write some normal clusters, zero some of them (creating preallocated +# zero clusters) and discard everything. Everything should now read as 0. +$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \ + -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \ | _filter_qemu_io # Check the image (there shouldn't be any leaks) _check_test_img diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out index 7bc9a10..7c1f31a 100644 --- a/tests/qemu-iotests/066.out +++ b/tests/qemu-iotests/066.out @@ -1,13 +1,17 @@ QA output created by 066 -=== Testing snapshotting an image with zero clusters === +=== Testing cluster discards === -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376 wrote 262144/262144 bytes at offset 0 256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 262144/262144 bytes at offset 0 256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -discard 262144/262144 bytes at offset 0 -256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 512/512 bytes at offset 67108864 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +discard 67109376/67109376 bytes at offset 0 +64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 67109376/67109376 bytes at offset 0 +64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) No errors were found on the image. *** done -- cgit v1.1 From 4f38497b0fc03dcb24c9014c2cf34d324ab20c1e Mon Sep 17 00:00:00 2001 From: John Snow Date: Thu, 27 Apr 2017 16:50:59 -0400 Subject: iotests: clarify help text Split the help text to highlight the groups of options a little better, carving out a clear "format" and "protocols" section. Signed-off-by: John Snow Message-id: 20170427205100.9505-2-jsnow@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/common | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common index 9c6f972..fa8e69e 100644 --- a/tests/qemu-iotests/common +++ b/tests/qemu-iotests/common @@ -138,7 +138,7 @@ common options -v verbose -d debug -check options +image format options -raw test raw (default) -bochs test bochs -cloop test cloop @@ -150,14 +150,18 @@ check options -vpc test vpc -vhdx test vhdx -vmdk test vmdk + -luks test luks + +image protocol options -file test file (default) -rbd test rbd -sheepdog test sheepdog -nbd test nbd -ssh test ssh -nfs test nfs - -luks test luks -vxhs test vxhs + +other options -xdiff graphical mode diff -nocache use O_DIRECT on backing file -misalign misalign memory allocations -- cgit v1.1 From cc02e89eb4eb8b1cc43b2bc168dc0fca48ee721f Mon Sep 17 00:00:00 2001 From: John Snow Date: Thu, 27 Apr 2017 16:51:00 -0400 Subject: iotests: fix exclusion option If you are running out-of-tree, the -x option to exclude a certain iotest is broken. Replace porcelain usage of ls with a sturdier awk command. Reviewed-by: Fam Zheng Signed-off-by: John Snow Message-id: 20170427205100.9505-3-jsnow@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/common | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common index fa8e69e..f2a7199 100644 --- a/tests/qemu-iotests/common +++ b/tests/qemu-iotests/common @@ -86,7 +86,8 @@ s/ .*//p elif $xgroup then # arg after -x - [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null + # Populate $tmp.list with all tests + awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ s/ .*//p }'` -- cgit v1.1