xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 9cdfa1b34e22bc09e80042b1ef3e4a5096f260d5)
152280eacSKevin Wolf#!/bin/bash
252280eacSKevin Wolf#
352280eacSKevin Wolf# qcow2 error path testing
452280eacSKevin Wolf#
552280eacSKevin Wolf# Copyright (C) 2010 Red Hat, Inc.
652280eacSKevin Wolf#
752280eacSKevin Wolf# This program is free software; you can redistribute it and/or modify
852280eacSKevin Wolf# it under the terms of the GNU General Public License as published by
952280eacSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1052280eacSKevin Wolf# (at your option) any later version.
1152280eacSKevin Wolf#
1252280eacSKevin Wolf# This program is distributed in the hope that it will be useful,
1352280eacSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1452280eacSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1552280eacSKevin Wolf# GNU General Public License for more details.
1652280eacSKevin Wolf#
1752280eacSKevin Wolf# You should have received a copy of the GNU General Public License
1852280eacSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1952280eacSKevin Wolf#
2052280eacSKevin Wolf
2152280eacSKevin Wolf# creator
2252280eacSKevin Wolfowner=kwolf@redhat.com
2352280eacSKevin Wolf
2452280eacSKevin Wolfseq=`basename $0`
2552280eacSKevin Wolfecho "QA output created by $seq"
2652280eacSKevin Wolf
2752280eacSKevin Wolfhere=`pwd`
2852280eacSKevin Wolftmp=/tmp/$$
2952280eacSKevin Wolfstatus=1	# failure is the default!
3052280eacSKevin Wolf
3152280eacSKevin Wolf_cleanup()
3252280eacSKevin Wolf{
3352280eacSKevin Wolf	_cleanup_test_img
3452280eacSKevin Wolf    rm $TEST_DIR/blkdebug.conf
3552280eacSKevin Wolf}
3652280eacSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3752280eacSKevin Wolf
3852280eacSKevin Wolf# get standard environment, filters and checks
3952280eacSKevin Wolf. ./common.rc
4052280eacSKevin Wolf. ./common.filter
4152280eacSKevin Wolf. ./common.pattern
4252280eacSKevin Wolf
4352280eacSKevin Wolf# Currently only qcow2 supports rebasing
4452280eacSKevin Wolf_supported_fmt qcow2
45*9cdfa1b3SMORITA Kazutaka_supported_proto generic
4652280eacSKevin Wolf_supported_os Linux
4752280eacSKevin Wolf
4852280eacSKevin Wolf
4952280eacSKevin Wolfecho "Errors while writing 128 kB"
5052280eacSKevin Wolfecho
5152280eacSKevin Wolf
5252280eacSKevin WolfCLUSTER_SIZE=1024
5352280eacSKevin Wolf
5452280eacSKevin WolfBLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
5552280eacSKevin Wolf
5652280eacSKevin Wolffor event in \
5752280eacSKevin Wolf    l1_update \
5852280eacSKevin Wolf    \
5952280eacSKevin Wolf    l2_load \
6052280eacSKevin Wolf    l2_update \
6152280eacSKevin Wolf    l2_alloc.write \
6252280eacSKevin Wolf    \
6352280eacSKevin Wolf    write_aio \
6452280eacSKevin Wolf    \
6552280eacSKevin Wolf    refblock_load \
6652280eacSKevin Wolf    refblock_update_part \
6752280eacSKevin Wolf    refblock_alloc \
6852280eacSKevin Wolf    \
6952280eacSKevin Wolf    cluster_alloc \
7052280eacSKevin Wolf
7152280eacSKevin Wolfdo
7252280eacSKevin Wolf
7352280eacSKevin Wolffor errno in 5 28; do
7452280eacSKevin Wolffor imm in off; do
7552280eacSKevin Wolffor once in on off; do
7652280eacSKevin Wolffor vmstate in "" "-b"; do
7752280eacSKevin Wolf
7852280eacSKevin Wolfcat > $TEST_DIR/blkdebug.conf <<EOF
7952280eacSKevin Wolf[inject-error]
8052280eacSKevin Wolfevent = "$event"
8152280eacSKevin Wolferrno = "$errno"
8252280eacSKevin Wolfimmediately = "$imm"
8352280eacSKevin Wolfonce ="$once"
8452280eacSKevin WolfEOF
8552280eacSKevin Wolf
8652280eacSKevin Wolf_make_test_img 1G
8752280eacSKevin Wolf
8852280eacSKevin Wolfecho
8952280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
9052280eacSKevin Wolf$QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
9152280eacSKevin Wolf
9252280eacSKevin Wolf# l2_load is not called on allocation, so issue a second write
9352280eacSKevin Wolf# Reads are another path to trigger l2_load, so do a read, too
9452280eacSKevin Wolfif [ "$event" == "l2_load" ]; then
9552280eacSKevin Wolf    $QEMU_IO -c "write $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
9652280eacSKevin Wolf    $QEMU_IO -c "read $vmstate 0 128k " $BLKDBG_TEST_IMG | _filter_qemu_io
9752280eacSKevin Wolffi
9852280eacSKevin Wolf
9952280eacSKevin Wolf$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
10052280eacSKevin Wolf
10152280eacSKevin Wolfdone
10252280eacSKevin Wolfdone
10352280eacSKevin Wolfdone
10452280eacSKevin Wolfdone
10552280eacSKevin Wolfdone
10652280eacSKevin Wolf
10752280eacSKevin Wolf
10852280eacSKevin Wolfecho
10952280eacSKevin Wolfecho === Refcout table growth tests ===
11052280eacSKevin Wolfecho
11152280eacSKevin WolfCLUSTER_SIZE=512
11252280eacSKevin Wolf
11352280eacSKevin Wolf
11452280eacSKevin Wolffor event in \
11552280eacSKevin Wolf    refblock_alloc.hookup \
11652280eacSKevin Wolf    refblock_alloc.write \
11752280eacSKevin Wolf    refblock_alloc.write_blocks \
11852280eacSKevin Wolf    refblock_alloc.write_table \
11952280eacSKevin Wolf    refblock_alloc.switch_table \
12052280eacSKevin Wolf
12152280eacSKevin Wolfdo
12252280eacSKevin Wolf
12352280eacSKevin Wolf# This one takes a while, so let's test only one error code (ENOSPC should
12452280eacSKevin Wolf# never be generated by qemu, so it's probably a good choice)
12552280eacSKevin Wolffor errno in 28; do
12652280eacSKevin Wolffor imm in off; do
12752280eacSKevin Wolffor once in on off; do
12852280eacSKevin Wolffor vmstate in "" "-b"; do
12952280eacSKevin Wolf
13052280eacSKevin Wolfcat > $TEST_DIR/blkdebug.conf <<EOF
13152280eacSKevin Wolf[inject-error]
13252280eacSKevin Wolfevent = "$event"
13352280eacSKevin Wolferrno = "$errno"
13452280eacSKevin Wolfimmediately = "$imm"
13552280eacSKevin Wolfonce = "$once"
13652280eacSKevin WolfEOF
13752280eacSKevin Wolf
13852280eacSKevin Wolf_make_test_img 1G
13952280eacSKevin Wolf
14052280eacSKevin Wolfecho
14152280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
14252280eacSKevin Wolf$QEMU_IO -c "write $vmstate 0 64M" $BLKDBG_TEST_IMG | _filter_qemu_io
14352280eacSKevin Wolf
14452280eacSKevin Wolf$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
14552280eacSKevin Wolf
14652280eacSKevin Wolfdone
14752280eacSKevin Wolfdone
14852280eacSKevin Wolfdone
14952280eacSKevin Wolfdone
15052280eacSKevin Wolfdone
15152280eacSKevin Wolf
15252280eacSKevin Wolfecho
15352280eacSKevin Wolfecho === L1 growth tests ===
15452280eacSKevin Wolfecho
15552280eacSKevin WolfCLUSTER_SIZE=1024
15652280eacSKevin Wolf
15752280eacSKevin Wolf
15852280eacSKevin Wolffor event in \
15952280eacSKevin Wolf    l1_grow.alloc_table \
16052280eacSKevin Wolf    l1_grow.write_table \
16152280eacSKevin Wolf    l1_grow.activate_table \
16252280eacSKevin Wolf
16352280eacSKevin Wolfdo
16452280eacSKevin Wolf
16552280eacSKevin Wolffor errno in 5 28; do
16652280eacSKevin Wolffor imm in off; do
16752280eacSKevin Wolffor once in on off; do
16852280eacSKevin Wolf
16952280eacSKevin Wolfcat > $TEST_DIR/blkdebug.conf <<EOF
17052280eacSKevin Wolf[inject-error]
17152280eacSKevin Wolfevent = "$event"
17252280eacSKevin Wolferrno = "$errno"
17352280eacSKevin Wolfimmediately = "$imm"
17452280eacSKevin Wolfonce = "$once"
17552280eacSKevin WolfEOF
17652280eacSKevin Wolf
17752280eacSKevin Wolf_make_test_img 1G
17852280eacSKevin Wolf
17952280eacSKevin Wolfecho
18052280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once"
18152280eacSKevin Wolf$QEMU_IO -c "write -b 0 64k" $BLKDBG_TEST_IMG | _filter_qemu_io
18252280eacSKevin Wolf
18352280eacSKevin Wolf$QEMU_IMG check $TEST_IMG 2>&1 | grep -v "refcount=1 reference=0"
18452280eacSKevin Wolf
18552280eacSKevin Wolfdone
18652280eacSKevin Wolfdone
18752280eacSKevin Wolfdone
18852280eacSKevin Wolfdone
18952280eacSKevin Wolf
19052280eacSKevin Wolf# success, all done
19152280eacSKevin Wolfecho "*** done"
19252280eacSKevin Wolfrm -f $seq.full
19352280eacSKevin Wolfstatus=0
194