xref: /openbmc/qemu/tests/qemu-iotests/061 (revision 174d2d68)
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 dirty lazy_refcounts=off ==="
116echo
117_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M
118_NO_VALGRIND \
119$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
120         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
121$PYTHON qcow2.py "$TEST_IMG" dump-header
122$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
123$PYTHON qcow2.py "$TEST_IMG" dump-header
124$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
125_check_test_img
126
127echo
128echo "=== Testing backing file ==="
129echo
130_make_test_img -o "compat=1.1" 64M
131TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
132$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
133$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
134$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
135$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
136_check_test_img
137
138echo
139echo "=== Testing invalid configurations ==="
140echo
141_make_test_img -o "compat=0.10" 64M
142$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
143$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
144$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
145$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
146$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
147$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
148$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
149$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
150
151echo
152echo "=== Testing correct handling of unset value ==="
153echo
154_make_test_img -o "compat=1.1,cluster_size=1k" 64M
155echo "Should work:"
156$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
157echo "Should not work:" # Just to know which of these tests actually fails
158$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
159
160echo
161echo "=== Testing zero expansion on inactive clusters ==="
162echo
163_make_test_img -o "compat=1.1" 64M
164$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
165$QEMU_IMG snapshot -c foo "$TEST_IMG"
166$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
167$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
168_check_test_img
169$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
170$QEMU_IMG snapshot -a foo "$TEST_IMG"
171_check_test_img
172$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
173
174echo
175echo "=== Testing zero expansion on shared L2 table ==="
176echo
177_make_test_img -o "compat=1.1" 64M
178$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
179$QEMU_IMG snapshot -c foo "$TEST_IMG"
180$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
181_check_test_img
182$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
183$QEMU_IMG snapshot -a foo "$TEST_IMG"
184_check_test_img
185$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
186
187echo
188echo "=== Testing zero expansion on backed image ==="
189echo
190TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
191$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
192_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
193$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
194$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
195_check_test_img
196$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
197
198echo
199echo "=== Testing zero expansion on backed inactive clusters ==="
200echo
201TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
202$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
203_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
204$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
205$QEMU_IMG snapshot -c foo "$TEST_IMG"
206$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
207$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
208_check_test_img
209$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
210$QEMU_IMG snapshot -a foo "$TEST_IMG"
211_check_test_img
212$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
213
214echo
215echo "=== Testing zero expansion on backed image with shared L2 table ==="
216echo
217TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
218$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
219_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M
220$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
221$QEMU_IMG snapshot -c foo "$TEST_IMG"
222$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
223_check_test_img
224$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
225$QEMU_IMG snapshot -a foo "$TEST_IMG"
226_check_test_img
227$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
228
229echo
230echo "=== Testing preallocated zero expansion on full image ==="
231echo
232TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
233$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
234$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
235_check_test_img
236$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
237
238echo
239echo "=== Testing progress report without snapshot ==="
240echo
241TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
242_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G
243$QEMU_IO -c "write -z 0  64k" \
244         -c "write -z 1G 64k" \
245         -c "write -z 2G 64k" \
246         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
247$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
248_check_test_img
249
250echo
251echo "=== Testing progress report with snapshot ==="
252echo
253TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
254_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G
255$QEMU_IO -c "write -z 0  64k" \
256         -c "write -z 1G 64k" \
257         -c "write -z 2G 64k" \
258         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
259$QEMU_IMG snapshot -c foo "$TEST_IMG"
260$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
261_check_test_img
262
263echo
264echo "=== Testing version downgrade with external data file ==="
265echo
266_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
267$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
268_img_info --format-specific
269_check_test_img
270
271echo
272echo "=== Try changing the external data file ==="
273echo
274_make_test_img -o "compat=1.1" 64M
275$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
276
277echo
278_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
279$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
280_img_info --format-specific
281TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
282
283echo
284$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
285_img_info --format-specific
286TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
287
288echo
289echo "=== Clearing and setting data-file-raw ==="
290echo
291_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
292$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
293_img_info --format-specific
294_check_test_img
295
296$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
297_img_info --format-specific
298_check_test_img
299
300$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
301_img_info --format-specific
302_check_test_img
303
304
305# success, all done
306echo "*** done"
307rm -f $seq.full
308status=0
309