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/>.
25 echo "QA output created by $seq"
29 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
41 # This tests qocw2-specific low-level functionality
43 _supported_proto generic
47 echo "=== Testing version downgrade with zero expansion ==="
49 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
50 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
51 ./qcow2.py "$TEST_IMG" dump-header
52 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
53 ./qcow2.py "$TEST_IMG" dump-header
54 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
58 echo "=== Testing dirty version downgrade ==="
60 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
61 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io
62 ./qcow2.py "$TEST_IMG" dump-header
63 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
64 ./qcow2.py "$TEST_IMG" dump-header
65 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
69 echo "=== Testing version downgrade with unknown compat/autoclear flags ==="
71 IMGOPTS="compat=1.1" _make_test_img 64M
72 ./qcow2.py "$TEST_IMG" set-feature-bit compatible 42
73 ./qcow2.py "$TEST_IMG" set-feature-bit autoclear 42
74 ./qcow2.py "$TEST_IMG" dump-header
75 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
76 ./qcow2.py "$TEST_IMG" dump-header
80 echo "=== Testing version upgrade and resize ==="
82 IMGOPTS="compat=0.10" _make_test_img 64M
83 $QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
84 ./qcow2.py "$TEST_IMG" dump-header
85 $QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG"
86 ./qcow2.py "$TEST_IMG" dump-header
87 $QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io
91 echo "=== Testing dirty lazy_refcounts=off ==="
93 IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M
94 $QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io
95 ./qcow2.py "$TEST_IMG" dump-header
96 $QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG"
97 ./qcow2.py "$TEST_IMG" dump-header
98 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
102 echo "=== Testing backing file ==="
104 IMGOPTS="compat=1.1" _make_test_img 64M
105 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
106 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
107 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
108 $QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG"
109 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
113 echo "=== Testing invalid configurations ==="
115 IMGOPTS="compat=0.10" _make_test_img 64M
116 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
117 $QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid
118 $QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG"
119 $QEMU_IMG amend -o "compat=0.42" "$TEST_IMG"
120 $QEMU_IMG amend -o "foo=bar" "$TEST_IMG"
121 $QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG"
122 $QEMU_IMG amend -o "encryption=on" "$TEST_IMG"
123 $QEMU_IMG amend -o "preallocation=on" "$TEST_IMG"
126 echo "=== Testing correct handling of unset value ==="
128 IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M
130 $QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG"
131 echo "Should not work:" # Just to know which of these tests actually fails
132 $QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG"
135 echo "=== Testing zero expansion on inactive clusters ==="
137 IMGOPTS="compat=1.1" _make_test_img 64M
138 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
139 $QEMU_IMG snapshot -c foo "$TEST_IMG"
140 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
141 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
143 $QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io
144 $QEMU_IMG snapshot -a foo "$TEST_IMG"
146 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
149 echo "=== Testing zero expansion on shared L2 table ==="
151 IMGOPTS="compat=1.1" _make_test_img 64M
152 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
153 $QEMU_IMG snapshot -c foo "$TEST_IMG"
154 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
156 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
157 $QEMU_IMG snapshot -a foo "$TEST_IMG"
159 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
162 echo "=== Testing zero expansion on backed image ==="
164 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
165 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
166 IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
167 $QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
168 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
170 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
173 echo "=== Testing zero expansion on backed inactive clusters ==="
175 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M
176 $QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io
177 IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
178 $QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io
179 $QEMU_IMG snapshot -c foo "$TEST_IMG"
180 $QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
181 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
183 $QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io
184 $QEMU_IMG snapshot -a foo "$TEST_IMG"
186 $QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io
189 echo "=== Testing zero expansion on backed image with shared L2 table ==="
191 IMGOPTS="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
193 IMGOPTS="compat=1.1,backing_file=$TEST_IMG.base" _make_test_img 64M
194 $QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io
195 $QEMU_IMG snapshot -c foo "$TEST_IMG"
196 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
198 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
199 $QEMU_IMG snapshot -a foo "$TEST_IMG"
201 $QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io
204 echo "=== Testing preallocated zero expansion on full image ==="
206 IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M
207 $QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io
208 $QEMU_IMG amend -o "compat=0.10" "$TEST_IMG"
210 $QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io