hw/ssi/pl022: Set up reset function in class init
[qemu.git] / tests / qemu-iotests / 108
blob2355d98c1d35941a51ba62ea416bf3dc7adf7cc1
1 #!/bin/bash
3 # Test case for repairing qcow2 images which cannot be repaired using
4 # the on-disk refcount structures
6 # Copyright (C) 2014 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=mreitz@redhat.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 here="$PWD"
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
45 # This test directly modifies a refblock so it relies on refcount_bits being 16
46 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
48 echo
49 echo '=== Repairing an image without any refcount table ==='
50 echo
52 _make_test_img 64M
53 # just write some data
54 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
56 # refcount_table_offset
57 poke_file "$TEST_IMG" $((0x30)) "\x00\x00\x00\x00\x00\x00\x00\x00"
58 # refcount_table_clusters
59 poke_file "$TEST_IMG" $((0x38)) "\x00\x00\x00\x00"
61 _check_test_img -r all
63 $QEMU_IO -c 'read -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
65 echo
66 echo '=== Repairing unreferenced data cluster in new refblock area ==='
67 echo
69 IMGOPTS='cluster_size=512' _make_test_img 64M
70 # Allocate the first 128 kB in the image (first refblock)
71 $QEMU_IO -c 'write 0 0x1b200' "$TEST_IMG" | _filter_qemu_io
72 # should be 131072 == 0x20000
73 stat -c '%s' "$TEST_IMG"
75 # Enter a cluster at 128 kB (0x20000)
76 # XXX: This should be the first free entry in the last L2 table, but we cannot
77 # be certain
78 poke_file "$TEST_IMG" $((0x1ccc8)) "\x80\x00\x00\x00\x00\x02\x00\x00"
80 # Fill the cluster
81 truncate -s $((0x20200)) "$TEST_IMG"
82 $QEMU_IO -c "open -o driver=raw $TEST_IMG" -c 'write -P 42 128k 512' \
83 | _filter_qemu_io
85 # The data should now appear at this guest offset
86 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
88 # This cluster is unallocated; fix it
89 _check_test_img -r all
91 # This repair operation must have allocated a new refblock; and that refblock
92 # should not overlap with the unallocated data cluster. If it does, the data
93 # will be damaged, so check it.
94 $QEMU_IO -c 'read -P 42 0x1b200 512' "$TEST_IMG" | _filter_qemu_io
96 echo
97 echo '=== Repairing refblock beyond the image end ==='
98 echo
100 echo
101 echo '--- Otherwise clean ---'
102 echo
104 _make_test_img 64M
105 # Normally, qemu doesn't create empty refblocks, so we just have to do it by
106 # hand
107 # XXX: This should be the entry for the second refblock
108 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
109 # Mark that refblock as used
110 # XXX: This should be the 17th entry (cluster 16) of the first
111 # refblock
112 poke_file "$TEST_IMG" $((0x20020)) "\x00\x01"
113 _check_test_img -r all
115 echo
116 echo '--- Refblock is unallocated ---'
117 echo
119 _make_test_img 64M
120 poke_file "$TEST_IMG" $((0x10008)) "\x00\x00\x00\x00\x00\x10\x00\x00"
121 _check_test_img -r all
123 echo
124 echo '--- Signed overflow after the refblock ---'
125 echo
127 _make_test_img 64M
128 poke_file "$TEST_IMG" $((0x10008)) "\x7f\xff\xff\xff\xff\xff\x00\x00"
129 _check_test_img -r all
131 echo
132 echo '--- Unsigned overflow after the refblock ---'
133 echo
135 _make_test_img 64M
136 poke_file "$TEST_IMG" $((0x10008)) "\xff\xff\xff\xff\xff\xff\x00\x00"
137 _check_test_img -r all
139 # success, all done
140 echo '*** done'
141 rm -f $seq.full
142 status=0