3 # Test case for image option amendment in qcow2.
5 # Copyright (C) 2013 Red Hat, Inc.
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.
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.
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/>.
22 owner
=mreitz@redhat.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
32 _rm_test_img
"$TEST_IMG.data"
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
40 # This tests qcow2-specific low-level functionality
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
48 _unsupported_imgopts
'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
51 echo "=== Testing version downgrade with zero expansion ==="
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
62 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
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
78 echo "=== Testing dirty version downgrade ==="
80 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
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
91 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
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
102 echo "=== Testing version upgrade and resize ==="
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
113 echo "=== Testing dirty lazy_refcounts=off ==="
115 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
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
126 echo "=== Testing backing file ==="
128 _make_test_img
-o "compat=1.1" 64M
129 TEST_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
137 echo "=== Testing invalid configurations ==="
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"
150 echo "=== Testing correct handling of unset value ==="
152 _make_test_img
-o "compat=1.1,cluster_size=1k" 64M
154 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
155 echo "Should not work:" # Just to know which of these tests actually fails
156 $QEMU_IMG amend
-o "cluster_size=64k" "$TEST_IMG"
159 echo "=== Testing zero expansion on inactive clusters ==="
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"
167 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
168 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
170 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
173 echo "=== Testing zero expansion on shared L2 table ==="
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"
180 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
181 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
183 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
186 echo "=== Testing zero expansion on backed image ==="
188 TEST_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"
194 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
197 echo "=== Testing zero expansion on backed inactive clusters ==="
199 TEST_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"
207 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
210 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
213 echo "=== Testing zero expansion on backed image with shared L2 table ==="
215 TEST_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"
222 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
223 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
225 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
228 echo "=== Testing preallocated zero expansion on full image ==="
230 TEST_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"
234 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
237 echo "=== Testing progress report without snapshot ==="
239 TEST_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"
249 echo "=== Testing progress report with snapshot ==="
251 TEST_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"
262 echo "=== Testing version downgrade with external data file ==="
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
270 echo "=== Try changing the external data file ==="
272 _make_test_img
-o "compat=1.1" 64M
273 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
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
279 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
282 $QEMU_IMG amend
-o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
283 _img_info
--format-specific
284 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
287 echo "=== Clearing and setting data-file-raw ==="
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
294 $QEMU_IMG amend
-o "data_file_raw=off" "$TEST_IMG"
295 _img_info
--format-specific
298 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
299 _img_info
--format-specific