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 # we have explicit tests for various cluster sizes, the remaining tests
49 # require the default 64k cluster
50 _unsupported_imgopts
'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file cluster_size
53 echo "=== Testing version downgrade with zero expansion ==="
55 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
56 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
57 $PYTHON qcow2.py
"$TEST_IMG" dump-header
58 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
59 $PYTHON qcow2.py
"$TEST_IMG" dump-header
60 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
64 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
66 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
67 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IO -c map
"$TEST_IMG" | _filter_qemu_io
70 $PYTHON qcow2.py
"$TEST_IMG" dump-header
71 $QEMU_IMG amend
-o "compat=0.10" --image-opts \
72 driver
=qcow2
,file.filename
=$TEST_IMG,l2-cache-entry-size
=4096
73 $PYTHON qcow2.py
"$TEST_IMG" dump-header
74 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
75 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
76 $QEMU_IO -c map
"$TEST_IMG" | _filter_qemu_io
80 echo "=== Testing dirty version downgrade ==="
82 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
84 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
85 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
86 $PYTHON qcow2.py
"$TEST_IMG" dump-header
87 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
88 $PYTHON qcow2.py
"$TEST_IMG" dump-header
89 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
93 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
95 _make_test_img
-o "compat=1.1" 64M
96 $PYTHON qcow2.py
"$TEST_IMG" set-feature-bit compatible
42
97 $PYTHON qcow2.py
"$TEST_IMG" set-feature-bit autoclear
42
98 $PYTHON qcow2.py
"$TEST_IMG" dump-header
99 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
100 $PYTHON qcow2.py
"$TEST_IMG" dump-header
104 echo "=== Testing version upgrade and resize ==="
106 _make_test_img
-o "compat=0.10" 64M
107 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
108 $PYTHON qcow2.py
"$TEST_IMG" dump-header
109 $QEMU_IMG amend
-o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
110 $PYTHON qcow2.py
"$TEST_IMG" dump-header
111 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
115 echo "=== Testing resize with snapshots ==="
117 _make_test_img
-o "compat=0.10" 32M
118 $QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
119 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
120 $QEMU_IMG resize
"$TEST_IMG" 64M
&&
121 echo "unexpected pass"
122 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
124 $QEMU_IMG amend
-o "compat=1.1,size=128M" "$TEST_IMG" ||
125 echo "unexpected fail"
126 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
128 $QEMU_IMG snapshot
-c bar
"$TEST_IMG"
129 $QEMU_IMG resize
--shrink "$TEST_IMG" 64M ||
130 echo "unexpected fail"
131 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
133 $QEMU_IMG amend
-o "compat=0.10,size=32M" "$TEST_IMG" &&
134 echo "unexpected pass"
135 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
137 $QEMU_IMG snapshot
-a bar
"$TEST_IMG" ||
138 echo "unexpected fail"
139 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
141 $QEMU_IMG snapshot
-d bar
"$TEST_IMG"
142 $QEMU_IMG amend
-o "compat=0.10,size=32M" "$TEST_IMG" ||
143 echo "unexpected fail"
144 $PYTHON qcow2.py
"$TEST_IMG" dump-header |
grep '^\(version\|size\|nb_snap\)'
150 echo "=== Testing dirty lazy_refcounts=off ==="
152 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
154 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
155 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
156 $PYTHON qcow2.py
"$TEST_IMG" dump-header
157 $QEMU_IMG amend
-o "lazy_refcounts=off" "$TEST_IMG"
158 $PYTHON qcow2.py
"$TEST_IMG" dump-header
159 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
163 echo "=== Testing backing file ==="
165 _make_test_img
-o "compat=1.1" 64M
166 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
167 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
168 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
169 $QEMU_IMG amend
-o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
170 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
174 echo "=== Testing invalid configurations ==="
176 _make_test_img
-o "compat=0.10" 64M
177 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
178 $QEMU_IMG amend
-o "compat=1.1" "$TEST_IMG" # actually valid
179 $QEMU_IMG amend
-o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
180 $QEMU_IMG amend
-o "compat=0.42" "$TEST_IMG"
181 $QEMU_IMG amend
-o "foo=bar" "$TEST_IMG"
182 $QEMU_IMG amend
-o "cluster_size=1k" "$TEST_IMG"
183 $QEMU_IMG amend
-o "encryption=on" "$TEST_IMG"
184 $QEMU_IMG amend
-o "preallocation=on" "$TEST_IMG"
187 echo "=== Testing correct handling of unset value ==="
189 _make_test_img
-o "compat=1.1,cluster_size=1k" 64M
191 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
192 echo "Should not work:" # Just to know which of these tests actually fails
193 $QEMU_IMG amend
-o "cluster_size=64k" "$TEST_IMG"
196 echo "=== Testing zero expansion on inactive clusters ==="
198 _make_test_img
-o "compat=1.1" 64M
199 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
200 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
201 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
202 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
204 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
205 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
207 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
210 echo "=== Testing zero expansion on shared L2 table ==="
212 _make_test_img
-o "compat=1.1" 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"
217 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
218 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
220 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
223 echo "=== Testing zero expansion on backed image ==="
225 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
226 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
227 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
228 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
229 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
231 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
234 echo "=== Testing zero expansion on backed inactive clusters ==="
236 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
237 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
238 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
239 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
240 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
241 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
242 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
244 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
245 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
247 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
250 echo "=== Testing zero expansion on backed image with shared L2 table ==="
252 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
253 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
254 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
255 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
256 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
257 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
259 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
260 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
262 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
265 echo "=== Testing preallocated zero expansion on full image ==="
267 TEST_IMG
="$TEST_IMG" _make_test_img
-o "compat=1.1" 64M
268 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
269 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
271 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
274 echo "=== Testing progress report without snapshot ==="
276 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 4G
277 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
278 $QEMU_IO -c "write -z 0 64k" \
279 -c "write -z 1G 64k" \
280 -c "write -z 2G 64k" \
281 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
282 $QEMU_IMG amend
-p -o "compat=0.10" "$TEST_IMG"
286 echo "=== Testing progress report with snapshot ==="
288 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 4G
289 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
290 $QEMU_IO -c "write -z 0 64k" \
291 -c "write -z 1G 64k" \
292 -c "write -z 2G 64k" \
293 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
294 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
295 $QEMU_IMG amend
-p -o "compat=0.10" "$TEST_IMG"
299 echo "=== Testing version downgrade with external data file ==="
301 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data" 64M
302 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
303 _img_info
--format-specific
307 echo "=== Testing version downgrade with extended L2 entries ==="
309 _make_test_img
-o "compat=1.1,extended_l2=on" 64M
310 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
313 echo "=== Try changing the external data file ==="
315 _make_test_img
-o "compat=1.1" 64M
316 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
319 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data" 64M
320 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
321 _img_info
--format-specific
322 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
325 $QEMU_IMG amend
-o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
326 _img_info
--format-specific
327 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
330 echo "=== Clearing and setting data-file-raw ==="
332 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
333 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
334 _img_info
--format-specific
337 $QEMU_IMG amend
-o "data_file_raw=off" "$TEST_IMG"
338 _img_info
--format-specific
341 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
342 _img_info
--format-specific