xref: /openbmc/qemu/tests/qemu-iotests/061 (revision eb85394f)
1#!/usr/bin/env bash
2#
3# Test case for image option amendment in qcow2.
4#
5# Copyright (C) 2013 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=mreitz@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29_cleanup()
30{
31    _cleanup_test_img
32    _rm_test_img "$TEST_IMG.data"
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39
40# This tests qcow2-specific low-level functionality
41_supported_fmt qcow2
42_supported_proto file
43_supported_os Linux
44# Conversion between different compat versions can only really work
45# with refcount_bits=16;
46# we have explicit tests for data_file here, but the whole test does
47# not work with it;
48# we have explicit tests for various cluster sizes, the remaining tests
49# require the default 64k cluster
50_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file cluster_size
51
52echo
53echo "=== Testing version downgrade with zero expansion ==="
54echo
55_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
56$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
57$PYTHON qcow2.py "$TEST_IMG" dump-header
58$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
59$PYTHON qcow2.py "$TEST_IMG" dump-header
60$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
61_check_test_img
62
63echo
64echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
65echo
66_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
67$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
68$QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
69$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
70$PYTHON qcow2.py "$TEST_IMG" dump-header
71$QEMU_IMG amend -o "compat=0.10" --image-opts \
72          driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
73$PYTHON qcow2.py "$TEST_IMG" dump-header
74$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
75$QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
76$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
77_check_test_img
78
79echo
80echo "=== Testing dirty version downgrade ==="
81echo
82_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
83_NO_VALGRIND \
84$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
85         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
86$PYTHON qcow2.py "$TEST_IMG" dump-header
87$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
88$PYTHON qcow2.py "$TEST_IMG" dump-header
89$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
90_check_test_img
91
92echo
93echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
94echo
95_make_test_img -o "compat=1.1" 64M
96$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
97$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
98$PYTHON qcow2.py "$TEST_IMG" dump-header
99$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
100$PYTHON qcow2.py "$TEST_IMG" dump-header
101_check_test_img
102
103echo
104echo "=== Testing version upgrade and resize ==="
105echo
106_make_test_img -o "compat=0.10" 64M
107$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
108$PYTHON qcow2.py "$TEST_IMG" dump-header
109$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
110$PYTHON qcow2.py "$TEST_IMG" dump-header
111$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
112_check_test_img
113
114echo
115echo "=== Testing resize with snapshots ==="
116echo
117_make_test_img -o "compat=0.10" 32M
118$QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
119$QEMU_IMG snapshot -c foo "$TEST_IMG"
120$QEMU_IMG resize "$TEST_IMG" 64M &&
121    echo "unexpected pass"
122$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
123
124$QEMU_IMG amend -o "compat=1.1,size=128M" "$TEST_IMG" ||
125    echo "unexpected fail"
126$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
127
128$QEMU_IMG snapshot -c bar "$TEST_IMG"
129$QEMU_IMG resize --shrink "$TEST_IMG" 64M ||
130    echo "unexpected fail"
131$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
132
133$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" &&
134    echo "unexpected pass"
135$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
136
137$QEMU_IMG snapshot -a bar "$TEST_IMG" ||
138    echo "unexpected fail"
139$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
140
141$QEMU_IMG snapshot -d bar "$TEST_IMG"
142$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" ||
143    echo "unexpected fail"
144$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
145
146_check_test_img
147
148
149echo
150echo "=== Testing dirty lazy_refcounts=off ==="
151echo
152_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
153_NO_VALGRIND \
154$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
155         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
156$PYTHON qcow2.py "$TEST_IMG" dump-header
157$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
158$PYTHON qcow2.py "$TEST_IMG" dump-header
159$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
160_check_test_img
161
162echo
163echo "=== Testing backing file ==="
164echo
165_make_test_img -o "compat=1.1" 64M
166TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
167$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
168$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
169$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
170$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
171_check_test_img
172
173echo
174echo "=== Testing invalid configurations ==="
175echo
176_make_test_img -o "compat=0.10" 64M
177$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
178$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
179$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
180$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
181$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
182$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
183$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
184$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
185
186echo
187echo "=== Testing correct handling of unset value ==="
188echo
189_make_test_img -o "compat=1.1,cluster_size=1k" 64M
190echo "Should work:"
191$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
192echo "Should not work:" # Just to know which of these tests actually fails
193$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
194
195echo
196echo "=== Testing zero expansion on inactive clusters ==="
197echo
198_make_test_img -o "compat=1.1" 64M
199$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
200$QEMU_IMG snapshot -c foo "$TEST_IMG"
201$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
202$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
203_check_test_img
204$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
205$QEMU_IMG snapshot -a foo "$TEST_IMG"
206_check_test_img
207$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
208
209echo
210echo "=== Testing zero expansion on shared L2 table ==="
211echo
212_make_test_img -o "compat=1.1" 64M
213$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
214$QEMU_IMG snapshot -c foo "$TEST_IMG"
215$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
216_check_test_img
217$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
218$QEMU_IMG snapshot -a foo "$TEST_IMG"
219_check_test_img
220$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
221
222echo
223echo "=== Testing zero expansion on backed image ==="
224echo
225TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
226$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
227_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
228$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
229$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
230_check_test_img
231$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
232
233echo
234echo "=== Testing zero expansion on backed inactive clusters ==="
235echo
236TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
237$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
238_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
239$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
240$QEMU_IMG snapshot -c foo "$TEST_IMG"
241$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
242$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
243_check_test_img
244$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
245$QEMU_IMG snapshot -a foo "$TEST_IMG"
246_check_test_img
247$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
248
249echo
250echo "=== Testing zero expansion on backed image with shared L2 table ==="
251echo
252TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
253$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
254_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
255$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
256$QEMU_IMG snapshot -c foo "$TEST_IMG"
257$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
258_check_test_img
259$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
260$QEMU_IMG snapshot -a foo "$TEST_IMG"
261_check_test_img
262$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
263
264echo
265echo "=== Testing preallocated zero expansion on full image ==="
266echo
267TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
268$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
269$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
270_check_test_img
271$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
272
273echo
274echo "=== Testing progress report without snapshot ==="
275echo
276TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
277_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
278$QEMU_IO -c "write -z 0  64k" \
279         -c "write -z 1G 64k" \
280         -c "write -z 2G 64k" \
281         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
282$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
283_check_test_img
284
285echo
286echo "=== Testing progress report with snapshot ==="
287echo
288TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
289_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
290$QEMU_IO -c "write -z 0  64k" \
291         -c "write -z 1G 64k" \
292         -c "write -z 2G 64k" \
293         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
294$QEMU_IMG snapshot -c foo "$TEST_IMG"
295$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
296_check_test_img
297
298echo
299echo "=== Testing version downgrade with external data file ==="
300echo
301_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
302$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
303_img_info --format-specific
304_check_test_img
305
306echo
307echo "=== Testing version downgrade with extended L2 entries ==="
308echo
309_make_test_img -o "compat=1.1,extended_l2=on" 64M
310$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
311
312echo
313echo "=== Try changing the external data file ==="
314echo
315_make_test_img -o "compat=1.1" 64M
316$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
317
318echo
319_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
320$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
321_img_info --format-specific
322TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
323
324echo
325$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
326_img_info --format-specific
327TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
328
329echo
330echo "=== Clearing and setting data-file-raw ==="
331echo
332_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
333$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
334_img_info --format-specific
335_check_test_img
336
337$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
338_img_info --format-specific
339_check_test_img
340
341$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
342_img_info --format-specific
343_check_test_img
344
345
346# success, all done
347echo "*** done"
348rm -f $seq.full
349status=0
350