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