Add qemu 2.4.0
[kvmfornfv.git] / qemu / tests / qemu-iotests / 026
1 #!/bin/bash
2 #
3 # qcow2 error path testing
4 #
5 # Copyright (C) 2010 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=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30
31 _cleanup()
32 {
33         _cleanup_test_img
34     rm "$TEST_DIR/blkdebug.conf"
35 }
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41 . ./common.pattern
42
43 # Currently only qcow2 supports rebasing
44 _supported_fmt qcow2
45 _supported_proto file
46 _supported_os Linux
47 _default_cache_mode "writethrough"
48 _supported_cache_modes "writethrough" "none"
49 # The refcount table tests expect a certain minimum width for refcount entries
50 # (so that the refcount table actually needs to grow); that minimum is 16 bits,
51 # being the default refcount entry width.
52 # 32 and 64 bits do not work either, however, due to different leaked cluster
53 # count on error.
54 # Thus, the only remaining option is refcount_bits=16.
55 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
56
57 echo "Errors while writing 128 kB"
58 echo
59
60 CLUSTER_SIZE=1024
61
62 BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
63
64 for event in \
65     l1_update \
66     \
67     l2_load \
68     l2_update \
69     l2_alloc.write \
70     \
71     write_aio \
72     \
73     refblock_load \
74     refblock_update_part \
75     refblock_alloc \
76     \
77     cluster_alloc \
78
79 do
80
81 for errno in 5 28; do
82 for imm in off; do
83 for once in on off; do
84 for vmstate in "" "-b"; do
85
86 cat > "$TEST_DIR/blkdebug.conf" <<EOF
87 [inject-error]
88 event = "$event"
89 errno = "$errno"
90 immediately = "$imm"
91 once ="$once"
92 EOF
93
94 _make_test_img 1G
95
96 echo
97 echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
98
99 # We want to catch a simple L2 update, not the allocation of the first L2 table
100 if [ "$event" == "l2_update" ]; then
101     $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1
102 fi
103
104 $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
105
106 # l2_load is not called on allocation, so issue a second write
107 # Reads are another path to trigger l2_load, so do a read, too
108 if [ "$event" == "l2_load" ]; then
109     $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
110     $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
111 fi
112
113 _check_test_img 2>&1 | grep -v "refcount=1 reference=0"
114
115 done
116 done
117 done
118 done
119 done
120
121
122 echo
123 echo === Refcout table growth tests ===
124 echo
125 CLUSTER_SIZE=512
126
127
128 for event in \
129     refblock_alloc.hookup \
130     refblock_alloc.write \
131     refblock_alloc.write_blocks \
132     refblock_alloc.write_table \
133     refblock_alloc.switch_table \
134
135 do
136
137 # This one takes a while, so let's test only one error code (ENOSPC should
138 # never be generated by qemu, so it's probably a good choice)
139 for errno in 28; do
140 for imm in off; do
141 for once in on off; do
142 for vmstate in "" "-b"; do
143
144 cat > "$TEST_DIR/blkdebug.conf" <<EOF
145 [inject-error]
146 event = "$event"
147 errno = "$errno"
148 immediately = "$imm"
149 once = "$once"
150 EOF
151
152 _make_test_img 1G
153
154 echo
155 echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
156 $QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
157
158 _check_test_img 2>&1 | grep -v "refcount=1 reference=0"
159
160 done
161 done
162 done
163 done
164 done
165
166 echo
167 echo === L1 growth tests ===
168 echo
169 CLUSTER_SIZE=1024
170
171
172 for event in \
173     l1_grow.alloc_table \
174     l1_grow.write_table \
175     l1_grow.activate_table \
176
177 do
178
179 for errno in 5 28; do
180 for imm in off; do
181 for once in on off; do
182
183 cat > "$TEST_DIR/blkdebug.conf" <<EOF
184 [inject-error]
185 event = "$event"
186 errno = "$errno"
187 immediately = "$imm"
188 once = "$once"
189 EOF
190
191 _make_test_img 1G
192
193 echo
194 echo "Event: $event; errno: $errno; imm: $imm; once: $once"
195 $QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io
196
197 _check_test_img 2>&1 | grep -v "refcount=1 reference=0"
198
199 done
200 done
201 done
202 done
203
204 # success, all done
205 echo "*** done"
206 rm -f $seq.full
207 status=0