xref: /openbmc/qemu/tests/qemu-iotests/026 (revision 0e324626)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw blkdbg
352280eacSKevin Wolf#
452280eacSKevin Wolf# qcow2 error path testing
552280eacSKevin Wolf#
652280eacSKevin Wolf# Copyright (C) 2010 Red Hat, Inc.
752280eacSKevin Wolf#
852280eacSKevin Wolf# This program is free software; you can redistribute it and/or modify
952280eacSKevin Wolf# it under the terms of the GNU General Public License as published by
1052280eacSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1152280eacSKevin Wolf# (at your option) any later version.
1252280eacSKevin Wolf#
1352280eacSKevin Wolf# This program is distributed in the hope that it will be useful,
1452280eacSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1552280eacSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1652280eacSKevin Wolf# GNU General Public License for more details.
1752280eacSKevin Wolf#
1852280eacSKevin Wolf# You should have received a copy of the GNU General Public License
1952280eacSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2052280eacSKevin Wolf#
2152280eacSKevin Wolf
2252280eacSKevin Wolf# creator
2352280eacSKevin Wolfowner=kwolf@redhat.com
2452280eacSKevin Wolf
2552280eacSKevin Wolfseq=`basename $0`
2652280eacSKevin Wolfecho "QA output created by $seq"
2752280eacSKevin Wolf
2852280eacSKevin Wolfstatus=1	# failure is the default!
2952280eacSKevin Wolf
3052280eacSKevin Wolf_cleanup()
3152280eacSKevin Wolf{
3252280eacSKevin Wolf	_cleanup_test_img
33fef9c191SJeff Cody    rm "$TEST_DIR/blkdebug.conf"
3481311255SMax Reitz    rm -f "$TEST_IMG.data_file"
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
4557284d2aSMax Reitz_supported_proto file fuse
46755c5fe7SNir Soffer_default_cache_mode writethrough
47755c5fe7SNir Soffer_supported_cache_modes writethrough none
485262caa7SMax Reitz# The refcount table tests expect a certain minimum width for refcount entries
495262caa7SMax Reitz# (so that the refcount table actually needs to grow); that minimum is 16 bits,
505262caa7SMax Reitz# being the default refcount entry width.
515262caa7SMax Reitz# 32 and 64 bits do not work either, however, due to different leaked cluster
525262caa7SMax Reitz# count on error.
535262caa7SMax Reitz# Thus, the only remaining option is refcount_bits=16.
543be2024aSMax Reitz#
553be2024aSMax Reitz# As for data_file, none of the refcount tests can work for it.
563be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' \
573be2024aSMax Reitz    data_file
5852280eacSKevin Wolf
5952280eacSKevin Wolfecho "Errors while writing 128 kB"
6052280eacSKevin Wolfecho
6152280eacSKevin Wolf
6252280eacSKevin WolfCLUSTER_SIZE=1024
6352280eacSKevin Wolf
6452280eacSKevin WolfBLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
6552280eacSKevin Wolf
6652280eacSKevin Wolffor event in \
6752280eacSKevin Wolf    l1_update \
6852280eacSKevin Wolf    \
6952280eacSKevin Wolf    l2_load \
7052280eacSKevin Wolf    l2_update \
715be5b776SEric Blake    l2_alloc_write \
7252280eacSKevin Wolf    \
7352280eacSKevin Wolf    write_aio \
7452280eacSKevin Wolf    \
7552280eacSKevin Wolf    refblock_load \
7652280eacSKevin Wolf    refblock_update_part \
7752280eacSKevin Wolf    refblock_alloc \
7852280eacSKevin Wolf    \
7952280eacSKevin Wolf    cluster_alloc \
8052280eacSKevin Wolf
8152280eacSKevin Wolfdo
8252280eacSKevin Wolf
8352280eacSKevin Wolffor errno in 5 28; do
8452280eacSKevin Wolffor imm in off; do
8552280eacSKevin Wolffor once in on off; do
8652280eacSKevin Wolffor vmstate in "" "-b"; do
8752280eacSKevin Wolf
88fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
8952280eacSKevin Wolf[inject-error]
9052280eacSKevin Wolfevent = "$event"
9152280eacSKevin Wolferrno = "$errno"
9252280eacSKevin Wolfimmediately = "$imm"
9352280eacSKevin Wolfonce ="$once"
9452280eacSKevin WolfEOF
9552280eacSKevin Wolf
9652280eacSKevin Wolf_make_test_img 1G
9752280eacSKevin Wolf
9852280eacSKevin Wolfecho
9952280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
10092ab69b6SKevin Wolf
10192ab69b6SKevin Wolf# We want to catch a simple L2 update, not the allocation of the first L2 table
10292ab69b6SKevin Wolfif [ "$event" == "l2_update" ]; then
103fef9c191SJeff Cody    $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1
10492ab69b6SKevin Wolffi
10592ab69b6SKevin Wolf
106fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
10752280eacSKevin Wolf
10852280eacSKevin Wolf# l2_load is not called on allocation, so issue a second write
10952280eacSKevin Wolf# Reads are another path to trigger l2_load, so do a read, too
11052280eacSKevin Wolfif [ "$event" == "l2_load" ]; then
111fef9c191SJeff Cody    $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
112fef9c191SJeff Cody    $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io
11352280eacSKevin Wolffi
11452280eacSKevin Wolf
115ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
11652280eacSKevin Wolf
11752280eacSKevin Wolfdone
11852280eacSKevin Wolfdone
11952280eacSKevin Wolfdone
12052280eacSKevin Wolfdone
12152280eacSKevin Wolfdone
12252280eacSKevin Wolf
12352280eacSKevin Wolf
12452280eacSKevin Wolfecho
12582481694SEric Blakeecho === Refcount table growth tests ===
12652280eacSKevin Wolfecho
12752280eacSKevin WolfCLUSTER_SIZE=512
12852280eacSKevin Wolf
12952280eacSKevin Wolf
13052280eacSKevin Wolffor event in \
1315be5b776SEric Blake    refblock_alloc_hookup \
1325be5b776SEric Blake    refblock_alloc_write \
1335be5b776SEric Blake    refblock_alloc_write_blocks \
1345be5b776SEric Blake    refblock_alloc_write_table \
1355be5b776SEric Blake    refblock_alloc_switch_table \
13652280eacSKevin Wolf
13752280eacSKevin Wolfdo
13852280eacSKevin Wolf
13952280eacSKevin Wolf# This one takes a while, so let's test only one error code (ENOSPC should
14052280eacSKevin Wolf# never be generated by qemu, so it's probably a good choice)
14152280eacSKevin Wolffor errno in 28; do
14252280eacSKevin Wolffor imm in off; do
14352280eacSKevin Wolffor once in on off; do
14452280eacSKevin Wolffor vmstate in "" "-b"; do
14552280eacSKevin Wolf
146fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
14752280eacSKevin Wolf[inject-error]
14852280eacSKevin Wolfevent = "$event"
14952280eacSKevin Wolferrno = "$errno"
15052280eacSKevin Wolfimmediately = "$imm"
15152280eacSKevin Wolfonce = "$once"
15252280eacSKevin WolfEOF
15352280eacSKevin Wolf
15452280eacSKevin Wolf_make_test_img 1G
15552280eacSKevin Wolf
15652280eacSKevin Wolfecho
15752280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate"
158fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
15952280eacSKevin Wolf
160ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
16152280eacSKevin Wolf
16252280eacSKevin Wolfdone
16352280eacSKevin Wolfdone
16452280eacSKevin Wolfdone
16552280eacSKevin Wolfdone
16652280eacSKevin Wolfdone
16752280eacSKevin Wolf
16852280eacSKevin Wolfecho
16952280eacSKevin Wolfecho === L1 growth tests ===
17052280eacSKevin Wolfecho
17152280eacSKevin WolfCLUSTER_SIZE=1024
17252280eacSKevin Wolf
17352280eacSKevin Wolf
17452280eacSKevin Wolffor event in \
1755be5b776SEric Blake    l1_grow_alloc_table \
1765be5b776SEric Blake    l1_grow_write_table \
1775be5b776SEric Blake    l1_grow_activate_table \
17852280eacSKevin Wolf
17952280eacSKevin Wolfdo
18052280eacSKevin Wolf
18152280eacSKevin Wolffor errno in 5 28; do
18252280eacSKevin Wolffor imm in off; do
18352280eacSKevin Wolffor once in on off; do
18452280eacSKevin Wolf
185fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF
18652280eacSKevin Wolf[inject-error]
18752280eacSKevin Wolfevent = "$event"
18852280eacSKevin Wolferrno = "$errno"
18952280eacSKevin Wolfimmediately = "$imm"
19052280eacSKevin Wolfonce = "$once"
19152280eacSKevin WolfEOF
19252280eacSKevin Wolf
19352280eacSKevin Wolf_make_test_img 1G
19452280eacSKevin Wolf
19552280eacSKevin Wolfecho
19652280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once"
197fef9c191SJeff Cody$QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io
19852280eacSKevin Wolf
199ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0"
20052280eacSKevin Wolf
20152280eacSKevin Wolfdone
20252280eacSKevin Wolfdone
20352280eacSKevin Wolfdone
20452280eacSKevin Wolfdone
20552280eacSKevin Wolf
206ae376c62SKevin Wolfecho
207ae376c62SKevin Wolfecho === Avoid cluster leaks after temporary failure ===
208ae376c62SKevin Wolfecho
209ae376c62SKevin Wolf
210ae376c62SKevin Wolfcat > "$TEST_DIR/blkdebug.conf" <<EOF
211ae376c62SKevin Wolf[inject-error]
212ae376c62SKevin Wolfevent = "write_aio"
213ae376c62SKevin Wolferrno = "5"
214ae376c62SKevin Wolfonce = "on"
215ae376c62SKevin WolfEOF
216ae376c62SKevin Wolf
217ae376c62SKevin Wolf# After the failed first write, do a second write so that the updated refcount
218ae376c62SKevin Wolf# block is actually written back
219ae376c62SKevin Wolf_make_test_img 64M
220ae376c62SKevin Wolf$QEMU_IO -c "write 0 1M" -c "write 0 1M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
221ae376c62SKevin Wolf_check_test_img
222ae376c62SKevin Wolf
22331ab00f3SMax Reitzecho
22431ab00f3SMax Reitzecho === Avoid freeing preallocated zero clusters on failure ===
22531ab00f3SMax Reitzecho
22631ab00f3SMax Reitz
22731ab00f3SMax Reitzcat > "$TEST_DIR/blkdebug.conf" <<EOF
22831ab00f3SMax Reitz[inject-error]
22931ab00f3SMax Reitzevent = "write_aio"
23031ab00f3SMax Reitzerrno = "5"
23131ab00f3SMax Reitzonce = "on"
23231ab00f3SMax ReitzEOF
23331ab00f3SMax Reitz
23431ab00f3SMax Reitz_make_test_img $CLUSTER_SIZE
23531ab00f3SMax Reitz# Create a preallocated zero cluster
23631ab00f3SMax Reitz$QEMU_IO -c "write 0 $CLUSTER_SIZE" -c "write -z 0 $CLUSTER_SIZE" "$TEST_IMG" \
23731ab00f3SMax Reitz    | _filter_qemu_io
23831ab00f3SMax Reitz# Try to overwrite it (prompting an I/O error from blkdebug), thus
23931ab00f3SMax Reitz# triggering the alloc abort code
24031ab00f3SMax Reitz$QEMU_IO -c "write 0 $CLUSTER_SIZE" "$BLKDBG_TEST_IMG" | _filter_qemu_io
24131ab00f3SMax Reitz
24231ab00f3SMax Reitz_check_test_img
24331ab00f3SMax Reitz
24452280eacSKevin Wolf# success, all done
24552280eacSKevin Wolfecho "*** done"
24652280eacSKevin Wolfrm -f $seq.full
24752280eacSKevin Wolfstatus=0
248