4 # Test case for image option amendment in qcow2.
6 # Copyright (C) 2013 Red Hat, Inc.
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.
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.
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/>.
23 owner
=mreitz@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
33 _rm_test_img
"$TEST_IMG.data"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
41 # This tests qcow2-specific low-level functionality
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
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
54 echo "=== Testing version downgrade with zero expansion ==="
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
65 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
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
81 echo "=== Testing dirty version downgrade ==="
83 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
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
94 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
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
105 echo "=== Testing version upgrade and resize ==="
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
116 echo "=== Testing resize with snapshots ==="
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\)'
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\)'
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\)'
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\)'
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\)'
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\)'
151 echo "=== Testing dirty lazy_refcounts=off ==="
153 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
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
164 echo "=== Testing backing file ==="
166 _make_test_img
-o "compat=1.1" 64M
167 TEST_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
178 echo "=== Testing invalid configurations ==="
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"
191 echo "=== Testing correct handling of unset value ==="
193 _make_test_img
-o "compat=1.1,cluster_size=1k" 64M
195 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
196 echo "Should not work:" # Just to know which of these tests actually fails
197 $QEMU_IMG amend
-o "cluster_size=64k" "$TEST_IMG"
200 echo "=== Testing zero expansion on inactive clusters ==="
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"
208 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
209 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
211 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
214 echo "=== Testing zero expansion on shared L2 table ==="
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"
221 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
222 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
224 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
227 echo "=== Testing zero expansion on backed image ==="
229 TEST_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"
235 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
238 echo "=== Testing zero expansion on backed inactive clusters ==="
240 TEST_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"
248 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
249 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
251 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
254 echo "=== Testing zero expansion on backed image with shared L2 table ==="
256 TEST_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"
263 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
264 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
266 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
269 echo "=== Testing preallocated zero expansion on full image ==="
271 TEST_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"
275 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
278 echo "=== Testing progress report without snapshot ==="
280 TEST_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"
290 echo "=== Testing progress report with snapshot ==="
292 TEST_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"
303 echo "=== Testing version downgrade with external data file ==="
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
311 echo "=== Testing version downgrade with extended L2 entries ==="
313 _make_test_img
-o "compat=1.1,extended_l2=on" 64M
314 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
317 echo "=== Try changing the external data file ==="
319 _make_test_img
-o "compat=1.1" 64M
320 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
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
326 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
329 $QEMU_IMG amend
-o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
330 _img_info
--format-specific
331 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
334 echo "=== Clearing and setting data-file-raw ==="
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
341 $QEMU_IMG amend
-o "data_file_raw=off" "$TEST_IMG"
342 _img_info
--format-specific
345 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
346 _img_info
--format-specific