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
=hreitz@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 # we don't have explicit tests for zstd qcow2 compression type, as zstd may be
52 # not compiled in. And we can't create compat images with comression type
54 _unsupported_imgopts
'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file \
55 cluster_size compression_type
58 echo "=== Testing version downgrade with zero expansion ==="
60 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
61 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
63 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
65 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
69 echo "=== Testing version downgrade with zero expansion and 4K cache entries ==="
71 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
72 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
73 $QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io
74 $QEMU_IO -c map
"$TEST_IMG" | _filter_qemu_io
76 $QEMU_IMG amend
-o "compat=0.10" --image-opts \
77 driver
=qcow2
,file.filename
=$TEST_IMG,l2-cache-entry-size
=4096
79 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
80 $QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io
81 $QEMU_IO -c map
"$TEST_IMG" | _filter_qemu_io
85 echo "=== Testing dirty version downgrade ==="
87 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
89 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
90 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
92 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
94 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
98 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
100 _make_test_img
-o "compat=1.1" 64M
101 $PYTHON qcow2.py
"$TEST_IMG" set-feature-bit compatible
42
102 $PYTHON qcow2.py
"$TEST_IMG" set-feature-bit autoclear
42
104 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
109 echo "=== Testing version upgrade and resize ==="
111 _make_test_img
-o "compat=0.10" 64M
112 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
114 $QEMU_IMG amend
-o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
116 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
120 echo "=== Testing resize with snapshots ==="
122 _make_test_img
-o "compat=0.10" 32M
123 $QEMU_IO -c "write -P 0x2a 24M 64k" "$TEST_IMG" | _filter_qemu_io
124 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
125 $QEMU_IMG resize
"$TEST_IMG" 64M
&&
126 echo "unexpected pass"
127 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
129 $QEMU_IMG amend
-o "compat=1.1,size=128M" "$TEST_IMG" ||
130 echo "unexpected fail"
131 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
133 $QEMU_IMG snapshot
-c bar
"$TEST_IMG"
134 $QEMU_IMG resize
--shrink "$TEST_IMG" 64M ||
135 echo "unexpected fail"
136 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
138 $QEMU_IMG amend
-o "compat=0.10,size=32M" "$TEST_IMG" &&
139 echo "unexpected pass"
140 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
142 $QEMU_IMG snapshot
-a bar
"$TEST_IMG" ||
143 echo "unexpected fail"
144 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
146 $QEMU_IMG snapshot
-d bar
"$TEST_IMG"
147 $QEMU_IMG amend
-o "compat=0.10,size=32M" "$TEST_IMG" ||
148 echo "unexpected fail"
149 _qcow2_dump_header |
grep '^\(version\|size\|nb_snap\)'
155 echo "=== Testing dirty lazy_refcounts=off ==="
157 _make_test_img
-o "compat=1.1,lazy_refcounts=on" 64M
159 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush \
160 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io
162 $QEMU_IMG amend
-o "lazy_refcounts=off" "$TEST_IMG"
164 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
168 echo "=== Testing backing file ==="
170 _make_test_img
-o "compat=1.1" 64M
171 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
172 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
173 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
174 $QEMU_IMG amend
-o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" \
175 "$TEST_IMG" && echo "unexpected pass"
176 $QEMU_IMG rebase
-u -b "$TEST_IMG.base" -F qcow2
"$TEST_IMG"
177 $QEMU_IMG amend
-o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
178 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
182 echo "=== Testing invalid configurations ==="
184 _make_test_img
-o "compat=0.10" 64M
185 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
186 $QEMU_IMG amend
-o "compat=1.1" "$TEST_IMG" # actually valid
187 $QEMU_IMG amend
-o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
188 $QEMU_IMG amend
-o "compat=0.42" "$TEST_IMG"
189 $QEMU_IMG amend
-o "foo=bar" "$TEST_IMG"
190 $QEMU_IMG amend
-o "cluster_size=1k" "$TEST_IMG"
191 $QEMU_IMG amend
-o "encryption=on" "$TEST_IMG"
192 $QEMU_IMG amend
-o "preallocation=on" "$TEST_IMG"
195 echo "=== Testing correct handling of unset value ==="
197 _make_test_img
-o "compat=1.1,cluster_size=1k" 64M
199 $QEMU_IMG amend
-o "lazy_refcounts=on" "$TEST_IMG"
200 echo "Should not work:" # Just to know which of these tests actually fails
201 $QEMU_IMG amend
-o "cluster_size=64k" "$TEST_IMG"
204 echo "=== Testing zero expansion on inactive clusters ==="
206 _make_test_img
-o "compat=1.1" 64M
207 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
209 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
210 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
212 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
213 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
215 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
218 echo "=== Testing zero expansion on shared L2 table ==="
220 _make_test_img
-o "compat=1.1" 64M
221 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
222 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
223 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
225 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
226 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
228 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
231 echo "=== Testing zero expansion on backed image ==="
233 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
234 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
235 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
236 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
237 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
239 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
242 echo "=== Testing zero expansion on backed inactive clusters ==="
244 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
245 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
246 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
247 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
248 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
249 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
250 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
252 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
253 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
255 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
258 echo "=== Testing zero expansion on backed image with shared L2 table ==="
260 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 64M
261 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
262 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 64M
263 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
264 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
265 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
267 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
268 $QEMU_IMG snapshot
-a foo
"$TEST_IMG"
270 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
273 echo "=== Testing preallocated zero expansion on full image ==="
275 TEST_IMG
="$TEST_IMG" _make_test_img
-o "compat=1.1" 64M
276 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
277 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
279 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io
282 echo "=== Testing progress report without snapshot ==="
284 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 4G
285 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
286 $QEMU_IO -c "write -z 0 64k" \
287 -c "write -z 1G 64k" \
288 -c "write -z 2G 64k" \
289 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
290 $QEMU_IMG amend
-p -o "compat=0.10" "$TEST_IMG"
294 echo "=== Testing progress report with snapshot ==="
296 TEST_IMG
="$TEST_IMG.base" _make_test_img
-o "compat=1.1" 4G
297 _make_test_img
-o "compat=1.1" -b "$TEST_IMG.base" -F $IMGFMT 4G
298 $QEMU_IO -c "write -z 0 64k" \
299 -c "write -z 1G 64k" \
300 -c "write -z 2G 64k" \
301 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io
302 $QEMU_IMG snapshot
-c foo
"$TEST_IMG"
303 $QEMU_IMG amend
-p -o "compat=0.10" "$TEST_IMG"
307 echo "=== Testing version downgrade with external data file ==="
309 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data" 64M
310 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
311 _img_info
--format-specific
315 echo "=== Testing version downgrade with extended L2 entries ==="
317 _make_test_img
-o "compat=1.1,extended_l2=on" 64M
318 $QEMU_IMG amend
-o "compat=0.10" "$TEST_IMG"
321 echo "=== Try changing the external data file ==="
323 _make_test_img
-o "compat=1.1" 64M
324 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
327 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data" 64M
328 $QEMU_IMG amend
-o "data_file=foo" "$TEST_IMG"
329 _img_info
--format-specific
330 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
333 $QEMU_IMG amend
-o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG"
334 _img_info
--format-specific
335 TEST_IMG
="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info
--format-specific --image-opts
338 echo "=== Clearing and setting data-file-raw ==="
340 _make_test_img
-o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M
341 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
342 _img_info
--format-specific
345 $QEMU_IMG amend
-o "data_file_raw=off" "$TEST_IMG"
346 _img_info
--format-specific
349 $QEMU_IMG amend
-o "data_file_raw=on" "$TEST_IMG"
350 _img_info
--format-specific