xref: /openbmc/qemu/tests/qemu-iotests/061 (revision 5b76dd13)
1#!/bin/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}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38
39# This tests qocw2-specific low-level functionality
40_supported_fmt qcow2
41_supported_proto file
42_supported_os Linux
43
44echo
45echo "=== Testing version downgrade with zero expansion ==="
46echo
47IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
48$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
49$PYTHON qcow2.py "$TEST_IMG" dump-header
50$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
51$PYTHON qcow2.py "$TEST_IMG" dump-header
52$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
53_check_test_img
54
55echo
56echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
57echo
58IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
59$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
60$QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
61$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
62$PYTHON qcow2.py "$TEST_IMG" dump-header
63$QEMU_IMG amend -o "compat=0.10" --image-opts \
64          driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096
65$PYTHON qcow2.py "$TEST_IMG" dump-header
66$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
67$QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
68$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io
69_check_test_img
70
71echo
72echo "=== Testing dirty version downgrade ==="
73echo
74IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
75$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
76         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
77$PYTHON qcow2.py "$TEST_IMG" dump-header
78$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
79$PYTHON qcow2.py "$TEST_IMG" dump-header
80$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
81_check_test_img
82
83echo
84echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
85echo
86IMGOPTS="compat=1.1" _make_test_img 64M
87$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42
88$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
89$PYTHON qcow2.py "$TEST_IMG" dump-header
90$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
91$PYTHON qcow2.py "$TEST_IMG" dump-header
92_check_test_img
93
94echo
95echo "=== Testing version upgrade and resize ==="
96echo
97IMGOPTS="compat=0.10" _make_test_img 64M
98$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
99$PYTHON qcow2.py "$TEST_IMG" dump-header
100$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
101$PYTHON qcow2.py "$TEST_IMG" dump-header
102$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
103_check_test_img
104
105echo
106echo "=== Testing dirty lazy_refcounts=off ==="
107echo
108IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
109$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
110         -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
111$PYTHON qcow2.py "$TEST_IMG" dump-header
112$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
113$PYTHON qcow2.py "$TEST_IMG" dump-header
114$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
115_check_test_img
116
117echo
118echo "=== Testing backing file ==="
119echo
120IMGOPTS="compat=1.1" _make_test_img 64M
121IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
122$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
123$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
124$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
125$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
126_check_test_img
127
128echo
129echo "=== Testing invalid configurations ==="
130echo
131IMGOPTS="compat=0.10" _make_test_img 64M
132$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
133$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
134$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
135$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
136$QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
137$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
138$QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
139$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
140
141echo
142echo "=== Testing correct handling of unset value ==="
143echo
144IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M
145echo "Should work:"
146$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
147echo "Should not work:" # Just to know which of these tests actually fails
148$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
149
150echo
151echo "=== Testing zero expansion on inactive clusters ==="
152echo
153IMGOPTS="compat=1.1" _make_test_img 64M
154$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
155$QEMU_IMG snapshot -c foo "$TEST_IMG"
156$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
157$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
158_check_test_img
159$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
160$QEMU_IMG snapshot -a foo "$TEST_IMG"
161_check_test_img
162$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
163
164echo
165echo "=== Testing zero expansion on shared L2 table ==="
166echo
167IMGOPTS="compat=1.1" _make_test_img 64M
168$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
169$QEMU_IMG snapshot -c foo "$TEST_IMG"
170$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
171_check_test_img
172$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
173$QEMU_IMG snapshot -a foo "$TEST_IMG"
174_check_test_img
175$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
176
177echo
178echo "=== Testing zero expansion on backed image ==="
179echo
180IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
181$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
182IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
183$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
184$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
185_check_test_img
186$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
187
188echo
189echo "=== Testing zero expansion on backed inactive clusters ==="
190echo
191IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
192$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
193IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
194$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
195$QEMU_IMG snapshot -c foo "$TEST_IMG"
196$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
197$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
198_check_test_img
199$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
200$QEMU_IMG snapshot -a foo "$TEST_IMG"
201_check_test_img
202$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
203
204echo
205echo "=== Testing zero expansion on backed image with shared L2 table ==="
206echo
207IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
208$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
209IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M
210$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
211$QEMU_IMG snapshot -c foo "$TEST_IMG"
212$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
213_check_test_img
214$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
215$QEMU_IMG snapshot -a foo "$TEST_IMG"
216_check_test_img
217$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
218
219echo
220echo "=== Testing preallocated zero expansion on full image ==="
221echo
222IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M
223$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
224$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
225_check_test_img
226$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
227
228echo
229echo "=== Testing progress report without snapshot ==="
230echo
231IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
232IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
233$QEMU_IO -c "write -z 0  64k" \
234         -c "write -z 1G 64k" \
235         -c "write -z 2G 64k" \
236         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
237$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
238_check_test_img
239
240echo
241echo "=== Testing progress report with snapshot ==="
242echo
243IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G
244IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G
245$QEMU_IO -c "write -z 0  64k" \
246         -c "write -z 1G 64k" \
247         -c "write -z 2G 64k" \
248         -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
249$QEMU_IMG snapshot -c foo "$TEST_IMG"
250$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG"
251_check_test_img
252
253# success, all done
254echo "*** done"
255rm -f $seq.full
256status=0
257