xref: /qemu/tests/qemu-iotests/061 (revision f9734d5d)
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" \
171	  "$TEST_IMG" && echo "unexpected pass"
172$QEMU_IMG rebase -u -b "$TEST_IMG.base" -F qcow2 "$TEST_IMG"
173$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
174$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
175_check_test_img
176
177echo
178echo "=== Testing invalid configurations ==="
179echo
180_make_test_img -o "compat=0.10" 64M
181$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
182$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
183$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
184$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
185$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
186$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
187$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
188$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
189
190echo
191echo "=== Testing correct handling of unset value ==="
192echo
193_make_test_img -o "compat=1.1,cluster_size=1k" 64M
194echo "Should work:"
195$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
196echo "Should not work:" # Just to know which of these tests actually fails
197$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
198
199echo
200echo "=== Testing zero expansion on inactive clusters ==="
201echo
202_make_test_img -o "compat=1.1" 64M
203$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
204$QEMU_IMG snapshot -c foo "$TEST_IMG"
205$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
206$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
207_check_test_img
208$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
209$QEMU_IMG snapshot -a foo "$TEST_IMG"
210_check_test_img
211$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
212
213echo
214echo "=== Testing zero expansion on shared L2 table ==="
215echo
216_make_test_img -o "compat=1.1" 64M
217$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
218$QEMU_IMG snapshot -c foo "$TEST_IMG"
219$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
220_check_test_img
221$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
222$QEMU_IMG snapshot -a foo "$TEST_IMG"
223_check_test_img
224$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
225
226echo
227echo "=== Testing zero expansion on backed image ==="
228echo
229TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
230$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
231_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
232$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
233$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
234_check_test_img
235$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
236
237echo
238echo "=== Testing zero expansion on backed inactive clusters ==="
239echo
240TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
241$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
242_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
243$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
244$QEMU_IMG snapshot -c foo "$TEST_IMG"
245$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
246$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
247_check_test_img
248$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
249$QEMU_IMG snapshot -a foo "$TEST_IMG"
250_check_test_img
251$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
252
253echo
254echo "=== Testing zero expansion on backed image with shared L2 table ==="
255echo
256TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M
257$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
258_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
259$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
260$QEMU_IMG snapshot -c foo "$TEST_IMG"
261$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
262_check_test_img
263$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
264$QEMU_IMG snapshot -a foo "$TEST_IMG"
265_check_test_img
266$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
267
268echo
269echo "=== Testing preallocated zero expansion on full image ==="
270echo
271TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M
272$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
273$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
274_check_test_img
275$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
276
277echo
278echo "=== Testing progress report without snapshot ==="
279echo
280TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
281_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
282$QEMU_IO -c "write -z 0  64k" \
283         -c "write -z 1G 64k" \
284         -c "write -z 2G 64k" \
285         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
286$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
287_check_test_img
288
289echo
290echo "=== Testing progress report with snapshot ==="
291echo
292TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G
293_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
294$QEMU_IO -c "write -z 0  64k" \
295         -c "write -z 1G 64k" \
296         -c "write -z 2G 64k" \
297         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
298$QEMU_IMG snapshot -c foo "$TEST_IMG"
299$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
300_check_test_img
301
302echo
303echo "=== Testing version downgrade with external data file ==="
304echo
305_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
306$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
307_img_info --format-specific
308_check_test_img
309
310echo
311echo "=== Testing version downgrade with extended L2 entries ==="
312echo
313_make_test_img -o "compat=1.1,extended_l2=on" 64M
314$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
315
316echo
317echo "=== Try changing the external data file ==="
318echo
319_make_test_img -o "compat=1.1" 64M
320$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
321
322echo
323_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M
324$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG"
325_img_info --format-specific
326TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
327
328echo
329$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
330_img_info --format-specific
331TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts
332
333echo
334echo "=== Clearing and setting data-file-raw ==="
335echo
336_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
337$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
338_img_info --format-specific
339_check_test_img
340
341$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG"
342_img_info --format-specific
343_check_test_img
344
345$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG"
346_img_info --format-specific
347_check_test_img
348
349
350# success, all done
351echo "*** done"
352rm -f $seq.full
353status=0
354