]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/061
Merge remote-tracking branch 'remotes/hdeller/tags/hppa-updates-pull-request' into...
[mirror_qemu.git] / tests / qemu-iotests / 061
CommitLineData
11a82d14 1#!/usr/bin/env bash
9dd003a9 2# group: rw auto
a8110c3d
HR
3#
4# Test case for image option amendment in qcow2.
5#
6# Copyright (C) 2013 Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21
22# creator
23owner=mreitz@redhat.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
a8110c3d
HR
28status=1 # failure is the default!
29
30_cleanup()
31{
ac40260d 32 _cleanup_test_img
f91ecbd7 33 _rm_test_img "$TEST_IMG.data"
a8110c3d
HR
34}
35trap "_cleanup; exit \$status" 0 1 2 3 15
36
37# get standard environment, filters and checks
38. ./common.rc
39. ./common.filter
40
e696f335 41# This tests qcow2-specific low-level functionality
a8110c3d 42_supported_fmt qcow2
1f7bf7d0 43_supported_proto file
a8110c3d 44_supported_os Linux
407fb56a 45# Conversion between different compat versions can only really work
3be2024a
HR
46# with refcount_bits=16;
47# we have explicit tests for data_file here, but the whole test does
e7be13ad
EB
48# not work with it;
49# we have explicit tests for various cluster sizes, the remaining tests
50# require the default 64k cluster
e287a351
VSO
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
a8110c3d
HR
56
57echo
58echo "=== Testing version downgrade with zero expansion ==="
59echo
407fb56a 60_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
a8110c3d 61$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
984d7a52 62_qcow2_dump_header
a8110c3d 63$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
984d7a52 64_qcow2_dump_header
a8110c3d
HR
65$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
66_check_test_img
67
2ecec911
AG
68echo
69echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
70echo
407fb56a 71_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
2ecec911
AG
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
984d7a52 75_qcow2_dump_header
2ecec911
AG
76$QEMU_IMG amend -o "compat=0.10" --image-opts \
77 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
984d7a52 78_qcow2_dump_header
2ecec911
AG
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
83
a8110c3d
HR
84echo
85echo "=== Testing dirty version downgrade ==="
86echo
407fb56a 87_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
8af224d6 88_NO_VALGRIND \
efd0fbbc
AG
89$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
90 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
984d7a52 91_qcow2_dump_header
a8110c3d 92$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
984d7a52 93_qcow2_dump_header
a8110c3d
HR
94$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
95_check_test_img
96
97echo
98echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
99echo
407fb56a 100_make_test_img -o "compat=1.1" 64M
ea81ca9d
HR
101$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
102$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
984d7a52 103_qcow2_dump_header
a8110c3d 104$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
984d7a52 105_qcow2_dump_header
a8110c3d
HR
106_check_test_img
107
108echo
109echo "=== Testing version upgrade and resize ==="
110echo
407fb56a 111_make_test_img -o "compat=0.10" 64M
a8110c3d 112$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
984d7a52 113_qcow2_dump_header
a8110c3d 114$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
984d7a52 115_qcow2_dump_header
a8110c3d
HR
116$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
117_check_test_img
118
7fa140ab
EB
119echo
120echo "=== Testing resize with snapshots ==="
121echo
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"
984d7a52 127_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
128
129$QEMU_IMG amend -o "compat=1.1,size=128M" "$TEST_IMG" ||
130 echo "unexpected fail"
984d7a52 131_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
132
133$QEMU_IMG snapshot -c bar "$TEST_IMG"
134$QEMU_IMG resize --shrink "$TEST_IMG" 64M ||
135 echo "unexpected fail"
984d7a52 136_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
137
138$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" &&
139 echo "unexpected pass"
984d7a52 140_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
141
142$QEMU_IMG snapshot -a bar "$TEST_IMG" ||
143 echo "unexpected fail"
984d7a52 144_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
145
146$QEMU_IMG snapshot -d bar "$TEST_IMG"
147$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" ||
148 echo "unexpected fail"
984d7a52 149_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
7fa140ab
EB
150
151_check_test_img
152
153
a8110c3d
HR
154echo
155echo "=== Testing dirty lazy_refcounts=off ==="
156echo
407fb56a 157_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
8af224d6 158_NO_VALGRIND \
efd0fbbc
AG
159$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
160 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
984d7a52 161_qcow2_dump_header
a8110c3d 162$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
984d7a52 163_qcow2_dump_header
a8110c3d
HR
164$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
165_check_test_img
166
167echo
168echo "=== Testing backing file ==="
169echo
407fb56a
HR
170_make_test_img -o "compat=1.1" 64M
171TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
a8110c3d
HR
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
5a385bf5
EB
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"
a8110c3d
HR
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
180
181echo
182echo "=== Testing invalid configurations ==="
183echo
407fb56a 184_make_test_img -o "compat=0.10" 64M
a8110c3d
HR
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"
193
194echo
195echo "=== Testing correct handling of unset value ==="
196echo
407fb56a 197_make_test_img -o "compat=1.1,cluster_size=1k" 64M
a8110c3d
HR
198echo "Should work:"
199$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
200echo "Should not work:" # Just to know which of these tests actually fails
201$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
202
203echo
204echo "=== Testing zero expansion on inactive clusters ==="
205echo
407fb56a 206_make_test_img -o "compat=1.1" 64M
a8110c3d
HR
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
216
d982919d
HR
217echo
218echo "=== Testing zero expansion on shared L2 table ==="
219echo
407fb56a 220_make_test_img -o "compat=1.1" 64M
d982919d
HR
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
229
a8110c3d
HR
230echo
231echo "=== Testing zero expansion on backed image ==="
232echo
407fb56a 233TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
a8110c3d 234$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
b66ff2c2 235_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
a8110c3d
HR
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
240
241echo
242echo "=== Testing zero expansion on backed inactive clusters ==="
243echo
407fb56a 244TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
a8110c3d 245$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
b66ff2c2 246_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
a8110c3d
HR
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
256
d982919d
HR
257echo
258echo "=== Testing zero expansion on backed image with shared L2 table ==="
259echo
407fb56a 260TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
d982919d 261$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
b66ff2c2 262_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
d982919d
HR
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
271
fd9e03e6
HR
272echo
273echo "=== Testing preallocated zero expansion on full image ==="
274echo
407fb56a 275TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
fd9e03e6
HR
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
280
78fa6582
HR
281echo
282echo "=== Testing progress report without snapshot ==="
283echo
407fb56a 284TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
b66ff2c2 285_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
78fa6582
HR
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
292
293echo
294echo "=== Testing progress report with snapshot ==="
295echo
407fb56a 296TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
b66ff2c2 297_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
78fa6582
HR
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
305
ac40260d
KW
306echo
307echo "=== Testing version downgrade with external data file ==="
308echo
407fb56a 309_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
ac40260d
KW
310$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
311_img_info --format-specific
312_check_test_img
313
7bbb5920
AG
314echo
315echo "=== Testing version downgrade with extended L2 entries ==="
316echo
317_make_test_img -o "compat=1.1,extended_l2=on" 64M
318$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
319
ac40260d
KW
320echo
321echo "=== Try changing the external data file ==="
322echo
407fb56a 323_make_test_img -o "compat=1.1" 64M
ac40260d
KW
324$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
325
326echo
407fb56a 327_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
ac40260d
KW
328$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
329_img_info --format-specific
330TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
331
332echo
333$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
334_img_info --format-specific
335TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
336
337echo
338echo "=== Clearing and setting data-file-raw ==="
339echo
407fb56a 340_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
ac40260d
KW
341$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
342_img_info --format-specific
343_check_test_img
344
345$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
346_img_info --format-specific
347_check_test_img
348
349$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
350_img_info --format-specific
351_check_test_img
352
353
a8110c3d
HR
354# success, all done
355echo "*** done"
356rm -f $seq.full
357status=0