Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / qemu-iotests / 061
blob509ad247cdc71a2489f322e9deec43e05234d65f
1 #!/usr/bin/env bash
2 # group: rw auto
4 # Test case for image option amendment in qcow2.
6 # Copyright (C) 2013 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=hreitz@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"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 # This tests qcow2-specific low-level functionality
42 _supported_fmt qcow2
43 _supported_proto file
44 _supported_os Linux
45 # Conversion between different compat versions can only really work
46 # with refcount_bits=16;
47 # we have explicit tests for data_file here, but the whole test does
48 # not work with it;
49 # we have explicit tests for various cluster sizes, the remaining tests
50 # require the default 64k cluster
51 # we don't have explicit tests for zstd qcow2 compression type, as zstd may be
52 # not compiled in. And we can't create compat images with comression type
53 # extension
54 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file \
55 cluster_size compression_type
57 echo
58 echo "=== Testing version downgrade with zero expansion ==="
59 echo
60 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
61 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
62 _qcow2_dump_header
63 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
64 _qcow2_dump_header
65 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
66 _check_test_img
68 echo
69 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
70 echo
71 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
72 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
73 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
74 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
75 _qcow2_dump_header
76 $QEMU_IMG amend -o "compat=0.10" --image-opts \
77 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
78 _qcow2_dump_header
79 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
80 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
81 $QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
82 _check_test_img
84 echo
85 echo "=== Testing dirty version downgrade ==="
86 echo
87 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
88 _NO_VALGRIND \
89 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
90 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
91 _qcow2_dump_header
92 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
93 _qcow2_dump_header
94 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
95 _check_test_img
97 echo
98 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
99 echo
100 _make_test_img -o "compat=1.1" 64M
101 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
102 $PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
103 _qcow2_dump_header
104 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
105 _qcow2_dump_header
106 _check_test_img
108 echo
109 echo "=== Testing version upgrade and resize ==="
110 echo
111 _make_test_img -o "compat=0.10" 64M
112 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
113 _qcow2_dump_header
114 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
115 _qcow2_dump_header
116 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
117 _check_test_img
119 echo
120 echo "=== Testing resize with snapshots ==="
121 echo
122 _make_test_img -o "compat=0.10" 32M
123 $QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
124 $QEMU_IMG snapshot -c foo "$TEST_IMG"
125 $QEMU_IMG resize "$TEST_IMG" 64M &&
126 echo "unexpected pass"
127 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
129 $QEMU_IMG amend -o "compat=1.1,size=128M" "$TEST_IMG" ||
130 echo "unexpected fail"
131 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
133 $QEMU_IMG snapshot -c bar "$TEST_IMG"
134 $QEMU_IMG resize --shrink "$TEST_IMG" 64M ||
135 echo "unexpected fail"
136 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
138 $QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" &&
139 echo "unexpected pass"
140 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
142 $QEMU_IMG snapshot -a bar "$TEST_IMG" ||
143 echo "unexpected fail"
144 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
146 $QEMU_IMG snapshot -d bar "$TEST_IMG"
147 $QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" ||
148 echo "unexpected fail"
149 _qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
151 _check_test_img
154 echo
155 echo "=== Testing dirty lazy_refcounts=off ==="
156 echo
157 _make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
158 _NO_VALGRIND \
159 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
160 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
161 _qcow2_dump_header
162 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
163 _qcow2_dump_header
164 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
165 _check_test_img
167 echo
168 echo "=== Testing backing file ==="
169 echo
170 _make_test_img -o "compat=1.1" 64M
171 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
172 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
173 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
174 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" \
175 "$TEST_IMG" && echo "unexpected pass"
176 $QEMU_IMG rebase -u -b "$TEST_IMG.base" -F qcow2 "$TEST_IMG"
177 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
178 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
179 _check_test_img
181 echo
182 echo "=== Testing invalid configurations ==="
183 echo
184 _make_test_img -o "compat=0.10" 64M
185 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
186 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
187 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
188 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
189 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
190 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
191 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
192 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
194 echo
195 echo "=== Testing correct handling of unset value ==="
196 echo
197 _make_test_img -o "compat=1.1,cluster_size=1k" 64M
198 echo "Should work:"
199 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
200 echo "Should not work:" # Just to know which of these tests actually fails
201 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
203 echo
204 echo "=== Testing zero expansion on inactive clusters ==="
205 echo
206 _make_test_img -o "compat=1.1" 64M
207 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IMG snapshot -c foo "$TEST_IMG"
209 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
210 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
211 _check_test_img
212 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
213 $QEMU_IMG snapshot -a foo "$TEST_IMG"
214 _check_test_img
215 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
217 echo
218 echo "=== Testing zero expansion on shared L2 table ==="
219 echo
220 _make_test_img -o "compat=1.1" 64M
221 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
222 $QEMU_IMG snapshot -c foo "$TEST_IMG"
223 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
224 _check_test_img
225 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
226 $QEMU_IMG snapshot -a foo "$TEST_IMG"
227 _check_test_img
228 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
230 echo
231 echo "=== Testing zero expansion on backed image ==="
232 echo
233 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
234 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
235 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
236 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
237 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
238 _check_test_img
239 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
241 echo
242 echo "=== Testing zero expansion on backed inactive clusters ==="
243 echo
244 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
245 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
246 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
247 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
248 $QEMU_IMG snapshot -c foo "$TEST_IMG"
249 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
250 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
251 _check_test_img
252 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
253 $QEMU_IMG snapshot -a foo "$TEST_IMG"
254 _check_test_img
255 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
257 echo
258 echo "=== Testing zero expansion on backed image with shared L2 table ==="
259 echo
260 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
261 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
262 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
263 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
264 $QEMU_IMG snapshot -c foo "$TEST_IMG"
265 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
266 _check_test_img
267 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
268 $QEMU_IMG snapshot -a foo "$TEST_IMG"
269 _check_test_img
270 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
272 echo
273 echo "=== Testing preallocated zero expansion on full image ==="
274 echo
275 TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
276 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
277 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
278 _check_test_img
279 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
281 echo
282 echo "=== Testing progress report without snapshot ==="
283 echo
284 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
285 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
286 $QEMU_IO -c "write -z 0 64k" \
287 -c "write -z 1G 64k" \
288 -c "write -z 2G 64k" \
289 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
290 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
291 _check_test_img
293 echo
294 echo "=== Testing progress report with snapshot ==="
295 echo
296 TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
297 _make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
298 $QEMU_IO -c "write -z 0 64k" \
299 -c "write -z 1G 64k" \
300 -c "write -z 2G 64k" \
301 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
302 $QEMU_IMG snapshot -c foo "$TEST_IMG"
303 $QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
304 _check_test_img
306 echo
307 echo "=== Testing version downgrade with external data file ==="
308 echo
309 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
310 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
311 _img_info --format-specific
312 _check_test_img
314 echo
315 echo "=== Testing version downgrade with extended L2 entries ==="
316 echo
317 _make_test_img -o "compat=1.1,extended_l2=on" 64M
318 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
320 echo
321 echo "=== Try changing the external data file ==="
322 echo
323 _make_test_img -o "compat=1.1" 64M
324 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
326 echo
327 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
328 $QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
329 _img_info --format-specific
330 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
332 echo
333 $QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
334 _img_info --format-specific
335 TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
337 echo
338 echo "=== Clearing and setting data-file-raw ==="
339 echo
340 _make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
341 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
342 _img_info --format-specific
343 _check_test_img
345 $QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
346 _img_info --format-specific
347 _check_test_img
349 $QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
350 _img_info --format-specific
351 _check_test_img
354 # success, all done
355 echo "*** done"
356 rm -f $seq.full
357 status=0