]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
d2eed8c6 HR |
2 | # |
3 | # Test cases for different refcount_bits values | |
4 | # | |
5 | # Copyright (C) 2015 Red Hat, Inc. | |
6 | # | |
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. | |
11 | # | |
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. | |
16 | # | |
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/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | owner=mreitz@redhat.com | |
23 | ||
24 | seq="$(basename $0)" | |
25 | echo "QA output created by $seq" | |
26 | ||
d2eed8c6 HR |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
31 | _cleanup_test_img | |
32 | } | |
33 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
34 | ||
35 | # get standard environment, filters and checks | |
36 | . ./common.rc | |
37 | . ./common.filter | |
38 | ||
39 | # This tests qcow2-specific low-level functionality | |
40 | _supported_fmt qcow2 | |
41 | _supported_proto file | |
d2eed8c6 | 42 | # This test will set refcount_bits on its own which would conflict with the |
3be2024a HR |
43 | # manual setting; compat will be overridden as well; |
44 | # and external data files do not work well with our refcount testing | |
45 | _unsupported_imgopts refcount_bits 'compat=0.10' data_file | |
d2eed8c6 | 46 | |
8cedcffd | 47 | print_refcount_bits() |
d2eed8c6 HR |
48 | { |
49 | $QEMU_IMG info "$TEST_IMG" | sed -n '/refcount bits:/ s/^ *//p' | |
50 | } | |
51 | ||
52 | echo | |
53 | echo '=== refcount_bits limits ===' | |
54 | echo | |
55 | ||
56 | # Must be positive (non-zero) | |
407fb56a | 57 | _make_test_img -o "refcount_bits=0" 64M |
d2eed8c6 | 58 | # Must be positive (non-negative) |
407fb56a | 59 | _make_test_img -o "refcount_bits=-1" 64M |
d2eed8c6 | 60 | # May not exceed 64 |
407fb56a | 61 | _make_test_img -o "refcount_bits=128" 64M |
d2eed8c6 | 62 | # Must be a power of two |
407fb56a | 63 | _make_test_img -o "refcount_bits=42" 64M |
d2eed8c6 HR |
64 | |
65 | # 1 is the minimum | |
407fb56a | 66 | _make_test_img -o "refcount_bits=1" 64M |
d2eed8c6 HR |
67 | print_refcount_bits |
68 | ||
69 | # 64 is the maximum | |
407fb56a | 70 | _make_test_img -o "refcount_bits=64" 64M |
d2eed8c6 HR |
71 | print_refcount_bits |
72 | ||
73 | # 16 is the default | |
74 | _make_test_img 64M | |
75 | print_refcount_bits | |
76 | ||
77 | echo | |
78 | echo '=== refcount_bits and compat=0.10 ===' | |
79 | echo | |
80 | ||
81 | # Should work | |
407fb56a | 82 | _make_test_img -o "compat=0.10,refcount_bits=16" 64M |
d2eed8c6 HR |
83 | print_refcount_bits |
84 | ||
85 | # Should not work | |
407fb56a HR |
86 | _make_test_img -o "compat=0.10,refcount_bits=1" 64M |
87 | _make_test_img -o "compat=0.10,refcount_bits=64" 64M | |
d2eed8c6 HR |
88 | |
89 | ||
90 | echo | |
91 | echo '=== Snapshot limit on refcount_bits=1 ===' | |
92 | echo | |
93 | ||
407fb56a | 94 | _make_test_img -o "refcount_bits=1" 64M |
d2eed8c6 HR |
95 | print_refcount_bits |
96 | ||
97 | $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io | |
98 | ||
99 | # Should fail for now; in the future, this might be supported by automatically | |
100 | # copying all clusters with overflowing refcount | |
101 | $QEMU_IMG snapshot -c foo "$TEST_IMG" | |
102 | ||
103 | # The new L1 table could/should be leaked | |
104 | _check_test_img | |
105 | ||
106 | echo | |
107 | echo '=== Snapshot limit on refcount_bits=2 ===' | |
108 | echo | |
109 | ||
407fb56a | 110 | _make_test_img -o "refcount_bits=2" 64M |
d2eed8c6 HR |
111 | print_refcount_bits |
112 | ||
113 | $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io | |
114 | ||
115 | # Should succeed | |
116 | $QEMU_IMG snapshot -c foo "$TEST_IMG" | |
117 | $QEMU_IMG snapshot -c bar "$TEST_IMG" | |
118 | # Should fail (4th reference) | |
119 | $QEMU_IMG snapshot -c baz "$TEST_IMG" | |
120 | ||
121 | # The new L1 table could/should be leaked | |
122 | _check_test_img | |
123 | ||
124 | echo | |
125 | echo '=== Compressed clusters with refcount_bits=1 ===' | |
126 | echo | |
127 | ||
407fb56a | 128 | _make_test_img -o "refcount_bits=1" 64M |
d2eed8c6 HR |
129 | print_refcount_bits |
130 | ||
131 | # Both should fit into a single host cluster; instead of failing to increase the | |
132 | # refcount of that cluster, qemu should just allocate a new cluster and make | |
133 | # this operation succeed | |
134 | $QEMU_IO -c 'write -P 0 -c 0 64k' \ | |
135 | -c 'write -P 1 -c 64k 64k' \ | |
136 | "$TEST_IMG" | _filter_qemu_io | |
137 | ||
138 | _check_test_img | |
139 | ||
140 | echo | |
141 | echo '=== MSb set in 64 bit refcount ===' | |
142 | echo | |
143 | ||
407fb56a | 144 | _make_test_img -o "refcount_bits=64" 64M |
d2eed8c6 HR |
145 | print_refcount_bits |
146 | ||
147 | $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io | |
148 | ||
149 | # Set the MSb in the refblock entry of the data cluster | |
150 | poke_file "$TEST_IMG" $((0x20028)) "\x80\x00\x00\x00\x00\x00\x00\x00" | |
151 | ||
152 | # Clear OFLAG_COPIED in the L2 entry of the data cluster | |
153 | poke_file "$TEST_IMG" $((0x40000)) "\x00\x00\x00\x00\x00\x05\x00\x00" | |
154 | ||
155 | # Try to write to that cluster (should work, even though the MSb is set) | |
156 | $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io | |
157 | ||
158 | echo | |
159 | echo '=== Snapshot on maximum 64 bit refcount value ===' | |
160 | echo | |
161 | ||
407fb56a | 162 | _make_test_img -o "refcount_bits=64" 64M |
d2eed8c6 HR |
163 | print_refcount_bits |
164 | ||
165 | $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io | |
166 | ||
167 | # Set the refblock entry to the maximum value possible | |
168 | poke_file "$TEST_IMG" $((0x20028)) "\xff\xff\xff\xff\xff\xff\xff\xff" | |
169 | ||
170 | # Clear OFLAG_COPIED in the L2 entry of the data cluster | |
171 | poke_file "$TEST_IMG" $((0x40000)) "\x00\x00\x00\x00\x00\x05\x00\x00" | |
172 | ||
173 | # Try a snapshot (should correctly identify the overflow; may work in the future | |
174 | # by falling back to COW) | |
175 | $QEMU_IMG snapshot -c foo "$TEST_IMG" | |
176 | ||
177 | # The new L1 table could/should be leaked; and obviously the data cluster is | |
178 | # leaked (refcount=UINT64_MAX reference=1) | |
179 | _check_test_img | |
180 | ||
e9dbdc5e HR |
181 | echo |
182 | echo '=== Amend from refcount_bits=16 to refcount_bits=1 ===' | |
183 | echo | |
184 | ||
185 | _make_test_img 64M | |
186 | print_refcount_bits | |
187 | ||
188 | $QEMU_IO -c 'write 16M 32M' "$TEST_IMG" | _filter_qemu_io | |
189 | $QEMU_IMG amend -o refcount_bits=1 "$TEST_IMG" | |
190 | _check_test_img | |
191 | print_refcount_bits | |
192 | ||
193 | echo | |
194 | echo '=== Amend from refcount_bits=1 to refcount_bits=64 ===' | |
195 | echo | |
196 | ||
197 | $QEMU_IMG amend -o refcount_bits=64 "$TEST_IMG" | |
198 | _check_test_img | |
199 | print_refcount_bits | |
200 | ||
201 | echo | |
202 | echo '=== Amend to compat=0.10 ===' | |
203 | echo | |
204 | ||
205 | # Should not work because refcount_bits needs to be 16 for compat=0.10 | |
206 | $QEMU_IMG amend -o compat=0.10 "$TEST_IMG" | |
207 | print_refcount_bits | |
208 | # Should work | |
209 | $QEMU_IMG amend -o compat=0.10,refcount_bits=16 "$TEST_IMG" | |
210 | _check_test_img | |
211 | print_refcount_bits | |
212 | ||
213 | # Get back to compat=1.1 and refcount_bits=16 | |
214 | $QEMU_IMG amend -o compat=1.1 "$TEST_IMG" | |
215 | print_refcount_bits | |
216 | # Should not work | |
217 | $QEMU_IMG amend -o refcount_bits=32,compat=0.10 "$TEST_IMG" | |
218 | print_refcount_bits | |
219 | ||
220 | echo | |
221 | echo '=== Amend with snapshot ===' | |
222 | echo | |
223 | ||
224 | $QEMU_IMG snapshot -c foo "$TEST_IMG" | |
225 | # Just to have different refcounts across the image | |
226 | $QEMU_IO -c 'write 0 16M' "$TEST_IMG" | _filter_qemu_io | |
227 | ||
228 | # Should not work (may work in the future by first decreasing all refcounts so | |
229 | # they fit into the target range by copying them) | |
230 | $QEMU_IMG amend -o refcount_bits=1 "$TEST_IMG" | |
231 | _check_test_img | |
232 | print_refcount_bits | |
233 | ||
234 | # Should work | |
235 | $QEMU_IMG amend -o refcount_bits=2 "$TEST_IMG" | |
236 | _check_test_img | |
237 | print_refcount_bits | |
238 | ||
239 | echo | |
240 | echo '=== Testing too many references for check ===' | |
241 | echo | |
242 | ||
407fb56a | 243 | _make_test_img -o "refcount_bits=1" 64M |
e9dbdc5e HR |
244 | print_refcount_bits |
245 | ||
246 | # This cluster should be created at 0x50000 | |
247 | $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io | |
248 | # Now make the second L2 entry (the L2 table should be at 0x40000) point to that | |
249 | # cluster, so we have two references | |
250 | poke_file "$TEST_IMG" $((0x40008)) "\x80\x00\x00\x00\x00\x05\x00\x00" | |
251 | ||
252 | # This should say "please use amend" | |
253 | _check_test_img -r all | |
254 | ||
255 | # So we do that | |
256 | $QEMU_IMG amend -o refcount_bits=2 "$TEST_IMG" | |
257 | print_refcount_bits | |
258 | ||
259 | # And try again | |
260 | _check_test_img -r all | |
261 | ||
262 | echo | |
263 | echo '=== Multiple walks necessary during amend ===' | |
264 | echo | |
265 | ||
407fb56a | 266 | _make_test_img -o "refcount_bits=1,cluster_size=512" 64k |
e9dbdc5e HR |
267 | |
268 | # Cluster 0 is the image header, clusters 1 to 4 are used by the L1 table, a | |
269 | # single L2 table, the reftable and a single refblock. This creates 58 data | |
270 | # clusters (actually, the L2 table is created here, too), so in total there are | |
271 | # then 63 used clusters in the image. With a refcount width of 64, one refblock | |
272 | # describes 64 clusters (512 bytes / 64 bits/entry = 64 entries), so this will | |
273 | # make the first refblock in the amended image have exactly one free entry. | |
274 | $QEMU_IO -c "write 0 $((58 * 512))" "$TEST_IMG" | _filter_qemu_io | |
275 | ||
276 | # Now change the refcount width; since the first new refblock will have exactly | |
277 | # one free entry, that entry will be used to store its own reference. No other | |
278 | # refblocks are needed, so then the new reftable will be allocated; since the | |
279 | # first new refblock is completely filled up, this will require a new refblock | |
280 | # which is why the refcount width changing function will need to run through | |
281 | # everything one more time until the allocations are stable. | |
282 | # Having more walks than usual should be visible as regressing progress (from | |
283 | # 66.67 % (2/3 walks) to 50.00 % (2/4 walks)). | |
284 | $QEMU_IMG amend -o refcount_bits=64 -p "$TEST_IMG" | tr '\r' '\n' \ | |
285 | | grep -A 1 '66.67' | |
286 | print_refcount_bits | |
287 | ||
288 | _check_test_img | |
289 | ||
d2eed8c6 HR |
290 | |
291 | # success, all done | |
292 | echo '*** done' | |
293 | rm -f $seq.full | |
294 | status=0 |