xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 9cdfa1b3)
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
27here=`pwd`
28tmp=/tmp/$$
29status=1	# failure is the default!
30
31_cleanup()
32{
33	_cleanup_test_img
34    rm $TEST_DIR/blkdebug.conf
35}
36trap "_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 generic
46_supported_os Linux
47
48
49echo "Errors while writing 128 kB"
50echo
51
52CLUSTER_SIZE=1024
53
54BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
55
56for event in \
57    l1_update \
58    \
59    l2_load \
60    l2_update \
61    l2_alloc.write \
62    \
63    write_aio \
64    \
65    refblock_load \
66    refblock_update_part \
67    refblock_alloc \
68    \
69    cluster_alloc \
70
71do
72
73for errno in 5 28; do
74for imm in off; do
75for once in on off; do
76for vmstate in "" "-b"; do
77
78cat > $TEST_DIR/blkdebug.conf <<EOF
79[inject-error]
80event = "$event"
81errno = "$errno"
82immediately = "$imm"
83once ="$once"
84EOF
85
86_make_test_img 1G
87
88echo
89echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
90$QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
91
92# l2_load is not called on allocation, so issue a second write
93# Reads are another path to trigger l2_load, so do a read, too
94if [ "$event" == "l2_load" ]; then
95    $QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
96    $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
97fi
98
99$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
100
101done
102done
103done
104done
105done
106
107
108echo
109echo === Refcout table growth tests ===
110echo
111CLUSTER_SIZE=512
112
113
114for event in \
115    refblock_alloc.hookup \
116    refblock_alloc.write \
117    refblock_alloc.write_blocks \
118    refblock_alloc.write_table \
119    refblock_alloc.switch_table \
120
121do
122
123# This one takes a while, so let's test only one error code (ENOSPC should
124# never be generated by qemu, so it's probably a good choice)
125for errno in 28; do
126for imm in off; do
127for once in on off; do
128for vmstate in "" "-b"; do
129
130cat > $TEST_DIR/blkdebug.conf <<EOF
131[inject-error]
132event = "$event"
133errno = "$errno"
134immediately = "$imm"
135once = "$once"
136EOF
137
138_make_test_img 1G
139
140echo
141echo "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
142$QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
143
144$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
145
146done
147done
148done
149done
150done
151
152echo
153echo === L1 growth tests ===
154echo
155CLUSTER_SIZE=1024
156
157
158for event in \
159    l1_grow.alloc_table \
160    l1_grow.write_table \
161    l1_grow.activate_table \
162
163do
164
165for errno in 5 28; do
166for imm in off; do
167for once in on off; do
168
169cat > $TEST_DIR/blkdebug.conf <<EOF
170[inject-error]
171event = "$event"
172errno = "$errno"
173immediately = "$imm"
174once = "$once"
175EOF
176
177_make_test_img 1G
178
179echo
180echo "Event: $event; errno: $errno; imm: $imm; once: $once"
181$QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
182
183$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
184
185done
186done
187done
188done
189
190# success, all done
191echo "*** done"
192rm -f $seq.full
193status=0
194