tests: Fix gcov paths for relocated device sources
[qemu/qmp-unstable.git] / tests / qemu-iotests / 060
blobaf8ed9f39afff5e2dbad00bc21e7384fd728264f
1 #!/bin/bash
3 # Test case for image corruption (overlapping data structures) 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/>.
21 # creator
22 owner=mreitz@redhat.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 here="$PWD"
28 tmp=/tmp/$$
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 # This tests qocw2-specific low-level functionality
42 _supported_fmt qcow2
43 _supported_proto file
44 _supported_os Linux
46 rt_offset=65536 # 0x10000 (XXX: just an assumption)
47 rb_offset=131072 # 0x20000 (XXX: just an assumption)
48 l1_offset=196608 # 0x30000 (XXX: just an assumption)
49 l2_offset=262144 # 0x40000 (XXX: just an assumption)
50 l2_offset_after_snapshot=524288 # 0x80000 (XXX: just an assumption)
52 IMGOPTS="compat=1.1"
54 OPEN_RW="open -o overlap-check=all $TEST_IMG"
55 # Overlap checks are done before write operations only, therefore opening an
56 # image read-only makes the overlap-check option irrelevant
57 OPEN_RO="open -r $TEST_IMG"
59 echo
60 echo "=== Testing L2 reference into L1 ==="
61 echo
62 _make_test_img 64M
63 # Link first L1 entry (first L2 table) onto itself
64 # (Note the MSb in the L1 entry is set, ensuring the refcount is one - else any
65 # later write will result in a COW operation, effectively ruining this attempt
66 # on image corruption)
67 poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x03\x00\x00"
68 _check_test_img
70 # The corrupt bit should not be set anyway
71 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
73 # Try to write something, thereby forcing the corrupt bit to be set
74 $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
76 # The corrupt bit must now be set
77 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
79 # Try to open the image R/W (which should fail)
80 $QEMU_IO -c "$OPEN_RW" -c "read 0 512" 2>&1 | _filter_qemu_io \
81 | _filter_testdir \
82 | _filter_imgfmt
84 # Try to open it RO (which should succeed)
85 $QEMU_IO -c "$OPEN_RO" -c "read 0 512" | _filter_qemu_io
87 # We could now try to fix the image, but this would probably fail (how should an
88 # L2 table linked onto the L1 table be fixed?)
90 echo
91 echo "=== Testing cluster data reference into refcount block ==="
92 echo
93 _make_test_img 64M
94 # Allocate L2 table
95 truncate -s "$(($l2_offset+65536))" "$TEST_IMG"
96 poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x04\x00\x00"
97 # Mark cluster as used
98 poke_file "$TEST_IMG" "$(($rb_offset+8))" "\x00\x01"
99 # Redirect new data cluster onto refcount block
100 poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x02\x00\x00"
101 _check_test_img
102 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
103 $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
104 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
106 # Try to fix it
107 _check_test_img -r all
109 # The corrupt bit should be cleared
110 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
112 # Look if it's really really fixed
113 $QEMU_IO -c "$OPEN_RW" -c "write -P 0x2a 0 512" | _filter_qemu_io
114 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
116 echo
117 echo "=== Testing cluster data reference into inactive L2 table ==="
118 echo
119 _make_test_img 64M
120 $QEMU_IO -c "$OPEN_RW" -c "write -P 1 0 512" | _filter_qemu_io
121 $QEMU_IMG snapshot -c foo "$TEST_IMG"
122 $QEMU_IO -c "$OPEN_RW" -c "write -P 2 0 512" | _filter_qemu_io
123 # The inactive L2 table remains at its old offset
124 poke_file "$TEST_IMG" "$l2_offset_after_snapshot" \
125 "\x80\x00\x00\x00\x00\x04\x00\x00"
126 _check_test_img
127 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
128 $QEMU_IO -c "$OPEN_RW" -c "write -P 3 0 512" | _filter_qemu_io
129 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
130 _check_test_img -r all
131 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
132 $QEMU_IO -c "$OPEN_RW" -c "write -P 4 0 512" | _filter_qemu_io
133 ./qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
135 # Check data
136 $QEMU_IO -c "$OPEN_RO" -c "read -P 4 0 512" | _filter_qemu_io
137 $QEMU_IMG snapshot -a foo "$TEST_IMG"
138 _check_test_img
139 $QEMU_IO -c "$OPEN_RO" -c "read -P 1 0 512" | _filter_qemu_io
141 # success, all done
142 echo "*** done"
143 rm -f $seq.full
144 status=0