xref: /openbmc/qemu/tests/qemu-iotests/061 (revision 6c3a9247)
1#!/usr/bin/env bash
2# group: rw auto
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
28status=1	# failure is the default!
29
30_cleanup()
31{
32    _cleanup_test_img
33    _rm_test_img "$TEST_IMG.data"
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
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
56
57echo
58echo "=== Testing version downgrade with zero expansion ==="
59echo
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
67
68echo
69echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
70echo
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
83
84echo
85echo "=== Testing dirty version downgrade ==="
86echo
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
96
97echo
98echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
99echo
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
107
108echo
109echo "=== Testing version upgrade and resize ==="
110echo
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
118
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"
127_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
128
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\)'
132
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\)'
137
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\)'
141
142$QEMU_IMG snapshot -a bar "$TEST_IMG" ||
143    echo "unexpected fail"
144_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
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"
149_qcow2_dump_header | grep '^\(version\|size\|nb_snap\)'
150
151_check_test_img
152
153
154echo
155echo "=== Testing dirty lazy_refcounts=off ==="
156echo
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
166
167echo
168echo "=== Testing backing file ==="
169echo
170_make_test_img -o "compat=1.1" 64M
171TEST_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
180
181echo
182echo "=== Testing invalid configurations ==="
183echo
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"
193
194echo
195echo "=== Testing correct handling of unset value ==="
196echo
197_make_test_img -o "compat=1.1,cluster_size=1k" 64M
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
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
216
217echo
218echo "=== Testing zero expansion on shared L2 table ==="
219echo
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
229
230echo
231echo "=== Testing zero expansion on backed image ==="
232echo
233TEST_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
240
241echo
242echo "=== Testing zero expansion on backed inactive clusters ==="
243echo
244TEST_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
256
257echo
258echo "=== Testing zero expansion on backed image with shared L2 table ==="
259echo
260TEST_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
271
272echo
273echo "=== Testing preallocated zero expansion on full image ==="
274echo
275TEST_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
280
281echo
282echo "=== Testing progress report without snapshot ==="
283echo
284TEST_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
292
293echo
294echo "=== Testing progress report with snapshot ==="
295echo
296TEST_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
305
306echo
307echo "=== Testing version downgrade with external data file ==="
308echo
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
313
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
320echo
321echo "=== Try changing the external data file ==="
322echo
323_make_test_img -o "compat=1.1" 64M
324$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
325
326echo
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
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
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
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
354# success, all done
355echo "*** done"
356rm -f $seq.full
357status=0
358