126bf474bSJeff Cody#!/bin/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 3426bf474bSJeff Cody rm -f "$TEST_IMG" "$DEST_IMG" 3526bf474bSJeff Cody} 3626bf474bSJeff Codytrap "_cleanup; exit \$status" 0 1 2 3 15 3726bf474bSJeff Cody 3826bf474bSJeff Cody# get standard environment, filters and checks 3926bf474bSJeff Cody. ./common.rc 4026bf474bSJeff Cody. ./common.filter 4126bf474bSJeff Cody. ./common.qemu 4226bf474bSJeff Cody 4326bf474bSJeff Cody# Needs backing file and backing format support 4426bf474bSJeff Cody_supported_fmt qcow2 qed 4526bf474bSJeff Cody_supported_proto file 4626bf474bSJeff Cody_supported_os Linux 4726bf474bSJeff Cody 4826bf474bSJeff Cody 4926bf474bSJeff CodyDEST_IMG="$TEST_DIR/d.$IMGFMT" 5026bf474bSJeff CodyTEST_IMG="$TEST_DIR/b.$IMGFMT" 5126bf474bSJeff Cody 5226bf474bSJeff Cody_make_test_img 2M 5326bf474bSJeff Cody 5426bf474bSJeff Cody# destination for mirror will be too small, causing error 5526bf474bSJeff CodyTEST_IMG=$DEST_IMG _make_test_img 1M 5626bf474bSJeff Cody 5726bf474bSJeff Cody$QEMU_IO -c 'write 0 2M' "$TEST_IMG" | _filter_qemu_io 5826bf474bSJeff Cody 5926bf474bSJeff Cody_launch_qemu -drive id=testdisk,file="$TEST_IMG",format="$IMGFMT" 6026bf474bSJeff Cody 6126bf474bSJeff Cody_send_qemu_cmd $QEMU_HANDLE \ 6226bf474bSJeff Cody "{'execute': 'qmp_capabilities'}" \ 6326bf474bSJeff Cody 'return' 6426bf474bSJeff Cody 6526bf474bSJeff Codyecho 6626bf474bSJeff Codyecho '=== Starting drive-mirror, causing error & stop ===' 6726bf474bSJeff Codyecho 6826bf474bSJeff Cody 6926bf474bSJeff Cody_send_qemu_cmd $QEMU_HANDLE \ 7026bf474bSJeff Cody "{'execute': 'drive-mirror', 7126bf474bSJeff Cody 'arguments': {'device': 'testdisk', 7226bf474bSJeff Cody 'format': '$IMGFMT', 7326bf474bSJeff Cody 'target': '$DEST_IMG', 7426bf474bSJeff Cody 'sync': 'full', 7526bf474bSJeff Cody 'mode': 'existing', 7626bf474bSJeff Cody 'on-source-error': 'stop', 7726bf474bSJeff Cody 'on-target-error': 'stop' }}" \ 7826bf474bSJeff Cody "JOB_STATUS_CHANGE.*pause" 7926bf474bSJeff Cody 8026bf474bSJeff Codyecho 8126bf474bSJeff Codyecho '=== Force cancel job paused in error state ===' 8226bf474bSJeff Codyecho 8326bf474bSJeff Cody 84*fff2388dSMax Reitz# Filter out BLOCK_JOB_ERROR events because they may or may not occur. 85*fff2388dSMax Reitz# Cancelling the job means resuming it for a bit before it is actually 86*fff2388dSMax Reitz# aborted, and in that time it may or may not re-encounter the error. 8726bf474bSJeff Codysuccess_or_failure="y" _send_qemu_cmd $QEMU_HANDLE \ 8826bf474bSJeff Cody "{'execute': 'block-job-cancel', 8926bf474bSJeff Cody 'arguments': { 'device': 'testdisk', 9026bf474bSJeff Cody 'force': true}}" \ 91*fff2388dSMax Reitz "BLOCK_JOB_CANCELLED" "Assertion" \ 92*fff2388dSMax Reitz | grep -v '"BLOCK_JOB_ERROR"' 9326bf474bSJeff Cody 9426bf474bSJeff Cody# success, all done 9526bf474bSJeff Codyecho "*** done" 9626bf474bSJeff Codyrm -f $seq.full 9726bf474bSJeff Codystatus=0 98