qcow2: write_zeroes corruption fixes and tests
cover qcow2: write_zeroes corruption fixes and tests
These are the qcow2 write_zeroes fixes that need to be merged with the next pull request as they can actually cause image corruption. The rest of Den's patches are mostly cleanups, so they aren't quite as urgent.
Denis V. Lunev (1):
qcow2: fix condition in is_zero_cluster
Kevin Wolf (2):
qcow2: Fix write_zeroes with partially allocated backing file cluster
qemu-iotests: Some more write_zeroes tests
block/qcow2.c | 3 +- tests/qemu-iotests/154 | 100 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/154.out | 64 +++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100755 tests/qemu-iotests/154 create mode 100644 tests/qemu-iotests/154.out
Signature · 1 line
1.8.3.1
PATCH 1/3 qcow2: fix condition in is_zero_cluster
From: "Denis V. Lunev" <[email protected]>
We should check for (res & BDRV_BLOCK_ZERO) only. The situation when we will have !(res & BDRV_BLOCK_DATA) and will not have BDRV_BLOCK_ZERO is not possible for images with bdi.unallocated_blocks_are_zero == true.
For those images where it's false, however, it can happen and we must not consider the data zeroed then or we would corrupt the image.
--- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2.c +1 -1
@@ -2412,7 +2412,7 @@ static bool is_zero_cluster(BlockDriverState *bs, int64_t start)BlockDriverState *file;int64_t res =bdrv_get_block_status_above (bs,NULL , start, s->cluster_sectors, &nr, &file); -return res >=0 && ((res &BDRV_BLOCK_ZERO ) || !(res &BDRV_BLOCK_DATA )); +return res >=0 && (res &BDRV_BLOCK_ZERO ); }static bool is_zero_cluster_top_locked (BlockDriverState *bs,int64_t start)
Signature · 1 line
1.8.3.1
PATCH 2/3 qcow2: Fix write_zeroes with partially allocated backing file cluster
In reply to Kevin WolfIn order to correctly check whether a given cluster is read as zero, we don't only need to check whether bdrv_get_block_status_above() sets BDRV_BLOCK_ZERO, but also if all sectors for the whole cluster have the same status.
--- block/qcow2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/qcow2.c +2 -1
@@ -2412,7 +2412,7 @@ static bool is_zero_cluster(BlockDriverState *bs, int64_t start)BlockDriverState *file;int64_t res =bdrv_get_block_status_above (bs,NULL , start, s->cluster_sectors, &nr, &file); -return res >=0 && (res &BDRV_BLOCK_ZERO ); +return res >=0 && (res &BDRV_BLOCK_ZERO ) && nr == s->cluster_sectors; }static bool is_zero_cluster_top_locked (BlockDriverState *bs,int64_t start)
@@ -2423,6 +2423,7 @@ static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start)int ret; ret =qcow2_get_cluster_offset (bs, start <<BDRV_SECTOR_BITS , &nr, &off); +assert (nr == s->cluster_sectors);return ret ==QCOW2_CLUSTER_UNALLOCATED || ret ==QCOW2_CLUSTER_ZERO ; }
Signature · 1 line
1.8.3.1
PATCH 3/3 qemu-iotests: Some more write_zeroes tests
In reply to Kevin WolfThis covers some more write_zeroes cases which are relevant for the recent qcow2 optimisations that check the allocation status of the backing file for partial cluster write_zeroes requests.
--- tests/qemu-iotests/154 | 100 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/154.out | 64 +++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 165 insertions(+) create mode 100755 tests/qemu-iotests/154 create mode 100644 tests/qemu-iotests/154.out
tests/qemu-iotests/154 new file +100 -0
@@ -0,0 +1,100 @@ +#!/bin/bash +# +# qcow2 specific bdrv_write_zeroes tests with backing files (complements 034) +# +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +CLUSTER_SIZE=4k +size=128M + +echo +echo == backing file contains zeros == + +# Make sure that the whole cluster is allocated even for partial write_zeroes +# when the backing file contains zeros + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -z 0k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == backing file contains non-zero data before write_zeros == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == backing file contains non-zero data after write_zeros == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 74k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 10k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/154.out new file +64 -0
64 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -153,3 +153,4 @@ 149 rw auto sudo 150 rw auto quick 152 rw auto quick +154 rw auto backing quick
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 2/3] qcow2: Fix write_zeroes with partially allocated backing file cluster
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
In order to correctly check whether a given cluster is read as zero, we don't only need to check whether
bdrv_get_block_status_above()setsBDRV_BLOCK_ZERO, but also if all sectors for the whole cluster have the same status.Signed-off-by Kevin Wolf <[email protected]>--- block/qcow2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/3] qcow2: fix condition in is_zero_cluster
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
From: "Denis V. Lunev" <[email protected]>
We should check for (res &
BDRV_BLOCK_ZERO) only. The situation when we will have !(res &BDRV_BLOCK_DATA) and will not haveBDRV_BLOCK_ZEROis not possible for images with bdi.unallocated_blocks_are_zero == true.For those images where it's false, however, it can happen and we must not consider the data zeroed then or we would corrupt the image.
Quoted 6 lines
Signed-off-by Denis V. Lunev <[email protected]>CC Kevin Wolf <[email protected]>Signed-off-by Kevin Wolf <[email protected]>--- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] qemu-iotests: Some more write_zeroes tests
In reply to Kevin Wolftests/qemu-iotests/154 line 40
Quoted 10 lines · Kevin Wolf
This covers some more
write_zeroescases which are relevant for the recent qcow2 optimisations that check the allocation status of the backing file for partial clusterwrite_zeroesrequests.Signed-off-by Kevin Wolf <[email protected]>---
tests/qemu-iotests/154 new file +2
-0+# qcow2 specific bdrv_write_zeroes tests with backing files (complements 034) +_supported_fmt qcow2
I guess test 034 covered cases of larger-than-sector write_zero, and that the reason you needed a new test id is because this one is qcow2 specific (the general test covers multiple formats, but the behavior on sub-cluster zeroing is specific to qcow2). Makes sense so far.
Quoted 4 lines
tests/qemu-iotests/154 new file +4
-0+ +CLUSTER_SIZE=4k +size=128M +
tests/qemu-iotests/154 line 56
Quoted 10 lines
tests/qemu-iotests/154 new file +10
-0+echo +echo == backing file contains zeros == + +# Make sure that the whole cluster is allocated even for partial write_zeroes +# when the backing file contains zeros + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -z 0k 2k" "$TEST_IMG" | _filter_qemu_io
head aligned, tail is unaligned
Quoted 1 line
+$QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" |
_filter_qemu_io
head is unaligned, tail is unaligned
Quoted 1 line
+$QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" |
_filter_qemu_io
both unaligned, and completely contained within a single cluster
No test of crossing a cluster boundary at this point? I would probably do:
$QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" | _filter_qemu_io
then check that the map shows an allocation starting at 24k for 8192 bytes
tests/qemu-iotests/154 line 68
Quoted 10 lines
+$QEMU_IMG map --output=json "$TEST_IMG" |
_filter_qemu_img_maptests/qemu-iotests/154 new file +9
-0+ +echo +echo == backing file contains non-zero data before write_zeros == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io
cluster contains partial non-zero data, which does not overlap with the write zero request. Good - you're testing that we don't nuke the rest of the cluster (that is, we cannot convert an entire cluster to 0 unless all sectors read as 0 before the conversion), but instead do proper copy-on-write.
Quoted 14 lines
+$QEMU_IO -c "read -P
0x1132k 1k" "$TEST_IMG" |_filter_qemu_io+$QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" |_filter_qemu_io+$QEMU_IMG map --output=json "$TEST_IMG" |_filter_qemu_img_maptests/qemu-iotests/154 new file +11
-0+ +echo +echo == backing file contains non-zero data after write_zeros == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io
tests/qemu-iotests/154 line 92
Quoted 10 lines
tests/qemu-iotests/154 new file +10
-0+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +$QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
the tail from 72k to 73k overlaps the sector that has to be copy-on-write to pick up the data at 74k; while the earlier portion picks up the clusters at 64k and 68k. Looks good.
What you have looks fine, but again, I'd consider also testing a sub-cluster size 'write -z' that spans a cluster boundary, including the case where it is overwriting data from the backing file. Something like:
$QEMU_IO -c "write -P 0x11 2k 4k" "$TEST_IMG.base" | _filter_qemu_io $QEMU_IO -c "write -z 3k 2k" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -P 0 0k 2k" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -P 0x11 2k 1k" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -P 0 3k 2k" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -P 0x11 5k 1k" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -P 0 6k 2k" "$TEST_IMG" | _filter_qemu_io
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/3] qcow2: Fix write_zeroes with partially allocated backing file cluster
In reply to Kevin WolfQuoted 24 lines · Kevin Wolf
In order to correctly check whether a given cluster is read as zero, we don't only need to check whether
bdrv_get_block_status_above()setsBDRV_BLOCK_ZERO, but also if all sectors for the whole cluster have the same status.Signed-off-by Kevin Wolf <[email protected]>--- block/qcow2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)block/qcow2.c +1
-1@@ -2412,7 +2412,7 @@ static bool is_zero_cluster(BlockDriverState *bs, int64_t start)BlockDriverState *file;int64_t res =bdrv_get_block_status_above (bs,NULL , start, s->cluster_sectors, &nr, &file); -return res >=0 && (res &BDRV_BLOCK_ZERO ); +return res >=0 && (res &BDRV_BLOCK_ZERO ) && nr == s->cluster_sectors; }static bool is_zero_cluster_top_locked (BlockDriverState *bs,int64_t start)
block/qcow2.c static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start) · line 2429
Quoted 7 lines
block/qcow2.c +1
-0@@ -2423,6 +2423,7 @@ static bool is_zero_cluster_top_locked(BlockDriverState *bs, int64_t start)int ret; ret =qcow2_get_cluster_offset (bs, start <<BDRV_SECTOR_BITS , &nr, &off); +assert (nr == s->cluster_sectors);return ret ==QCOW2_CLUSTER_UNALLOCATED || ret ==QCOW2_CLUSTER_ZERO ; }
I have had this kludge in the revision one and I have lost them in revision 3 :(
Re: [Qemu-devel] [PATCH 3/3] qemu-iotests: Some more write_zeroes tests
In reply to Eric BlakeAm 17.05.2016 um 22:35 hat Eric Blake geschrieben:
Quoted 9 lines
No test of crossing a cluster boundary at this point? I would probably do:
$QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" |
_filter_qemu_iothen check that the map shows an allocation starting at 24k for 8192 bytes
What you have looks fine, but again, I'd consider also testing a sub-cluster size 'write -z' that spans a cluster boundary, including the case where it is overwriting data from the backing file.
Okay, I'll put some more time into this test case. What we're testing here is a source for corruption bugs, so it's probably worth doing it right.
Kevin
PATCH v2 3/3 qemu-iotests: Some more write_zeroes tests
In reply to Eric BlakeThis covers some more write_zeroes cases which are relevant for the recent qcow2 optimisations that check the allocation status of the backing file for partial cluster write_zeroes requests.
This needs to be separate from 034 because we can only support qcow2 in this test case for multiple reasons: We check the allocation status after write_zeroes with 'qemu-img map' and the optimised behaviour that produces zero clusters is only implemented in qcow2; second, the map command returns offsets that are qcow2 specific; and finally, we also use 512 byte clusters which aren't supported for formats like qed.
---
v2:
- Some more test cases, including one suggested by Eric
- Comments in the test script that visualise each case with ASCII art
tests/qemu-iotests/154 | 265 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/154.out | 242 +++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 508 insertions(+) create mode 100755 tests/qemu-iotests/154 create mode 100644 tests/qemu-iotests/154.out
tests/qemu-iotests/154 new file +265 -0
@@ -0,0 +1,265 @@ +#!/bin/bash +# +# qcow2 specific bdrv_write_zeroes tests with backing files (complements 034) +# +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +CLUSTER_SIZE=4k +size=128M + +echo +echo == backing file contains zeros == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Make sure that the whole cluster is allocated even for partial write_zeroes +# when the backing file contains zeros + +# X = non-zero data sector in backing file +# - = sector unallocated in whole backing chain +# 0 = sector touched by write_zeroes request + +# 1. Tail unaligned: 00 00 -- -- +# 2. Head unaligned: -- -- 00 00 +# 3. Both unaligned: -- 00 00 -- +# 4. Both, 2 clusters: -- -- -- 00 | 00 -- -- -- + +$QEMU_IO -c "write -z 0 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == backing file contains non-zero data before write_zeroes == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Single cluster; non-zero data at the cluster start +# ... | XX -- 00 -- | ... +$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" | _filter_qemu_io + +# Single cluster; non-zero data exists, but not at the cluster start +# ... | -- XX 00 -- | ... +$QEMU_IO -c "write -P 0x11 65k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 66k 2k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == backing file contains non-zero data after write_zeroes == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Single cluster; non-zero data directly after request +# ... | -- 00 XX -- | ... +$QEMU_IO -c "write -P 0x11 34k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 33k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 32k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 34k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 35k 1k" "$TEST_IMG" | _filter_qemu_io + +# Single cluster; non-zero data exists, but not directly after request +# ... | -- 00 -- XX | ... +$QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning two clusters, non-zero before request == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Two clusters; non-zero data before request: +# 1. At cluster start: 32k: XX -- -- 00 | 00 -- -- -- +# 2. Between unallocated space: 48k: -- XX -- 00 | 00 -- -- -- +# 3. Directly before request: 64k: -- -- XX 00 | 00 -- -- -- + +$QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 33k 7k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IO -c "write -P 0x11 49k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 48k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 49k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 50k 6k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IO -c "write -P 0x11 66k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 66k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 67k 5k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning two clusters, non-zero after request == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Two clusters; non-zero data after request: +# 1. Directly after request: 32k: -- -- -- 00 | 00 XX -- -- +# 2. Between unallocated space: 48k: -- -- -- 00 | 00 -- XX -- +# 3. At cluster end: 64k: -- -- -- 00 | 00 -- -- XX + +$QEMU_IO -c "write -P 0x11 37k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 32k 5k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 37k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 38k 2k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IO -c "write -P 0x11 54k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 48k 6k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 54k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 55k 1k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IO -c "write -P 0x11 71k 1k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 71k 1k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning two clusters, partially overwriting backing file == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Backing file: -- -- XX XX | XX XX -- -- +# Active layer: -- -- XX 00 | 00 XX -- -- + +$QEMU_IO -c "write -P 0x11 2k 4k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 3k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 0k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 2k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 3k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 5k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 6k 2k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters, non-zero in first cluster == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Backing file: 64k: XX XX -- -- | -- -- -- -- | -- -- -- -- +# Active layer: 64k: XX XX 00 00 | 00 00 00 00 | 00 -- -- -- + +$QEMU_IO -c "write -P 0x11 64k 2k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 64k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 66k 10k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters, non-zero in intermediate cluster == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Backing file: 64k: -- -- -- -- | -- XX XX -- | -- -- -- -- +# Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- -- -- + +$QEMU_IO -c "write -P 0x11 69k 2k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 12k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters, non-zero in final cluster == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Backing file: 64k: -- -- -- -- | -- -- -- -- | -- -- XX XX +# Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- XX XX + +$QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 10k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 74k 2k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +echo +echo == spanning multiple clusters, partially overwriting backing file == + +CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" + +# Backing file: 64k: -- XX XX XX | XX XX XX XX | XX XX XX -- +# Active layer: 64k: -- XX 00 00 | 00 00 00 00 | 00 XX XX -- + +$QEMU_IO -c "write -P 0x11 65k 10k" "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 66k 7k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0x11 73k 2k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io + +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/154.out new file +242 -0
242 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -153,3 +153,4 @@ 149 rw auto sudo 150 rw auto quick 152 rw auto quick +154 rw auto backing quick
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 3/3] qemu-iotests: Some more write_zeroes tests
Quoted 11 lines · Kevin Wolf
This covers some more
write_zeroescases which are relevant for the recent qcow2 optimisations that check the allocation status of the backing file for partial clusterwrite_zeroesrequests.This needs to be separate from 034 because we can only support qcow2 in this test case for multiple reasons: We check the allocation status after
write_zeroeswith 'qemu-img map' and the optimised behaviour that produces zero clusters is only implemented in qcow2; second, the map command returns offsets that are qcow2 specific; and finally, we also use 512 byte clusters which aren't supported for formats like qed.
Quoted 6 lines
Signed-off-by Kevin Wolf <[email protected]>---
v2:
- Some more test cases, including one suggested by Eric
- Comments in the test script that visualise each case with ASCII art
Nice!
Quoted 1 line
+# qcow2 specific
bdrv_write_zeroestests with backing files (complements 034)
Maybe also worth a one line tweak to 034 to give a comment pointing to this file (so the two mutually reference each other), but that doesn't require a respin.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 3/3] qemu-iotests: Some more write_zeroes tests
Am 18.05.2016 um 16:12 hat Eric Blake geschrieben:
Quoted 21 lines · Kevin Wolf
Quoted 11 lines
This covers some more
write_zeroescases which are relevant for the recent qcow2 optimisations that check the allocation status of the backing file for partial clusterwrite_zeroesrequests.This needs to be separate from 034 because we can only support qcow2 in this test case for multiple reasons: We check the allocation status after
write_zeroeswith 'qemu-img map' and the optimised behaviour that produces zero clusters is only implemented in qcow2; second, the map command returns offsets that are qcow2 specific; and finally, we also use 512 byte clusters which aren't supported for formats like qed.Quoted 6 lines
Signed-off-by Kevin Wolf <[email protected]>---
v2:
- Some more test cases, including one suggested by Eric
- Comments in the test script that visualise each case with ASCII artNice!
Quoted 7 lines
Quoted 1 line
+# qcow2 specific
bdrv_write_zeroestests with backing files (complements 034)Maybe also worth a one line tweak to 034 to give a comment pointing to this file (so the two mutually reference each other), but that doesn't require a respin.
Reviewed-by Eric Blake <[email protected]>
Thanks, I pushed this to my block branch now.
Kevin