1*c264e5d2SMax Reitz#!/usr/bin/env bash 2*c264e5d2SMax Reitz# 3*c264e5d2SMax Reitz# qcow2 v3-exclusive error path testing 4*c264e5d2SMax Reitz# (026 tests paths common to v2 and v3) 5*c264e5d2SMax Reitz# 6*c264e5d2SMax Reitz# Copyright (C) 2020 Red Hat, Inc. 7*c264e5d2SMax Reitz# 8*c264e5d2SMax Reitz# This program is free software; you can redistribute it and/or modify 9*c264e5d2SMax Reitz# it under the terms of the GNU General Public License as published by 10*c264e5d2SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11*c264e5d2SMax Reitz# (at your option) any later version. 12*c264e5d2SMax Reitz# 13*c264e5d2SMax Reitz# This program is distributed in the hope that it will be useful, 14*c264e5d2SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*c264e5d2SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*c264e5d2SMax Reitz# GNU General Public License for more details. 17*c264e5d2SMax Reitz# 18*c264e5d2SMax Reitz# You should have received a copy of the GNU General Public License 19*c264e5d2SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*c264e5d2SMax Reitz# 21*c264e5d2SMax Reitz 22*c264e5d2SMax Reitzseq=$(basename $0) 23*c264e5d2SMax Reitzecho "QA output created by $seq" 24*c264e5d2SMax Reitz 25*c264e5d2SMax Reitzstatus=1 # failure is the default! 26*c264e5d2SMax Reitz 27*c264e5d2SMax Reitz_cleanup() 28*c264e5d2SMax Reitz{ 29*c264e5d2SMax Reitz _cleanup_test_img 30*c264e5d2SMax Reitz rm "$TEST_DIR/blkdebug.conf" 31*c264e5d2SMax Reitz rm -f "$TEST_IMG.data_file" 32*c264e5d2SMax Reitz} 33*c264e5d2SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 34*c264e5d2SMax Reitz 35*c264e5d2SMax Reitz# get standard environment, filters and checks 36*c264e5d2SMax Reitz. ./common.rc 37*c264e5d2SMax Reitz. ./common.filter 38*c264e5d2SMax Reitz. ./common.pattern 39*c264e5d2SMax Reitz 40*c264e5d2SMax Reitz_supported_fmt qcow2 41*c264e5d2SMax Reitz_supported_proto file 42*c264e5d2SMax Reitz# This is a v3-exclusive test; 43*c264e5d2SMax Reitz# As for data_file, error paths often very much depend on whether 44*c264e5d2SMax Reitz# there is an external data file or not; so we create one exactly when 45*c264e5d2SMax Reitz# we want to test it 46*c264e5d2SMax Reitz_unsupported_imgopts 'compat=0.10' data_file 47*c264e5d2SMax Reitz 48*c264e5d2SMax Reitzecho 49*c264e5d2SMax Reitzecho === Avoid freeing external data clusters on failure === 50*c264e5d2SMax Reitzecho 51*c264e5d2SMax Reitz 52*c264e5d2SMax Reitzcat > "$TEST_DIR/blkdebug.conf" <<EOF 53*c264e5d2SMax Reitz[inject-error] 54*c264e5d2SMax Reitzevent = "write_aio" 55*c264e5d2SMax Reitzerrno = "5" 56*c264e5d2SMax Reitzonce = "on" 57*c264e5d2SMax ReitzEOF 58*c264e5d2SMax Reitz 59*c264e5d2SMax Reitz# Test what happens when there is an error when writing to an external 60*c264e5d2SMax Reitz# data file instead of when writing to a preallocated zero cluster 61*c264e5d2SMax Reitz_make_test_img -o "data_file=$TEST_IMG.data_file" 64k 62*c264e5d2SMax Reitz 63*c264e5d2SMax Reitz# Put blkdebug above the data-file, and a raw node on top of that so 64*c264e5d2SMax Reitz# that blkdebug will see a write_aio event and emit an error. This 65*c264e5d2SMax Reitz# will then trigger the alloc abort code, which we want to test here. 66*c264e5d2SMax Reitz$QEMU_IO -c "write 0 64k" \ 67*c264e5d2SMax Reitz "json:{ 68*c264e5d2SMax Reitz 'driver': 'qcow2', 69*c264e5d2SMax Reitz 'file': { 'driver': 'file', 'filename': '$TEST_IMG' }, 70*c264e5d2SMax Reitz 'data-file': { 71*c264e5d2SMax Reitz 'driver': 'raw', 72*c264e5d2SMax Reitz 'file': { 73*c264e5d2SMax Reitz 'driver': 'blkdebug', 74*c264e5d2SMax Reitz 'config': '$TEST_DIR/blkdebug.conf', 75*c264e5d2SMax Reitz 'image': { 76*c264e5d2SMax Reitz 'driver': 'file', 77*c264e5d2SMax Reitz 'filename': '$TEST_IMG.data_file' 78*c264e5d2SMax Reitz } 79*c264e5d2SMax Reitz } 80*c264e5d2SMax Reitz } 81*c264e5d2SMax Reitz }" \ 82*c264e5d2SMax Reitz | _filter_qemu_io 83*c264e5d2SMax Reitz 84*c264e5d2SMax Reitz_check_test_img 85*c264e5d2SMax Reitz 86*c264e5d2SMax Reitz# success, all done 87*c264e5d2SMax Reitzecho "*** done" 88*c264e5d2SMax Reitzrm -f $seq.full 89*c264e5d2SMax Reitzstatus=0 90