]> Git Repo - qemu.git/blob - tests/qemu-iotests/026
tests/docker: Remove old Debian 9 containers
[qemu.git] / tests / qemu-iotests / 026
1 #!/usr/bin/env 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 [email protected]
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 status=1        # failure is the default!
28
29 _cleanup()
30 {
31         _cleanup_test_img
32     rm "$TEST_DIR/blkdebug.conf"
33     rm -f "$TEST_IMG.data_file"
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40 . ./common.pattern
41
42 # Currently only qcow2 supports rebasing
43 _supported_fmt qcow2
44 _supported_proto file
45 _default_cache_mode writethrough
46 _supported_cache_modes writethrough none
47 # The refcount table tests expect a certain minimum width for refcount entries
48 # (so that the refcount table actually needs to grow); that minimum is 16 bits,
49 # being the default refcount entry width.
50 # 32 and 64 bits do not work either, however, due to different leaked cluster
51 # count on error.
52 # Thus, the only remaining option is refcount_bits=16.
53 #
54 # As for data_file, none of the refcount tests can work for it.
55 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' \
56     data_file
57
58 echo "Errors while writing 128 kB"
59 echo
60
61 CLUSTER_SIZE=1024
62
63 BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
64
65 for event in \
66     l1_update \
67     \
68     l2_load \
69     l2_update \
70     l2_alloc_write \
71     \
72     write_aio \
73     \
74     refblock_load \
75     refblock_update_part \
76     refblock_alloc \
77     \
78     cluster_alloc \
79
80 do
81
82 for errno in 5 28; do
83 for imm in off; do
84 for once in on off; do
85 for vmstate in "" "-b"; do
86
87 cat > "$TEST_DIR/blkdebug.conf" <<EOF
88 [inject-error]
89 event = "$event"
90 errno = "$errno"
91 immediately = "$imm"
92 once ="$once"
93 EOF
94
95 _make_test_img 1G
96
97 echo
98 echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
99
100 # We want to catch a simple L2 update, not the allocation of the first L2 table
101 if [ "$event" == "l2_update" ]; then
102     $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1
103 fi
104
105 $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
106
107 # l2_load is not called on allocation, so issue a second write
108 # Reads are another path to trigger l2_load, so do a read, too
109 if [ "$event" == "l2_load" ]; then
110     $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
111     $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
112 fi
113
114 _check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
115
116 done
117 done
118 done
119 done
120 done
121
122
123 echo
124 echo === Refcount table growth tests ===
125 echo
126 CLUSTER_SIZE=512
127
128
129 for event in \
130     refblock_alloc_hookup \
131     refblock_alloc_write \
132     refblock_alloc_write_blocks \
133     refblock_alloc_write_table \
134     refblock_alloc_switch_table \
135
136 do
137
138 # This one takes a while, so let's test only one error code (ENOSPC should
139 # never be generated by qemu, so it's probably a good choice)
140 for errno in 28; do
141 for imm in off; do
142 for once in on off; do
143 for vmstate in "" "-b"; do
144
145 cat > "$TEST_DIR/blkdebug.conf" <<EOF
146 [inject-error]
147 event = "$event"
148 errno = "$errno"
149 immediately = "$imm"
150 once = "$once"
151 EOF
152
153 _make_test_img 1G
154
155 echo
156 echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
157 $QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
158
159 _check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
160
161 done
162 done
163 done
164 done
165 done
166
167 echo
168 echo === L1 growth tests ===
169 echo
170 CLUSTER_SIZE=1024
171
172
173 for event in \
174     l1_grow_alloc_table \
175     l1_grow_write_table \
176     l1_grow_activate_table \
177
178 do
179
180 for errno in 5 28; do
181 for imm in off; do
182 for once in on off; do
183
184 cat > "$TEST_DIR/blkdebug.conf" <<EOF
185 [inject-error]
186 event = "$event"
187 errno = "$errno"
188 immediately = "$imm"
189 once = "$once"
190 EOF
191
192 _make_test_img 1G
193
194 echo
195 echo "Event: $event; errno: $errno; imm: $imm; once: $once"
196 $QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io
197
198 _check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
199
200 done
201 done
202 done
203 done
204
205 echo
206 echo === Avoid cluster leaks after temporary failure ===
207 echo
208
209 cat > "$TEST_DIR/blkdebug.conf" <<EOF
210 [inject-error]
211 event = "write_aio"
212 errno = "5"
213 once = "on"
214 EOF
215
216 # After the failed first write, do a second write so that the updated refcount
217 # block is actually written back
218 _make_test_img 64M
219 $QEMU_IO -c "write 0 1M" -c "write 0 1M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
220 _check_test_img
221
222 echo
223 echo === Avoid freeing preallocated zero clusters on failure ===
224 echo
225
226 cat > "$TEST_DIR/blkdebug.conf" <<EOF
227 [inject-error]
228 event = "write_aio"
229 errno = "5"
230 once = "on"
231 EOF
232
233 _make_test_img $CLUSTER_SIZE
234 # Create a preallocated zero cluster
235 $QEMU_IO -c "write 0 $CLUSTER_SIZE" -c "write -z 0 $CLUSTER_SIZE" "$TEST_IMG" \
236     | _filter_qemu_io
237 # Try to overwrite it (prompting an I/O error from blkdebug), thus
238 # triggering the alloc abort code
239 $QEMU_IO -c "write 0 $CLUSTER_SIZE" "$BLKDBG_TEST_IMG" | _filter_qemu_io
240
241 _check_test_img
242
243 # success, all done
244 echo "*** done"
245 rm -f $seq.full
246 status=0
This page took 0.035881 seconds and 4 git commands to generate.