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