Merge remote-tracking branch 'remotes/kraxel/tags/ui-20210311-pull-request' into...
[qemu/ar7.git] / tests / qemu-iotests / 244
bloba46b44162766367233086b6f8e60c4ddb044717c
1 #!/usr/bin/env bash
2 # group: rw auto quick
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/>.
22 # creator
23 owner=kwolf@redhat.com
25 seq=$(basename $0)
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
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
39 . ./common.rc
40 . ./common.filter
42 _supported_fmt qcow2
43 _supported_proto file
44 _supported_os Linux
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
49 echo
50 echo "=== Create and open image with external data file ==="
51 echo
53 echo "With data file name in the image:"
54 _make_test_img -o "data_file=$TEST_IMG.data" 64M
55 _check_test_img
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
61 echo
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
69 echo
70 echo "Setting data-file for an image with internal data:"
71 _make_test_img 64M
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
76 echo
77 echo "=== Conflicting features ==="
78 echo
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" |
85 _filter_qemu_io
87 $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c -odata_file="$TEST_IMG.data" \
88 "$TEST_IMG.src" "$TEST_IMG"
90 echo
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" |
98 _filter_qemu_io
99 _check_test_img
101 echo
102 echo "Take an internal snapshot:"
104 $QEMU_IMG snapshot -c test "$TEST_IMG"
105 _check_test_img
107 echo
108 echo "=== Standalone image with external data file (efficient) ==="
109 echo
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)
119 # 2-3 MB: Discarded
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
124 echo
125 $QEMU_IO -c 'write -P 0x11 1M 4M' \
126 -c 'discard 2M 2M' \
127 -c 'write -z 3M 3M' \
128 -f $IMGFMT "$TEST_IMG" |
129 _filter_qemu_io
130 _check_test_img
132 echo
133 $QEMU_IMG map --output=json "$TEST_IMG"
135 echo
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" |
140 _filter_qemu_io
142 # Zero clusters are only marked as such in the qcow2 metadata, but contain
143 # stale data in the external data file
144 echo
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" |
150 _filter_qemu_io
153 echo -n "qcow2 file size after I/O: "
154 du -b $TEST_IMG | cut -f1
156 echo
157 echo "=== Standalone image with external data file (valid raw) ==="
158 echo
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
165 echo
166 $QEMU_IO -c 'write -P 0x11 1M 4M' \
167 -c 'discard 2M 2M' \
168 -c 'write -z 3M 3M' \
169 -f $IMGFMT "$TEST_IMG" |
170 _filter_qemu_io
171 _check_test_img
173 echo
174 $QEMU_IMG map --output=json "$TEST_IMG"
176 echo
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" |
181 _filter_qemu_io
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.
186 echo
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 |
191 _filter_qemu_io
193 echo -n "qcow2 file size after I/O: "
194 du -b $TEST_IMG | cut -f1
196 echo
197 echo "=== bdrv_co_block_status test for file and offset=0 ==="
198 echo
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"
207 echo
208 echo "=== Copy offloading ==="
209 echo
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"
221 echo
222 echo "=== Flushing should flush the data file ==="
223 echo
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 \
234 -t writeback \
235 "json:{
236 'driver': 'qcow2',
237 'file': {
238 'driver': 'file',
239 'filename': '$TEST_IMG'
241 'data-file': {
242 'driver': 'blkdebug',
243 'inject-error': [{
244 'event': 'none',
245 'iotype': 'flush'
247 'image': {
248 'driver': 'file',
249 'filename': '$TEST_IMG.data'
252 }" \
253 | _filter_qemu_io
255 result=${PIPESTATUS[0]}
256 echo
258 case $result in
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"
268 esac
270 # success, all done
271 echo "*** done"
272 rm -f $seq.full
273 status=0