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