]>
Commit | Line | Data |
---|---|---|
ca0eca91 HR |
1 | #!/bin/bash |
2 | # | |
3 | # Test case for image corruption (overlapping data structures) in qcow2 | |
4 | # | |
5 | # Copyright (C) 2013 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 | [email protected] | |
23 | ||
34eeb82d | 24 | seq="$(basename $0)" |
ca0eca91 HR |
25 | echo "QA output created by $seq" |
26 | ||
34eeb82d | 27 | here="$PWD" |
ca0eca91 HR |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
32 | _cleanup_test_img | |
33 | } | |
34 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
35 | ||
36 | # get standard environment, filters and checks | |
37 | . ./common.rc | |
38 | . ./common.filter | |
39 | ||
40 | # This tests qocw2-specific low-level functionality | |
41 | _supported_fmt qcow2 | |
1f7bf7d0 | 42 | _supported_proto file |
ca0eca91 HR |
43 | _supported_os Linux |
44 | ||
45 | rt_offset=65536 # 0x10000 (XXX: just an assumption) | |
46 | rb_offset=131072 # 0x20000 (XXX: just an assumption) | |
47 | l1_offset=196608 # 0x30000 (XXX: just an assumption) | |
48 | l2_offset=262144 # 0x40000 (XXX: just an assumption) | |
34eeb82d | 49 | l2_offset_after_snapshot=524288 # 0x80000 (XXX: just an assumption) |
ca0eca91 HR |
50 | |
51 | IMGOPTS="compat=1.1" | |
52 | ||
34eeb82d HR |
53 | OPEN_RW="open -o overlap-check=all $TEST_IMG" |
54 | # Overlap checks are done before write operations only, therefore opening an | |
55 | # image read-only makes the overlap-check option irrelevant | |
56 | OPEN_RO="open -r $TEST_IMG" | |
57 | ||
ca0eca91 HR |
58 | echo |
59 | echo "=== Testing L2 reference into L1 ===" | |
60 | echo | |
61 | _make_test_img 64M | |
62 | # Link first L1 entry (first L2 table) onto itself | |
63 | # (Note the MSb in the L1 entry is set, ensuring the refcount is one - else any | |
64 | # later write will result in a COW operation, effectively ruining this attempt | |
65 | # on image corruption) | |
66 | poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x03\x00\x00" | |
67 | _check_test_img | |
68 | ||
69 | # The corrupt bit should not be set anyway | |
ea81ca9d | 70 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
ca0eca91 HR |
71 | |
72 | # Try to write something, thereby forcing the corrupt bit to be set | |
34eeb82d | 73 | $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io |
ca0eca91 HR |
74 | |
75 | # The corrupt bit must now be set | |
ea81ca9d | 76 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
ca0eca91 | 77 | |
f383611a | 78 | # This information should be available through qemu-img info |
e800e5d4 | 79 | _img_info --format-specific |
f383611a | 80 | |
ca0eca91 | 81 | # Try to open the image R/W (which should fail) |
34eeb82d HR |
82 | $QEMU_IO -c "$OPEN_RW" -c "read 0 512" 2>&1 | _filter_qemu_io \ |
83 | | _filter_testdir \ | |
84 | | _filter_imgfmt | |
ca0eca91 HR |
85 | |
86 | # Try to open it RO (which should succeed) | |
34eeb82d | 87 | $QEMU_IO -c "$OPEN_RO" -c "read 0 512" | _filter_qemu_io |
ca0eca91 HR |
88 | |
89 | # We could now try to fix the image, but this would probably fail (how should an | |
90 | # L2 table linked onto the L1 table be fixed?) | |
91 | ||
92 | echo | |
93 | echo "=== Testing cluster data reference into refcount block ===" | |
94 | echo | |
95 | _make_test_img 64M | |
96 | # Allocate L2 table | |
97 | truncate -s "$(($l2_offset+65536))" "$TEST_IMG" | |
98 | poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x04\x00\x00" | |
99 | # Mark cluster as used | |
100 | poke_file "$TEST_IMG" "$(($rb_offset+8))" "\x00\x01" | |
101 | # Redirect new data cluster onto refcount block | |
102 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x02\x00\x00" | |
103 | _check_test_img | |
ea81ca9d | 104 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d | 105 | $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io |
ea81ca9d | 106 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
ca0eca91 HR |
107 | |
108 | # Try to fix it | |
109 | _check_test_img -r all | |
110 | ||
111 | # The corrupt bit should be cleared | |
ea81ca9d | 112 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
ca0eca91 HR |
113 | |
114 | # Look if it's really really fixed | |
34eeb82d | 115 | $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io |
ea81ca9d | 116 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d HR |
117 | |
118 | echo | |
119 | echo "=== Testing cluster data reference into inactive L2 table ===" | |
120 | echo | |
121 | _make_test_img 64M | |
122 | $QEMU_IO -c "$OPEN_RW" -c "write -P 1 0 512" | _filter_qemu_io | |
123 | $QEMU_IMG snapshot -c foo "$TEST_IMG" | |
124 | $QEMU_IO -c "$OPEN_RW" -c "write -P 2 0 512" | _filter_qemu_io | |
125 | # The inactive L2 table remains at its old offset | |
126 | poke_file "$TEST_IMG" "$l2_offset_after_snapshot" \ | |
127 | "\x80\x00\x00\x00\x00\x04\x00\x00" | |
128 | _check_test_img | |
ea81ca9d | 129 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d | 130 | $QEMU_IO -c "$OPEN_RW" -c "write -P 3 0 512" | _filter_qemu_io |
ea81ca9d | 131 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d | 132 | _check_test_img -r all |
ea81ca9d | 133 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d | 134 | $QEMU_IO -c "$OPEN_RW" -c "write -P 4 0 512" | _filter_qemu_io |
ea81ca9d | 135 | $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features |
34eeb82d HR |
136 | |
137 | # Check data | |
138 | $QEMU_IO -c "$OPEN_RO" -c "read -P 4 0 512" | _filter_qemu_io | |
139 | $QEMU_IMG snapshot -a foo "$TEST_IMG" | |
140 | _check_test_img | |
141 | $QEMU_IO -c "$OPEN_RO" -c "read -P 1 0 512" | _filter_qemu_io | |
ca0eca91 | 142 | |
98d39e34 HR |
143 | echo |
144 | echo "=== Testing overlap while COW is in flight ===" | |
145 | echo | |
146 | # compat=0.10 is required in order to make the following discard actually | |
147 | # unallocate the sector rather than make it a zero sector - we want COW, after | |
148 | # all. | |
149 | IMGOPTS='compat=0.10' _make_test_img 1G | |
150 | # Write two clusters, the second one enforces creation of an L2 table after | |
151 | # the first data cluster. | |
152 | $QEMU_IO -c 'write 0k 64k' -c 'write 512M 64k' "$TEST_IMG" | _filter_qemu_io | |
153 | # Discard the first cluster. This cluster will soon enough be reallocated and | |
154 | # used for COW. | |
155 | $QEMU_IO -c 'discard 0k 64k' "$TEST_IMG" | _filter_qemu_io | |
156 | # Now, corrupt the image by marking the second L2 table cluster as free. | |
157 | poke_file "$TEST_IMG" '131084' "\x00\x00" # 0x2000c | |
158 | # Start a write operation requiring COW on the image stopping it right before | |
159 | # doing the read; then, trigger the corruption prevention by writing anything to | |
160 | # any unallocated cluster, leading to an attempt to overwrite the second L2 | |
161 | # table. Finally, resume the COW write and see it fail (but not crash). | |
162 | echo "open -o file.driver=blkdebug $TEST_IMG | |
163 | break cow_read 0 | |
164 | aio_write 0k 1k | |
165 | wait_break 0 | |
166 | write 64k 64k | |
167 | resume 0" | $QEMU_IO | _filter_qemu_io | |
168 | ||
a42f8a3d HR |
169 | echo |
170 | echo "=== Testing unallocated image header ===" | |
171 | echo | |
172 | _make_test_img 64M | |
173 | # Create L1/L2 | |
5b0ed2be | 174 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io |
a42f8a3d | 175 | poke_file "$TEST_IMG" "$rb_offset" "\x00\x00" |
5b0ed2be HR |
176 | $QEMU_IO -c "write 64k 64k" "$TEST_IMG" | _filter_qemu_io |
177 | ||
178 | echo | |
179 | echo "=== Testing unaligned L1 entry ===" | |
180 | echo | |
181 | _make_test_img 64M | |
182 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
183 | # This will be masked with ~(512 - 1) = ~0x1ff, so whether the lower 9 bits are | |
184 | # aligned or not does not matter | |
185 | poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x04\x2a\x00" | |
186 | $QEMU_IO -c "read 0 64k" "$TEST_IMG" | _filter_qemu_io | |
187 | ||
f30136b3 HR |
188 | # Test how well zero cluster expansion can cope with this |
189 | _make_test_img 64M | |
190 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
191 | poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x04\x2a\x00" | |
192 | $QEMU_IMG amend -o compat=0.10 "$TEST_IMG" | |
193 | ||
5b0ed2be HR |
194 | echo |
195 | echo "=== Testing unaligned L2 entry ===" | |
196 | echo | |
197 | _make_test_img 64M | |
198 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
199 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00" | |
200 | $QEMU_IO -c "read 0 64k" "$TEST_IMG" | _filter_qemu_io | |
201 | ||
f30136b3 HR |
202 | echo |
203 | echo "=== Testing unaligned pre-allocated zero cluster ===" | |
204 | echo | |
205 | _make_test_img 64M | |
206 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
207 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x01" | |
208 | # zero cluster expansion | |
209 | $QEMU_IMG amend -o compat=0.10 "$TEST_IMG" | |
210 | ||
5b0ed2be HR |
211 | echo |
212 | echo "=== Testing unaligned reftable entry ===" | |
213 | echo | |
214 | _make_test_img 64M | |
215 | poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\x00\x02\x2a\x00" | |
216 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
217 | ||
218 | echo | |
219 | echo "=== Testing non-fatal corruption on freeing ===" | |
220 | echo | |
221 | _make_test_img 64M | |
222 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
223 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00" | |
224 | $QEMU_IO -c "discard 0 64k" "$TEST_IMG" | _filter_qemu_io | |
225 | ||
226 | echo | |
227 | echo "=== Testing read-only corruption report ===" | |
228 | echo | |
229 | _make_test_img 64M | |
230 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
231 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00" | |
232 | # Should only emit a single error message | |
233 | $QEMU_IO -c "$OPEN_RO" -c "read 0 64k" -c "read 0 64k" | _filter_qemu_io | |
234 | ||
235 | echo | |
236 | echo "=== Testing non-fatal and then fatal corruption report ===" | |
237 | echo | |
238 | _make_test_img 64M | |
239 | $QEMU_IO -c "write 0 128k" "$TEST_IMG" | _filter_qemu_io | |
240 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00" | |
241 | poke_file "$TEST_IMG" "$(($l2_offset+8))" "\x80\x00\x00\x00\x00\x06\x2a\x00" | |
242 | # Should emit two error messages | |
243 | $QEMU_IO -c "discard 0 64k" -c "read 64k 64k" "$TEST_IMG" | _filter_qemu_io | |
a42f8a3d | 244 | |
ef083f61 AG |
245 | echo |
246 | echo "=== Testing empty refcount table ===" | |
247 | echo | |
248 | _make_test_img 64M | |
249 | poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
250 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
bcb5270c AG |
251 | # Repair the image |
252 | _check_test_img -r all | |
ef083f61 | 253 | |
6bf45d59 AG |
254 | echo |
255 | echo "=== Testing empty refcount table with valid L1 and L2 tables ===" | |
256 | echo | |
257 | _make_test_img 64M | |
258 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
259 | poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
260 | # Since the first data cluster is already allocated this triggers an | |
261 | # allocation with an explicit offset (using qcow2_alloc_clusters_at()) | |
262 | # causing a refcount block to be allocated at offset 0 | |
263 | $QEMU_IO -c "write 0 128k" "$TEST_IMG" | _filter_qemu_io | |
bcb5270c AG |
264 | # Repair the image |
265 | _check_test_img -r all | |
6bf45d59 | 266 | |
98839750 AG |
267 | echo |
268 | echo "=== Testing empty refcount block ===" | |
269 | echo | |
270 | _make_test_img 64M | |
271 | poke_file "$TEST_IMG" "$rb_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
272 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
bcb5270c AG |
273 | # Repair the image |
274 | _check_test_img -r all | |
98839750 | 275 | |
8aa34834 AG |
276 | echo |
277 | echo "=== Testing empty refcount block with compressed write ===" | |
278 | echo | |
279 | _make_test_img 64M | |
280 | $QEMU_IO -c "write 64k 64k" "$TEST_IMG" | _filter_qemu_io | |
281 | poke_file "$TEST_IMG" "$rb_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
282 | # The previous write already allocated an L2 table, so now this new | |
283 | # write will try to allocate a compressed data cluster at offset 0. | |
284 | $QEMU_IO -c "write -c 0k 64k" "$TEST_IMG" | _filter_qemu_io | |
bcb5270c AG |
285 | # Repair the image |
286 | _check_test_img -r all | |
8aa34834 | 287 | |
951053a9 AG |
288 | echo |
289 | echo "=== Testing zero refcount table size ===" | |
290 | echo | |
291 | _make_test_img 64M | |
292 | poke_file "$TEST_IMG" "56" "\x00\x00\x00\x00" | |
293 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" 2>&1 | _filter_testdir | _filter_imgfmt | |
bcb5270c AG |
294 | # Repair the image |
295 | _check_test_img -r all | |
951053a9 | 296 | |
5a45da5e AG |
297 | echo |
298 | echo "=== Testing incorrect refcount table offset ===" | |
299 | echo | |
300 | _make_test_img 64M | |
301 | poke_file "$TEST_IMG" "48" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
302 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
303 | ||
791fff50 HR |
304 | echo |
305 | echo "=== Testing dirty corrupt image ===" | |
306 | echo | |
307 | ||
308 | _make_test_img 64M | |
309 | ||
310 | # Let the refblock appear unaligned | |
311 | poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\xff\xff\x2a\x00" | |
312 | # Mark the image dirty, thus forcing an automatic check when opening it | |
313 | poke_file "$TEST_IMG" 72 "\x00\x00\x00\x00\x00\x00\x00\x01" | |
314 | # Open the image (qemu should refuse to do so) | |
315 | $QEMU_IO -c close "$TEST_IMG" 2>&1 | _filter_testdir | _filter_imgfmt | |
316 | ||
317 | echo '--- Repairing ---' | |
318 | ||
319 | # The actual repair should have happened (because of the dirty bit), | |
320 | # but some cleanup may have failed (like freeing the old reftable) | |
321 | # because the image was already marked corrupt by that point | |
322 | _check_test_img -r all | |
323 | ||
93bbaf03 HR |
324 | echo |
325 | echo "=== Writing to an unaligned preallocated zero cluster ===" | |
326 | echo | |
327 | ||
328 | _make_test_img 64M | |
329 | ||
330 | # Allocate the L2 table | |
331 | $QEMU_IO -c "write 0 64k" -c "discard 0 64k" "$TEST_IMG" | _filter_qemu_io | |
332 | # Pretend there is a preallocated zero cluster somewhere inside the | |
333 | # image header | |
334 | poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x00\x2a\x01" | |
335 | # Let's write to it! | |
336 | $QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io | |
337 | ||
ac5b787a HR |
338 | echo '--- Repairing ---' |
339 | _check_test_img -r all | |
93bbaf03 | 340 | |
d470ad42 HR |
341 | echo |
342 | echo '=== Discarding with an unaligned refblock ===' | |
343 | echo | |
344 | ||
345 | _make_test_img 64M | |
346 | ||
347 | $QEMU_IO -c "write 0 128k" "$TEST_IMG" | _filter_qemu_io | |
348 | # Make our refblock unaligned | |
349 | poke_file "$TEST_IMG" "$(($rt_offset))" "\x00\x00\x00\x00\x00\x00\x2a\x00" | |
350 | # Now try to discard something that will be submitted as two requests | |
351 | # (main part + tail) | |
352 | $QEMU_IO -c "discard 0 65537" "$TEST_IMG" | |
353 | ||
354 | echo '--- Repairing ---' | |
355 | # Fails the first repair because the corruption prevents the check | |
356 | # function from double-checking | |
357 | # (Using -q for the first invocation, because otherwise the | |
358 | # double-check error message appears above the summary for some | |
359 | # reason -- so let's just hide the summary) | |
360 | _check_test_img -q -r all | |
361 | _check_test_img -r all | |
362 | ||
23482f8a HR |
363 | echo |
364 | echo "=== Discarding an out-of-bounds refblock ===" | |
365 | echo | |
366 | ||
367 | _make_test_img 64M | |
368 | ||
369 | # Pretend there's a refblock really up high | |
370 | poke_file "$TEST_IMG" "$(($rt_offset+8))" "\x00\xff\xff\xff\x00\x00\x00\x00" | |
371 | # Let's try to shrink the qcow2 image so that the block driver tries | |
372 | # to discard that refblock (and see what happens!) | |
373 | $QEMU_IMG resize --shrink "$TEST_IMG" 32M | |
374 | ||
375 | echo '--- Checking and retrying ---' | |
376 | # Image should not be resized | |
377 | _img_info | grep 'virtual size' | |
378 | # But it should pass this check, because the "partial" resize has | |
379 | # already overwritten refblocks past the end | |
380 | _check_test_img -r all | |
381 | # So let's try again | |
382 | $QEMU_IMG resize --shrink "$TEST_IMG" 32M | |
383 | _img_info | grep 'virtual size' | |
384 | ||
385 | echo | |
386 | echo "=== Discarding a non-covered in-bounds refblock ===" | |
387 | echo | |
388 | ||
389 | IMGOPTS='refcount_bits=1' _make_test_img 64M | |
390 | ||
391 | # Pretend there's a refblock somewhere where there is no refblock to | |
392 | # cover it (but the covering refblock has a valid index in the | |
393 | # reftable) | |
394 | # Every refblock covers 65536 * 8 * 65536 = 32 GB, so we have to point | |
395 | # to 0x10_0000_0000 (64G) to point to the third refblock | |
396 | poke_file "$TEST_IMG" "$(($rt_offset+8))" "\x00\x00\x00\x10\x00\x00\x00\x00" | |
397 | $QEMU_IMG resize --shrink "$TEST_IMG" 32M | |
398 | ||
399 | echo '--- Checking and retrying ---' | |
400 | # Image should not be resized | |
401 | _img_info | grep 'virtual size' | |
402 | # But it should pass this check, because the "partial" resize has | |
403 | # already overwritten refblocks past the end | |
404 | _check_test_img -r all | |
405 | # So let's try again | |
406 | $QEMU_IMG resize --shrink "$TEST_IMG" 32M | |
407 | _img_info | grep 'virtual size' | |
408 | ||
4efb1f7c HR |
409 | echo |
410 | echo "=== Discarding a refblock covered by an unaligned refblock ===" | |
411 | echo | |
412 | ||
413 | IMGOPTS='refcount_bits=1' _make_test_img 64M | |
414 | ||
415 | # Same as above | |
416 | poke_file "$TEST_IMG" "$(($rt_offset+8))" "\x00\x00\x00\x10\x00\x00\x00\x00" | |
417 | # But now we actually "create" an unaligned third refblock | |
418 | poke_file "$TEST_IMG" "$(($rt_offset+16))" "\x00\x00\x00\x00\x00\x00\x02\x00" | |
419 | $QEMU_IMG resize --shrink "$TEST_IMG" 32M | |
420 | ||
421 | echo '--- Repairing ---' | |
422 | # Fails the first repair because the corruption prevents the check | |
423 | # function from double-checking | |
424 | # (Using -q for the first invocation, because otherwise the | |
425 | # double-check error message appears above the summary for some | |
426 | # reason -- so let's just hide the summary) | |
427 | _check_test_img -q -r all | |
428 | _check_test_img -r all | |
429 | ||
50a3efb0 AG |
430 | echo |
431 | echo "=== Testing the QEMU shutdown with a corrupted image ===" | |
432 | echo | |
433 | _make_test_img 64M | |
434 | poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\x00\x00\x00\x00" | |
435 | echo "{'execute': 'qmp_capabilities'} | |
436 | {'execute': 'human-monitor-command', | |
437 | 'arguments': {'command-line': 'qemu-io drive \"write 0 512\"'}} | |
438 | {'execute': 'quit'}" \ | |
439 | | $QEMU -qmp stdio -nographic -nodefaults \ | |
440 | -drive if=none,node-name=drive,file="$TEST_IMG",driver=qcow2 \ | |
441 | | _filter_qmp | _filter_qemu_io | |
442 | ||
c50abd17 HR |
443 | echo |
444 | echo "=== Testing incoming inactive corrupted image ===" | |
445 | echo | |
446 | ||
447 | _make_test_img 64M | |
448 | # Create an unaligned L1 entry, so qemu will signal a corruption when | |
449 | # reading from the covered area | |
450 | poke_file "$TEST_IMG" "$l1_offset" "\x00\x00\x00\x00\x2a\x2a\x2a\x2a" | |
451 | ||
452 | # Inactive images are effectively read-only images, so this should be a | |
453 | # non-fatal corruption (which does not modify the image) | |
454 | echo "{'execute': 'qmp_capabilities'} | |
455 | {'execute': 'human-monitor-command', | |
456 | 'arguments': {'command-line': 'qemu-io drive \"read 0 512\"'}} | |
457 | {'execute': 'quit'}" \ | |
458 | | $QEMU -qmp stdio -nographic -nodefaults \ | |
459 | -blockdev "{'node-name': 'drive', | |
460 | 'driver': 'qcow2', | |
461 | 'file': { | |
462 | 'driver': 'file', | |
463 | 'filename': '$TEST_IMG' | |
464 | }}" \ | |
465 | -incoming exec:'cat /dev/null' \ | |
466 | 2>&1 \ | |
467 | | _filter_qmp | _filter_qemu_io | |
468 | ||
469 | echo | |
470 | # Image should not have been marked corrupt | |
471 | _img_info --format-specific | grep 'corrupt:' | |
472 | ||
ca0eca91 HR |
473 | # success, all done |
474 | echo "*** done" | |
475 | rm -f $seq.full | |
476 | status=0 |