111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1 # failure is the default! 2852280eacSKevin Wolf 2952280eacSKevin Wolf_cleanup() 3052280eacSKevin Wolf{ 3152280eacSKevin Wolf _cleanup_test_img 32fef9c191SJeff Cody rm "$TEST_DIR/blkdebug.conf" 3352280eacSKevin Wolf} 3452280eacSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3552280eacSKevin Wolf 3652280eacSKevin Wolf# get standard environment, filters and checks 3752280eacSKevin Wolf. ./common.rc 3852280eacSKevin Wolf. ./common.filter 3952280eacSKevin Wolf. ./common.pattern 4052280eacSKevin Wolf 4152280eacSKevin Wolf# Currently only qcow2 supports rebasing 4252280eacSKevin Wolf_supported_fmt qcow2 431f7bf7d0SPeter Lieven_supported_proto file 44755c5fe7SNir Soffer_default_cache_mode writethrough 45755c5fe7SNir Soffer_supported_cache_modes writethrough none 465262caa7SMax Reitz# The refcount table tests expect a certain minimum width for refcount entries 475262caa7SMax Reitz# (so that the refcount table actually needs to grow); that minimum is 16 bits, 485262caa7SMax Reitz# being the default refcount entry width. 495262caa7SMax Reitz# 32 and 64 bits do not work either, however, due to different leaked cluster 505262caa7SMax Reitz# count on error. 515262caa7SMax Reitz# Thus, the only remaining option is refcount_bits=16. 52*3be2024aSMax Reitz# 53*3be2024aSMax Reitz# As for data_file, none of the refcount tests can work for it. 54*3be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' \ 55*3be2024aSMax Reitz data_file 5652280eacSKevin Wolf 5752280eacSKevin Wolfecho "Errors while writing 128 kB" 5852280eacSKevin Wolfecho 5952280eacSKevin Wolf 6052280eacSKevin WolfCLUSTER_SIZE=1024 6152280eacSKevin Wolf 6252280eacSKevin WolfBLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG" 6352280eacSKevin Wolf 6452280eacSKevin Wolffor event in \ 6552280eacSKevin Wolf l1_update \ 6652280eacSKevin Wolf \ 6752280eacSKevin Wolf l2_load \ 6852280eacSKevin Wolf l2_update \ 695be5b776SEric Blake l2_alloc_write \ 7052280eacSKevin Wolf \ 7152280eacSKevin Wolf write_aio \ 7252280eacSKevin Wolf \ 7352280eacSKevin Wolf refblock_load \ 7452280eacSKevin Wolf refblock_update_part \ 7552280eacSKevin Wolf refblock_alloc \ 7652280eacSKevin Wolf \ 7752280eacSKevin Wolf cluster_alloc \ 7852280eacSKevin Wolf 7952280eacSKevin Wolfdo 8052280eacSKevin Wolf 8152280eacSKevin Wolffor errno in 5 28; do 8252280eacSKevin Wolffor imm in off; do 8352280eacSKevin Wolffor once in on off; do 8452280eacSKevin Wolffor vmstate in "" "-b"; do 8552280eacSKevin Wolf 86fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF 8752280eacSKevin Wolf[inject-error] 8852280eacSKevin Wolfevent = "$event" 8952280eacSKevin Wolferrno = "$errno" 9052280eacSKevin Wolfimmediately = "$imm" 9152280eacSKevin Wolfonce ="$once" 9252280eacSKevin WolfEOF 9352280eacSKevin Wolf 9452280eacSKevin Wolf_make_test_img 1G 9552280eacSKevin Wolf 9652280eacSKevin Wolfecho 9752280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate" 9892ab69b6SKevin Wolf 9992ab69b6SKevin Wolf# We want to catch a simple L2 update, not the allocation of the first L2 table 10092ab69b6SKevin Wolfif [ "$event" == "l2_update" ]; then 101fef9c191SJeff Cody $QEMU_IO -c "write $vmstate 0 512" "$TEST_IMG" > /dev/null 2>&1 10292ab69b6SKevin Wolffi 10392ab69b6SKevin Wolf 104fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io 10552280eacSKevin Wolf 10652280eacSKevin Wolf# l2_load is not called on allocation, so issue a second write 10752280eacSKevin Wolf# Reads are another path to trigger l2_load, so do a read, too 10852280eacSKevin Wolfif [ "$event" == "l2_load" ]; then 109fef9c191SJeff Cody $QEMU_IO -c "write $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io 110fef9c191SJeff Cody $QEMU_IO -c "read $vmstate 0 128k " "$BLKDBG_TEST_IMG" | _filter_qemu_io 11152280eacSKevin Wolffi 11252280eacSKevin Wolf 113ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0" 11452280eacSKevin Wolf 11552280eacSKevin Wolfdone 11652280eacSKevin Wolfdone 11752280eacSKevin Wolfdone 11852280eacSKevin Wolfdone 11952280eacSKevin Wolfdone 12052280eacSKevin Wolf 12152280eacSKevin Wolf 12252280eacSKevin Wolfecho 12382481694SEric Blakeecho === Refcount table growth tests === 12452280eacSKevin Wolfecho 12552280eacSKevin WolfCLUSTER_SIZE=512 12652280eacSKevin Wolf 12752280eacSKevin Wolf 12852280eacSKevin Wolffor event in \ 1295be5b776SEric Blake refblock_alloc_hookup \ 1305be5b776SEric Blake refblock_alloc_write \ 1315be5b776SEric Blake refblock_alloc_write_blocks \ 1325be5b776SEric Blake refblock_alloc_write_table \ 1335be5b776SEric Blake refblock_alloc_switch_table \ 13452280eacSKevin Wolf 13552280eacSKevin Wolfdo 13652280eacSKevin Wolf 13752280eacSKevin Wolf# This one takes a while, so let's test only one error code (ENOSPC should 13852280eacSKevin Wolf# never be generated by qemu, so it's probably a good choice) 13952280eacSKevin Wolffor errno in 28; do 14052280eacSKevin Wolffor imm in off; do 14152280eacSKevin Wolffor once in on off; do 14252280eacSKevin Wolffor vmstate in "" "-b"; do 14352280eacSKevin Wolf 144fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF 14552280eacSKevin Wolf[inject-error] 14652280eacSKevin Wolfevent = "$event" 14752280eacSKevin Wolferrno = "$errno" 14852280eacSKevin Wolfimmediately = "$imm" 14952280eacSKevin Wolfonce = "$once" 15052280eacSKevin WolfEOF 15152280eacSKevin Wolf 15252280eacSKevin Wolf_make_test_img 1G 15352280eacSKevin Wolf 15452280eacSKevin Wolfecho 15552280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once; write $vmstate" 156fef9c191SJeff Cody$QEMU_IO -c "write $vmstate 0 64M" "$BLKDBG_TEST_IMG" | _filter_qemu_io 15752280eacSKevin Wolf 158ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0" 15952280eacSKevin Wolf 16052280eacSKevin Wolfdone 16152280eacSKevin Wolfdone 16252280eacSKevin Wolfdone 16352280eacSKevin Wolfdone 16452280eacSKevin Wolfdone 16552280eacSKevin Wolf 16652280eacSKevin Wolfecho 16752280eacSKevin Wolfecho === L1 growth tests === 16852280eacSKevin Wolfecho 16952280eacSKevin WolfCLUSTER_SIZE=1024 17052280eacSKevin Wolf 17152280eacSKevin Wolf 17252280eacSKevin Wolffor event in \ 1735be5b776SEric Blake l1_grow_alloc_table \ 1745be5b776SEric Blake l1_grow_write_table \ 1755be5b776SEric Blake l1_grow_activate_table \ 17652280eacSKevin Wolf 17752280eacSKevin Wolfdo 17852280eacSKevin Wolf 17952280eacSKevin Wolffor errno in 5 28; do 18052280eacSKevin Wolffor imm in off; do 18152280eacSKevin Wolffor once in on off; do 18252280eacSKevin Wolf 183fef9c191SJeff Codycat > "$TEST_DIR/blkdebug.conf" <<EOF 18452280eacSKevin Wolf[inject-error] 18552280eacSKevin Wolfevent = "$event" 18652280eacSKevin Wolferrno = "$errno" 18752280eacSKevin Wolfimmediately = "$imm" 18852280eacSKevin Wolfonce = "$once" 18952280eacSKevin WolfEOF 19052280eacSKevin Wolf 19152280eacSKevin Wolf_make_test_img 1G 19252280eacSKevin Wolf 19352280eacSKevin Wolfecho 19452280eacSKevin Wolfecho "Event: $event; errno: $errno; imm: $imm; once: $once" 195fef9c191SJeff Cody$QEMU_IO -c "write -b 0 64k" "$BLKDBG_TEST_IMG" | _filter_qemu_io 19652280eacSKevin Wolf 197ee1e66d9SVladimir Sementsov-Ogievskiy_check_test_img_ignore_leaks 2>&1 | grep -v "refcount=1 reference=0" 19852280eacSKevin Wolf 19952280eacSKevin Wolfdone 20052280eacSKevin Wolfdone 20152280eacSKevin Wolfdone 20252280eacSKevin Wolfdone 20352280eacSKevin Wolf 204ae376c62SKevin Wolfecho 205ae376c62SKevin Wolfecho === Avoid cluster leaks after temporary failure === 206ae376c62SKevin Wolfecho 207ae376c62SKevin Wolf 208ae376c62SKevin Wolfcat > "$TEST_DIR/blkdebug.conf" <<EOF 209ae376c62SKevin Wolf[inject-error] 210ae376c62SKevin Wolfevent = "write_aio" 211ae376c62SKevin Wolferrno = "5" 212ae376c62SKevin Wolfonce = "on" 213ae376c62SKevin WolfEOF 214ae376c62SKevin Wolf 215ae376c62SKevin Wolf# After the failed first write, do a second write so that the updated refcount 216ae376c62SKevin Wolf# block is actually written back 217ae376c62SKevin Wolf_make_test_img 64M 218ae376c62SKevin Wolf$QEMU_IO -c "write 0 1M" -c "write 0 1M" "$BLKDBG_TEST_IMG" | _filter_qemu_io 219ae376c62SKevin Wolf_check_test_img 220ae376c62SKevin Wolf 22152280eacSKevin Wolf# success, all done 22252280eacSKevin Wolfecho "*** done" 22352280eacSKevin Wolfrm -f $seq.full 22452280eacSKevin Wolfstatus=0 225