osdep: protect qemu/osdep.h with extern "C"
[qemu/ar7.git] / tests / qemu-iotests / 108
blob8eaef0b8bf27592912d23ba6b36e3e70901c88d7
1 #!/usr/bin/env bash
2 # group: rw auto quick
4 # Test case for repairing qcow2 images which cannot be repaired using
5 # the on-disk refcount structures
7 # Copyright (C) 2014 Red Hat, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # creator
24 owner=mreitz@redhat.com
26 seq="$(basename $0)"
27 echo "QA output created by $seq"
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 qcow2-specific low-level functionality
42 _supported_fmt qcow2
43 _supported_proto file fuse
44 _supported_os Linux
45 # This test directly modifies a refblock so it relies on refcount_bits being 16;
46 # and the low-level modification it performs are not tuned for external data
47 # files
48 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
50 echo
51 echo '=== Repairing an image without any refcount table ==='
52 echo
54 _make_test_img 64M
55 # just write some data
56 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
58 # refcount_table_offset
59 poke_file "$TEST_IMG" $((0x30)) "\x00\x00\x00\x00\x00\x00\x00\x00"
60 # refcount_table_clusters
61 poke_file "$TEST_IMG" $((0x38)) "\x00\x00\x00\x00"
63 _check_test_img -r all
65 $QEMU_IO -c 'read -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
67 echo
68 echo '=== Repairing unreferenced data cluster in new refblock area ==='
69 echo
71 _make_test_img -o 'cluster_size=512' 64M
72 # Allocate the first 128 kB in the image (first refblock)
73 $QEMU_IO -c 'write 0 0x1b200' "$TEST_IMG" | _filter_qemu_io
74 # should be 131072 == 0x20000
75 stat -c '%s' "$TEST_IMG"
77 # Enter a cluster at 128 kB (0x20000)
78 # XXX: This should be the first free entry in the last L2 table, but we cannot
79 # be certain
80 poke_file "$TEST_IMG" $((0x1ccc8)) "\x80\x00\x00\x00\x00\x02\x00\x00"
82 # Fill the cluster
83 truncate -s $((0x20200)) "$TEST_IMG"
84 $QEMU_IO -c "open -o driver=raw $TEST_IMG" -c 'write -P 42 128k 512' \
85 | _filter_qemu_io
87 # The data should now appear at this guest offset
88 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
90 # This cluster is unallocated; fix it
91 _check_test_img -r all
93 # This repair operation must have allocated a new refblock; and that refblock
94 # should not overlap with the unallocated data cluster. If it does, the data
95 # will be damaged, so check it.
96 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
98 echo
99 echo '=== Repairing refblock beyond the image end ==='
100 echo
102 echo
103 echo '--- Otherwise clean ---'
104 echo
106 _make_test_img 64M
107 # Normally, qemu doesn't create empty refblocks, so we just have to do it by
108 # hand
109 # XXX: This should be the entry for the second refblock
110 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
111 # Mark that refblock as used
112 # XXX: This should be the 17th entry (cluster 16) of the first
113 # refblock
114 poke_file "$TEST_IMG" $((0x20020)) "\x00\x01"
115 _check_test_img -r all
117 echo
118 echo '--- Refblock is unallocated ---'
119 echo
121 _make_test_img 64M
122 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
123 _check_test_img -r all
125 echo
126 echo '--- Signed overflow after the refblock ---'
127 echo
129 _make_test_img 64M
130 poke_file "$TEST_IMG" $((0x10008)) "\x7f\xff\xff\xff\xff\xff\x00\x00"
131 _check_test_img -r all
133 echo
134 echo '--- Unsigned overflow after the refblock ---'
135 echo
137 _make_test_img 64M
138 poke_file "$TEST_IMG" $((0x10008)) "\xff\xff\xff\xff\xff\xff\x00\x00"
139 _check_test_img -r all
141 # success, all done
142 echo '*** done'
143 rm -f $seq.full
144 status=0