xref: /openbmc/qemu/tests/qemu-iotests/229 (revision d89ac3cf305b28c024a76805a84d75c0ee1e786f)
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"
36*d89ac3cfSKevin 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
4926bf474bSJeff Cody
5026bf474bSJeff Cody
5126bf474bSJeff CodyDEST_IMG="$TEST_DIR/d.$IMGFMT"
5226bf474bSJeff CodyTEST_IMG="$TEST_DIR/b.$IMGFMT"
53*d89ac3cfSKevin WolfBLKDEBUG_CONF="$TEST_DIR/blkdebug.conf"
5426bf474bSJeff Cody
5526bf474bSJeff Cody_make_test_img 2M
56*d89ac3cfSKevin WolfTEST_IMG=$DEST_IMG _make_test_img 2M
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
70*d89ac3cfSKevin Wolfcat > "$BLKDEBUG_CONF" <<EOF
71*d89ac3cfSKevin Wolf[inject-error]
72*d89ac3cfSKevin Wolfevent = "write_aio"
73*d89ac3cfSKevin Wolferrno = "5"
74*d89ac3cfSKevin Wolfonce = "on"
75*d89ac3cfSKevin WolfEOF
76*d89ac3cfSKevin Wolf
7726bf474bSJeff Cody_send_qemu_cmd $QEMU_HANDLE \
7826bf474bSJeff Cody    "{'execute': 'drive-mirror',
7926bf474bSJeff Cody                 'arguments': {'device': 'testdisk',
8026bf474bSJeff Cody                               'format': '$IMGFMT',
81*d89ac3cfSKevin Wolf                               'target': 'blkdebug:$BLKDEBUG_CONF:$DEST_IMG',
8226bf474bSJeff Cody                               'sync':   'full',
8326bf474bSJeff Cody                               'mode':   'existing',
8426bf474bSJeff Cody                               'on-source-error': 'stop',
8526bf474bSJeff Cody                               'on-target-error': 'stop' }}"    \
8626bf474bSJeff Cody     "JOB_STATUS_CHANGE.*pause"
8726bf474bSJeff Cody
8826bf474bSJeff Codyecho
8926bf474bSJeff Codyecho '=== Force cancel job paused in error state  ==='
9026bf474bSJeff Codyecho
9126bf474bSJeff Cody
92fff2388dSMax Reitz# Filter out BLOCK_JOB_ERROR events because they may or may not occur.
93fff2388dSMax Reitz# Cancelling the job means resuming it for a bit before it is actually
94fff2388dSMax Reitz# aborted, and in that time it may or may not re-encounter the error.
9526bf474bSJeff Codysuccess_or_failure="y" _send_qemu_cmd $QEMU_HANDLE \
9626bf474bSJeff Cody    "{'execute': 'block-job-cancel',
9726bf474bSJeff Cody                 'arguments': { 'device': 'testdisk',
9826bf474bSJeff Cody                                'force': true}}" \
99fff2388dSMax Reitz     "BLOCK_JOB_CANCELLED" "Assertion" \
100*d89ac3cfSKevin Wolf    | grep -v '"BLOCK_JOB_ERROR"' \
101*d89ac3cfSKevin Wolf    | _filter_block_job_offset
10226bf474bSJeff Cody
10326bf474bSJeff Cody# success, all done
10426bf474bSJeff Codyecho "*** done"
10526bf474bSJeff Codyrm -f $seq.full
10626bf474bSJeff Codystatus=0
107