xref: /openbmc/qemu/tests/qemu-iotests/061 (revision 64c9a921)
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_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file cluster_size
52
53echo
54echo "=== Testing version downgrade with zero expansion ==="
55echo
56_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
57$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
58$PYTHON qcow2.py "$TEST_IMG" dump-header
59$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
60$PYTHON qcow2.py "$TEST_IMG" dump-header
61$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
62_check_test_img
63
64echo
65echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
66echo
67_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
68$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
69$QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
70$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
71$PYTHON qcow2.py "$TEST_IMG" dump-header
72$QEMU_IMG amend -o "compat=0.10" --image-opts \
73          driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
74$PYTHON qcow2.py "$TEST_IMG" dump-header
75$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
76$QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
77$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
78_check_test_img
79
80echo
81echo "=== Testing dirty version downgrade ==="
82echo
83_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
84_NO_VALGRIND \
85$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
86         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
87$PYTHON qcow2.py "$TEST_IMG" dump-header
88$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
89$PYTHON qcow2.py "$TEST_IMG" dump-header
90$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
91_check_test_img
92
93echo
94echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
95echo
96_make_test_img -o "compat=1.1" 64M
97$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
98$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
99$PYTHON qcow2.py "$TEST_IMG" dump-header
100$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
101$PYTHON qcow2.py "$TEST_IMG" dump-header
102_check_test_img
103
104echo
105echo "=== Testing version upgrade and resize ==="
106echo
107_make_test_img -o "compat=0.10" 64M
108$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
109$PYTHON qcow2.py "$TEST_IMG" dump-header
110$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
111$PYTHON qcow2.py "$TEST_IMG" dump-header
112$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
113_check_test_img
114
115echo
116echo "=== Testing resize with snapshots ==="
117echo
118_make_test_img -o "compat=0.10" 32M
119$QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
120$QEMU_IMG snapshot -c foo "$TEST_IMG"
121$QEMU_IMG resize "$TEST_IMG" 64M &&
122    echo "unexpected pass"
123$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
124
125$QEMU_IMG amend -o "compat=1.1,size=128M" "$TEST_IMG" ||
126    echo "unexpected fail"
127$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
128
129$QEMU_IMG snapshot -c bar "$TEST_IMG"
130$QEMU_IMG resize --shrink "$TEST_IMG" 64M ||
131    echo "unexpected fail"
132$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
133
134$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" &&
135    echo "unexpected pass"
136$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
137
138$QEMU_IMG snapshot -a bar "$TEST_IMG" ||
139    echo "unexpected fail"
140$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
141
142$QEMU_IMG snapshot -d bar "$TEST_IMG"
143$QEMU_IMG amend -o "compat=0.10,size=32M" "$TEST_IMG" ||
144    echo "unexpected fail"
145$PYTHON qcow2.py "$TEST_IMG" dump-header | grep '^\(version\|size\|nb_snap\)'
146
147_check_test_img
148
149
150echo
151echo "=== Testing dirty lazy_refcounts=off ==="
152echo
153_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
154_NO_VALGRIND \
155$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
156         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
157$PYTHON qcow2.py "$TEST_IMG" dump-header
158$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
159$PYTHON qcow2.py "$TEST_IMG" dump-header
160$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
161_check_test_img
162
163echo
164echo "=== Testing backing file ==="
165echo
166_make_test_img -o "compat=1.1" 64M
167TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
168$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
169$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
170$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
171$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
172_check_test_img
173
174echo
175echo "=== Testing invalid configurations ==="
176echo
177_make_test_img -o "compat=0.10" 64M
178$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
179$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
180$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
181$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
182$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
183$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
184$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
185$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
186
187echo
188echo "=== Testing correct handling of unset value ==="
189echo
190_make_test_img -o "compat=1.1,cluster_size=1k" 64M
191echo "Should work:"
192$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
193echo "Should not work:" # Just to know which of these tests actually fails
194$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
195
196echo
197echo "=== Testing zero expansion on inactive clusters ==="
198echo
199_make_test_img -o "compat=1.1" 64M
200$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
201$QEMU_IMG snapshot -c foo "$TEST_IMG"
202$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
203$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
204_check_test_img
205$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
206$QEMU_IMG snapshot -a foo "$TEST_IMG"
207_check_test_img
208$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
209
210echo
211echo "=== Testing zero expansion on shared L2 table ==="
212echo
213_make_test_img -o "compat=1.1" 64M
214$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
215$QEMU_IMG snapshot -c foo "$TEST_IMG"
216$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
217_check_test_img
218$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
219$QEMU_IMG snapshot -a foo "$TEST_IMG"
220_check_test_img
221$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
222
223echo
224echo "=== Testing zero expansion on backed image ==="
225echo
226TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
227$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
228_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
229$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
230$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
231_check_test_img
232$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
233
234echo
235echo "=== Testing zero expansion on backed inactive clusters ==="
236echo
237TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
238$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
239_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
240$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
241$QEMU_IMG snapshot -c foo "$TEST_IMG"
242$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
243$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
244_check_test_img
245$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
246$QEMU_IMG snapshot -a foo "$TEST_IMG"
247_check_test_img
248$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
249
250echo
251echo "=== Testing zero expansion on backed image with shared L2 table ==="
252echo
253TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
254$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
255_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
256$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
257$QEMU_IMG snapshot -c foo "$TEST_IMG"
258$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
259_check_test_img
260$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
261$QEMU_IMG snapshot -a foo "$TEST_IMG"
262_check_test_img
263$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
264
265echo
266echo "=== Testing preallocated zero expansion on full image ==="
267echo
268TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
269$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
270$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
271_check_test_img
272$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
273
274echo
275echo "=== Testing progress report without snapshot ==="
276echo
277TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
278_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
279$QEMU_IO -c "write -z 0  64k" \
280         -c "write -z 1G 64k" \
281         -c "write -z 2G 64k" \
282         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
283$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
284_check_test_img
285
286echo
287echo "=== Testing progress report with snapshot ==="
288echo
289TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
290_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
291$QEMU_IO -c "write -z 0  64k" \
292         -c "write -z 1G 64k" \
293         -c "write -z 2G 64k" \
294         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
295$QEMU_IMG snapshot -c foo "$TEST_IMG"
296$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
297_check_test_img
298
299echo
300echo "=== Testing version downgrade with external data file ==="
301echo
302_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
303$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
304_img_info --format-specific
305_check_test_img
306
307echo
308echo "=== Testing version downgrade with extended L2 entries ==="
309echo
310_make_test_img -o "compat=1.1,extended_l2=on" 64M
311$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
312
313echo
314echo "=== Try changing the external data file ==="
315echo
316_make_test_img -o "compat=1.1" 64M
317$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
318
319echo
320_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
321$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
322_img_info --format-specific
323TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
324
325echo
326$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
327_img_info --format-specific
328TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
329
330echo
331echo "=== Clearing and setting data-file-raw ==="
332echo
333_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
334$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
335_img_info --format-specific
336_check_test_img
337
338$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
339_img_info --format-specific
340_check_test_img
341
342$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
343_img_info --format-specific
344_check_test_img
345
346
347# success, all done
348echo "*** done"
349rm -f $seq.full
350status=0
351