111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 226bf474bSJeff Cody# 326bf474bSJeff Cody# Test for force canceling a running blockjob that is paused in 426bf474bSJeff Cody# an error state. 526bf474bSJeff Cody# 626bf474bSJeff Cody# Copyright (C) 2018 Red Hat, Inc. 726bf474bSJeff Cody# 826bf474bSJeff Cody# This program is free software; you can redistribute it and/or modify 926bf474bSJeff Cody# it under the terms of the GNU General Public License as published by 1026bf474bSJeff Cody# the Free Software Foundation; either version 2 of the License, or 1126bf474bSJeff Cody# (at your option) any later version. 1226bf474bSJeff Cody# 1326bf474bSJeff Cody# This program is distributed in the hope that it will be useful, 1426bf474bSJeff Cody# but WITHOUT ANY WARRANTY; without even the implied warranty of 1526bf474bSJeff Cody# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1626bf474bSJeff Cody# GNU General Public License for more details. 1726bf474bSJeff Cody# 1826bf474bSJeff Cody# You should have received a copy of the GNU General Public License 1926bf474bSJeff Cody# along with this program. If not, see <http://www.gnu.org/licenses/>. 2026bf474bSJeff Cody# 2126bf474bSJeff Cody 2226bf474bSJeff Cody# creator 2326bf474bSJeff Codyowner=jcody@redhat.com 2426bf474bSJeff Cody 2526bf474bSJeff Codyseq="$(basename $0)" 2626bf474bSJeff Codyecho "QA output created by $seq" 2726bf474bSJeff Cody 2826bf474bSJeff Codystatus=1 # failure is the default! 2926bf474bSJeff Cody 3026bf474bSJeff Cody_cleanup() 3126bf474bSJeff Cody{ 3226bf474bSJeff Cody _cleanup_qemu 3326bf474bSJeff Cody _cleanup_test_img 34f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG" 35f91ecbd7SMax Reitz _rm_test_img "$DEST_IMG" 36d89ac3cfSKevin Wolf rm -f "$TEST_DIR/blkdebug.conf" 3726bf474bSJeff Cody} 3826bf474bSJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15 3926bf474bSJeff Cody 4026bf474bSJeff Cody# get standard environment, filters and checks 4126bf474bSJeff Cody. ./common.rc 4226bf474bSJeff Cody. ./common.filter 4326bf474bSJeff Cody. ./common.qemu 4426bf474bSJeff Cody 4526bf474bSJeff Cody# Needs backing file and backing format support 4626bf474bSJeff Cody_supported_fmt qcow2 qed 4726bf474bSJeff Cody_supported_proto file 4826bf474bSJeff Cody_supported_os Linux 4973b2b7b5SMax Reitz# blkdebug can only inject errors on bs->file, so external data files 5073b2b7b5SMax Reitz# do not work with this test 5173b2b7b5SMax Reitz_unsupported_imgopts data_file 5226bf474bSJeff Cody 5326bf474bSJeff Cody 54*4c36f030SMax ReitzDEST_IMG="$TEST_IMG.dest" 55d89ac3cfSKevin WolfBLKDEBUG_CONF="$TEST_DIR/blkdebug.conf" 5626bf474bSJeff Cody 5726bf474bSJeff Cody_make_test_img 2M 58d89ac3cfSKevin WolfTEST_IMG=$DEST_IMG _make_test_img 2M 5926bf474bSJeff Cody 6026bf474bSJeff Cody$QEMU_IO -c 'write 0 2M' "$TEST_IMG" | _filter_qemu_io 6126bf474bSJeff Cody 6226bf474bSJeff Cody_launch_qemu -drive id=testdisk,file="$TEST_IMG",format="$IMGFMT" 6326bf474bSJeff Cody 6426bf474bSJeff Cody_send_qemu_cmd $QEMU_HANDLE \ 6526bf474bSJeff Cody "{'execute': 'qmp_capabilities'}" \ 6626bf474bSJeff Cody 'return' 6726bf474bSJeff Cody 6826bf474bSJeff Codyecho 6926bf474bSJeff Codyecho '=== Starting drive-mirror, causing error & stop ===' 7026bf474bSJeff Codyecho 7126bf474bSJeff Cody 72d89ac3cfSKevin Wolfcat > "$BLKDEBUG_CONF" <<EOF 73d89ac3cfSKevin Wolf[inject-error] 74d89ac3cfSKevin Wolfevent = "write_aio" 75d89ac3cfSKevin Wolferrno = "5" 76d89ac3cfSKevin Wolfonce = "on" 77d89ac3cfSKevin WolfEOF 78d89ac3cfSKevin Wolf 7926bf474bSJeff Cody_send_qemu_cmd $QEMU_HANDLE \ 8026bf474bSJeff Cody "{'execute': 'drive-mirror', 8126bf474bSJeff Cody 'arguments': {'device': 'testdisk', 8226bf474bSJeff Cody 'format': '$IMGFMT', 83d89ac3cfSKevin Wolf 'target': 'blkdebug:$BLKDEBUG_CONF:$DEST_IMG', 8426bf474bSJeff Cody 'sync': 'full', 8526bf474bSJeff Cody 'mode': 'existing', 8626bf474bSJeff Cody 'on-source-error': 'stop', 8726bf474bSJeff Cody 'on-target-error': 'stop' }}" \ 8826bf474bSJeff Cody "JOB_STATUS_CHANGE.*pause" 8926bf474bSJeff Cody 9026bf474bSJeff Codyecho 9126bf474bSJeff Codyecho '=== Force cancel job paused in error state ===' 9226bf474bSJeff Codyecho 9326bf474bSJeff Cody 94fff2388dSMax Reitz# Filter out BLOCK_JOB_ERROR events because they may or may not occur. 95fff2388dSMax Reitz# Cancelling the job means resuming it for a bit before it is actually 96fff2388dSMax Reitz# aborted, and in that time it may or may not re-encounter the error. 9726bf474bSJeff Codysuccess_or_failure="y" _send_qemu_cmd $QEMU_HANDLE \ 9826bf474bSJeff Cody "{'execute': 'block-job-cancel', 9926bf474bSJeff Cody 'arguments': { 'device': 'testdisk', 10026bf474bSJeff Cody 'force': true}}" \ 101fff2388dSMax Reitz "BLOCK_JOB_CANCELLED" "Assertion" \ 102d89ac3cfSKevin Wolf | grep -v '"BLOCK_JOB_ERROR"' \ 103d89ac3cfSKevin Wolf | _filter_block_job_offset 10426bf474bSJeff Cody 10526bf474bSJeff Cody# success, all done 10626bf474bSJeff Codyecho "*** done" 10726bf474bSJeff Codyrm -f $seq.full 10826bf474bSJeff Codystatus=0 109