xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 1f7bf7d0687f5a58613358f5e7cfd8f29a3a21e2)
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
34fef9c191SJeff Cody    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*1f7bf7d0SPeter Lieven_supported_proto file
4652280eacSKevin Wolf_supported_os Linux
47f210a83cSFam Zheng_default_cache_mode "writethrough"
48f210a83cSFam Zheng_supported_cache_modes "writethrough" "none"
4952280eacSKevin Wolf
5052280eacSKevin Wolfecho "Errors while writing 128 kB"
5152280eacSKevin Wolfecho
5252280eacSKevin Wolf
5352280eacSKevin WolfCLUSTER_SIZE=1024
5452280eacSKevin Wolf
5552280eacSKevin WolfBLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
5652280eacSKevin Wolf
5752280eacSKevin Wolffor event in \
5852280eacSKevin Wolf    l1_update \
5952280eacSKevin Wolf    \
6052280eacSKevin Wolf    l2_load \
6152280eacSKevin Wolf    l2_update \
6252280eacSKevin Wolf    l2_alloc.write \
6352280eacSKevin Wolf    \
6452280eacSKevin Wolf    write_aio \
6552280eacSKevin Wolf    \
6652280eacSKevin Wolf    refblock_load \
6752280eacSKevin Wolf    refblock_update_part \
6852280eacSKevin Wolf    refblock_alloc \
6952280eacSKevin Wolf    \
7052280eacSKevin Wolf    cluster_alloc \
7152280eacSKevin Wolf
7252280eacSKevin Wolfdo
7352280eacSKevin Wolf
7452280eacSKevin Wolffor errno in 5 28; do
7552280eacSKevin Wolffor imm in off; do
7652280eacSKevin Wolffor once in on off; do
7752280eacSKevin Wolffor vmstate in "" "-b"; do
7852280eacSKevin Wolf
79fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
8052280eacSKevin Wolf[inject-error]
8152280eacSKevin Wolfevent = "$event"
8252280eacSKevin Wolferrno = "$errno"
8352280eacSKevin Wolfimmediately = "$imm"
8452280eacSKevin Wolfonce ="$once"
8552280eacSKevin WolfEOF
8652280eacSKevin Wolf
8752280eacSKevin Wolf_make_test_img 1G
8852280eacSKevin Wolf
8952280eacSKevin Wolfecho
9052280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
9192ab69b6SKevin Wolf
9292ab69b6SKevin Wolf# We want to catch a simple L2 update, not the allocation of the first L2 table
9392ab69b6SKevin Wolfif [ "$event" == "l2_update" ]; then
94fef9c191SJeff Cody    $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1
9592ab69b6SKevin Wolffi
9692ab69b6SKevin Wolf
97fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
9852280eacSKevin Wolf
9952280eacSKevin Wolf# l2_load is not called on allocation, so issue a second write
10052280eacSKevin Wolf# Reads are another path to trigger l2_load, so do a read, too
10152280eacSKevin Wolfif [ "$event" == "l2_load" ]; then
102fef9c191SJeff Cody    $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
103fef9c191SJeff Cody    $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
10452280eacSKevin Wolffi
10552280eacSKevin Wolf
106c6bb9ad1SFederico Simoncelli_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
10752280eacSKevin Wolf
10852280eacSKevin Wolfdone
10952280eacSKevin Wolfdone
11052280eacSKevin Wolfdone
11152280eacSKevin Wolfdone
11252280eacSKevin Wolfdone
11352280eacSKevin Wolf
11452280eacSKevin Wolf
11552280eacSKevin Wolfecho
11652280eacSKevin Wolfecho === Refcout table growth tests ===
11752280eacSKevin Wolfecho
11852280eacSKevin WolfCLUSTER_SIZE=512
11952280eacSKevin Wolf
12052280eacSKevin Wolf
12152280eacSKevin Wolffor event in \
12252280eacSKevin Wolf    refblock_alloc.hookup \
12352280eacSKevin Wolf    refblock_alloc.write \
12452280eacSKevin Wolf    refblock_alloc.write_blocks \
12552280eacSKevin Wolf    refblock_alloc.write_table \
12652280eacSKevin Wolf    refblock_alloc.switch_table \
12752280eacSKevin Wolf
12852280eacSKevin Wolfdo
12952280eacSKevin Wolf
13052280eacSKevin Wolf# This one takes a while, so let's test only one error code (ENOSPC should
13152280eacSKevin Wolf# never be generated by qemu, so it's probably a good choice)
13252280eacSKevin Wolffor errno in 28; do
13352280eacSKevin Wolffor imm in off; do
13452280eacSKevin Wolffor once in on off; do
13552280eacSKevin Wolffor vmstate in "" "-b"; do
13652280eacSKevin Wolf
137fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
13852280eacSKevin Wolf[inject-error]
13952280eacSKevin Wolfevent = "$event"
14052280eacSKevin Wolferrno = "$errno"
14152280eacSKevin Wolfimmediately = "$imm"
14252280eacSKevin Wolfonce = "$once"
14352280eacSKevin WolfEOF
14452280eacSKevin Wolf
14552280eacSKevin Wolf_make_test_img 1G
14652280eacSKevin Wolf
14752280eacSKevin Wolfecho
14852280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
149fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
15052280eacSKevin Wolf
151c6bb9ad1SFederico Simoncelli_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
15252280eacSKevin Wolf
15352280eacSKevin Wolfdone
15452280eacSKevin Wolfdone
15552280eacSKevin Wolfdone
15652280eacSKevin Wolfdone
15752280eacSKevin Wolfdone
15852280eacSKevin Wolf
15952280eacSKevin Wolfecho
16052280eacSKevin Wolfecho === L1 growth tests ===
16152280eacSKevin Wolfecho
16252280eacSKevin WolfCLUSTER_SIZE=1024
16352280eacSKevin Wolf
16452280eacSKevin Wolf
16552280eacSKevin Wolffor event in \
16652280eacSKevin Wolf    l1_grow.alloc_table \
16752280eacSKevin Wolf    l1_grow.write_table \
16852280eacSKevin Wolf    l1_grow.activate_table \
16952280eacSKevin Wolf
17052280eacSKevin Wolfdo
17152280eacSKevin Wolf
17252280eacSKevin Wolffor errno in 5 28; do
17352280eacSKevin Wolffor imm in off; do
17452280eacSKevin Wolffor once in on off; do
17552280eacSKevin Wolf
176fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
17752280eacSKevin Wolf[inject-error]
17852280eacSKevin Wolfevent = "$event"
17952280eacSKevin Wolferrno = "$errno"
18052280eacSKevin Wolfimmediately = "$imm"
18152280eacSKevin Wolfonce = "$once"
18252280eacSKevin WolfEOF
18352280eacSKevin Wolf
18452280eacSKevin Wolf_make_test_img 1G
18552280eacSKevin Wolf
18652280eacSKevin Wolfecho
18752280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once"
188fef9c191SJeff Cody$QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io
18952280eacSKevin Wolf
190c6bb9ad1SFederico Simoncelli_check_test_img 2>&1 | grep -v "refcount=1 reference=0"
19152280eacSKevin Wolf
19252280eacSKevin Wolfdone
19352280eacSKevin Wolfdone
19452280eacSKevin Wolfdone
19552280eacSKevin Wolfdone
19652280eacSKevin Wolf
19752280eacSKevin Wolf# success, all done
19852280eacSKevin Wolfecho "*** done"
19952280eacSKevin Wolfrm -f $seq.full
20052280eacSKevin Wolfstatus=0
201