xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 709395f8)
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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29_cleanup()
30{
31	_cleanup_test_img
32    rm "$TEST_DIR/blkdebug.conf"
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39. ./common.pattern
40
41# Currently only qcow2 supports rebasing
42_supported_fmt qcow2
43_supported_proto file
44_supported_os Linux
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_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
54
55echo "Errors while writing 128 kB"
56echo
57
58CLUSTER_SIZE=1024
59
60BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
61
62for event in \
63    l1_update \
64    \
65    l2_load \
66    l2_update \
67    l2_alloc_write \
68    \
69    write_aio \
70    \
71    refblock_load \
72    refblock_update_part \
73    refblock_alloc \
74    \
75    cluster_alloc \
76
77do
78
79for errno in 5 28; do
80for imm in off; do
81for once in on off; do
82for vmstate in "" "-b"; do
83
84cat > "$TEST_DIR/blkdebug.conf" <<EOF
85[inject-error]
86event = "$event"
87errno = "$errno"
88immediately = "$imm"
89once ="$once"
90EOF
91
92_make_test_img 1G
93
94echo
95echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
96
97# We want to catch a simple L2 update, not the allocation of the first L2 table
98if [ "$event" == "l2_update" ]; then
99    $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1
100fi
101
102$QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
103
104# l2_load is not called on allocation, so issue a second write
105# Reads are another path to trigger l2_load, so do a read, too
106if [ "$event" == "l2_load" ]; then
107    $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
108    $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
109fi
110
111_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
112
113done
114done
115done
116done
117done
118
119
120echo
121echo === Refcount table growth tests ===
122echo
123CLUSTER_SIZE=512
124
125
126for event in \
127    refblock_alloc_hookup \
128    refblock_alloc_write \
129    refblock_alloc_write_blocks \
130    refblock_alloc_write_table \
131    refblock_alloc_switch_table \
132
133do
134
135# This one takes a while, so let's test only one error code (ENOSPC should
136# never be generated by qemu, so it's probably a good choice)
137for errno in 28; do
138for imm in off; do
139for once in on off; do
140for vmstate in "" "-b"; do
141
142cat > "$TEST_DIR/blkdebug.conf" <<EOF
143[inject-error]
144event = "$event"
145errno = "$errno"
146immediately = "$imm"
147once = "$once"
148EOF
149
150_make_test_img 1G
151
152echo
153echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
154$QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
155
156_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
157
158done
159done
160done
161done
162done
163
164echo
165echo === L1 growth tests ===
166echo
167CLUSTER_SIZE=1024
168
169
170for event in \
171    l1_grow_alloc_table \
172    l1_grow_write_table \
173    l1_grow_activate_table \
174
175do
176
177for errno in 5 28; do
178for imm in off; do
179for once in on off; do
180
181cat > "$TEST_DIR/blkdebug.conf" <<EOF
182[inject-error]
183event = "$event"
184errno = "$errno"
185immediately = "$imm"
186once = "$once"
187EOF
188
189_make_test_img 1G
190
191echo
192echo "Event: $event; errno: $errno; imm: $imm; once: $once"
193$QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io
194
195_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
196
197done
198done
199done
200done
201
202echo
203echo === Avoid cluster leaks after temporary failure ===
204echo
205
206cat > "$TEST_DIR/blkdebug.conf" <<EOF
207[inject-error]
208event = "write_aio"
209errno = "5"
210once = "on"
211EOF
212
213# After the failed first write, do a second write so that the updated refcount
214# block is actually written back
215_make_test_img 64M
216$QEMU_IO -c "write 0 1M" -c "write 0 1M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
217_check_test_img
218
219# success, all done
220echo "*** done"
221rm -f $seq.full
222status=0
223