4 # Test qcow2 with external data files
6 # Copyright (C) 2019 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 owner
=kwolf@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
33 _rm_test_img
"$TEST_IMG.data"
34 _rm_test_img
"$TEST_IMG.src"
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
45 # External data files do not work with compat=0.10, and because we use
46 # our own external data file, we cannot let the user specify one
47 _unsupported_imgopts
'compat=0.10' data_file
50 echo "=== Create and open image with external data file ==="
53 echo "With data file name in the image:"
54 _make_test_img
-o "data_file=$TEST_IMG.data" 64M
57 $QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
58 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
59 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
62 echo "Data file required, but without data file name in the image:"
63 $QEMU_IMG amend
-odata_file= $TEST_IMG
65 $QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
66 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
67 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
70 echo "Setting data-file for an image with internal data:"
73 $QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
74 $QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir
77 echo "=== Conflicting features ==="
80 echo "Convert to compressed target with data file:"
81 TEST_IMG
="$TEST_IMG.src" _make_test_img
64M
83 $QEMU_IO -c 'write -P 0x11 0 1M' \
84 -f $IMGFMT "$TEST_IMG.src" |
87 $QEMU_IMG convert
-f $IMGFMT -O $IMGFMT -c -odata_file="$TEST_IMG.data" \
88 "$TEST_IMG.src" "$TEST_IMG"
91 echo "Convert uncompressed, then write compressed data manually:"
92 $QEMU_IMG convert
-f $IMGFMT -O $IMGFMT -odata_file="$TEST_IMG.data" \
93 "$TEST_IMG.src" "$TEST_IMG"
94 $QEMU_IMG compare
"$TEST_IMG.src" "$TEST_IMG"
96 $QEMU_IO -c 'write -c -P 0x22 0 1M' \
97 -f $IMGFMT "$TEST_IMG" |
102 echo "Take an internal snapshot:"
104 $QEMU_IMG snapshot
-c test "$TEST_IMG"
108 echo "=== Standalone image with external data file (efficient) ==="
111 _make_test_img
-o "data_file=$TEST_IMG.data" 64M
113 echo -n "qcow2 file size before I/O: "
114 du
-b $TEST_IMG | cut
-f1
116 # Create image with the following layout
117 # 0-1 MB: Unallocated
118 # 1-2 MB: Written (pattern 0x11)
120 # 3-4 MB: Zero write over discarded space
121 # 4-5 MB: Zero write over written space
122 # 5-6 MB: Zero write over unallocated space
125 $QEMU_IO -c 'write -P 0x11 1M 4M' \
127 -c 'write -z 3M 3M' \
128 -f $IMGFMT "$TEST_IMG" |
133 $QEMU_IMG map
--output=json
"$TEST_IMG"
136 $QEMU_IO -c 'read -P 0 0 1M' \
137 -c 'read -P 0x11 1M 1M' \
138 -c 'read -P 0 2M 4M' \
139 -f $IMGFMT "$TEST_IMG" |
142 # Zero clusters are only marked as such in the qcow2 metadata, but contain
143 # stale data in the external data file
145 $QEMU_IO -c 'read -P 0 0 1M' \
146 -c 'read -P 0x11 1M 1M' \
147 -c 'read -P 0x11 4M 1M' \
148 -c 'read -P 0 5M 1M' \
149 -f raw
"$TEST_IMG.data" |
153 echo -n "qcow2 file size after I/O: "
154 du
-b $TEST_IMG | cut
-f1
157 echo "=== Standalone image with external data file (valid raw) ==="
160 _make_test_img
-o "data_file=$TEST_IMG.data,data_file_raw=on" 64M
162 echo -n "qcow2 file size before I/O: "
163 du
-b $TEST_IMG | cut
-f1
166 $QEMU_IO -c 'write -P 0x11 1M 4M' \
168 -c 'write -z 3M 3M' \
169 -f $IMGFMT "$TEST_IMG" |
174 $QEMU_IMG map
--output=json
"$TEST_IMG"
177 $QEMU_IO -c 'read -P 0 0 1M' \
178 -c 'read -P 0x11 1M 1M' \
179 -c 'read -P 0 2M 4M' \
180 -f $IMGFMT "$TEST_IMG" |
183 # Discarded clusters are only marked as such in the qcow2 metadata, but
184 # they can contain stale data in the external data file. Instead, zero
185 # clusters must be zeroed in the external data file too.
187 $QEMU_IO -c 'read -P 0 0 1M' \
188 -c 'read -P 0x11 1M 1M' \
189 -c 'read -P 0 3M 3M' \
190 -f raw
"$TEST_IMG".data |
193 echo -n "qcow2 file size after I/O: "
194 du
-b $TEST_IMG | cut
-f1
197 echo "=== bdrv_co_block_status test for file and offset=0 ==="
200 _make_test_img
-o "data_file=$TEST_IMG.data" 64M
202 $QEMU_IO -c 'write -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
203 $QEMU_IO -c 'read -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
204 $QEMU_IMG map
--output=human
"$TEST_IMG" | _filter_testdir
205 $QEMU_IMG map
--output=json
"$TEST_IMG"
208 echo "=== Copy offloading ==="
211 # Make use of copy offloading if the test host can provide it
212 _make_test_img
-o "data_file=$TEST_IMG.data" 64M
213 $QEMU_IMG convert
-f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG"
214 $QEMU_IMG compare
-f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG"
216 # blkdebug doesn't support copy offloading, so this tests the error path
217 $QEMU_IMG amend
-f $IMGFMT -o "data_file=blkdebug::$TEST_IMG.data" "$TEST_IMG"
218 $QEMU_IMG convert
-f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG"
219 $QEMU_IMG compare
-f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG"
222 echo "=== Flushing should flush the data file ==="
225 # We are going to flush a qcow2 file with a blkdebug node inserted
226 # between the qcow2 node and its data file node. The blkdebug node
227 # will return an error for all flushes and so we if the data file is
228 # flushed, we will see qemu-io return an error.
230 # We need to write something or the flush will not do anything; we
231 # also need -t writeback so the write is not done as a FUA write
232 # (which would then fail thanks to the implicit flush)
233 $QEMU_IO -c 'write 0 512' -c flush \
239 'filename': '$TEST_IMG'
242 'driver': 'blkdebug',
249 'filename': '$TEST_IMG.data'
255 result
=${PIPESTATUS[0]}
260 echo "ERROR: qemu-io succeeded, so the data file was not flushed"
263 echo "Success: qemu-io failed, so the data file was flushed"
266 echo "ERROR: qemu-io returned unknown exit code $result"