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