xref: /openbmc/qemu/tests/qemu-iotests/229 (revision 2055dbc1)
1#!/usr/bin/env bash
2#
3# Test for force canceling a running blockjob that is paused in
4# an error state.
5#
6# Copyright (C) 2018 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=jcody@redhat.com
24
25seq="$(basename $0)"
26echo "QA output created by $seq"
27
28status=1	# failure is the default!
29
30_cleanup()
31{
32    _cleanup_qemu
33    _cleanup_test_img
34    _rm_test_img "$TEST_IMG"
35    _rm_test_img "$DEST_IMG"
36    rm -f "$TEST_DIR/blkdebug.conf"
37}
38trap "_cleanup; exit \$status" 0 1 2 3 15
39
40# get standard environment, filters and checks
41. ./common.rc
42. ./common.filter
43. ./common.qemu
44
45# Needs backing file and backing format support
46_supported_fmt qcow2 qed
47_supported_proto file
48_supported_os Linux
49# blkdebug can only inject errors on bs->file, so external data files
50# do not work with this test
51_unsupported_imgopts data_file
52
53
54DEST_IMG="$TEST_DIR/d.$IMGFMT"
55TEST_IMG="$TEST_DIR/b.$IMGFMT"
56BLKDEBUG_CONF="$TEST_DIR/blkdebug.conf"
57
58_make_test_img 2M
59TEST_IMG=$DEST_IMG _make_test_img 2M
60
61$QEMU_IO -c 'write 0 2M' "$TEST_IMG" | _filter_qemu_io
62
63_launch_qemu -drive id=testdisk,file="$TEST_IMG",format="$IMGFMT"
64
65_send_qemu_cmd $QEMU_HANDLE \
66    "{'execute': 'qmp_capabilities'}" \
67    'return'
68
69echo
70echo '=== Starting drive-mirror, causing error & stop  ==='
71echo
72
73cat > "$BLKDEBUG_CONF" <<EOF
74[inject-error]
75event = "write_aio"
76errno = "5"
77once = "on"
78EOF
79
80_send_qemu_cmd $QEMU_HANDLE \
81    "{'execute': 'drive-mirror',
82                 'arguments': {'device': 'testdisk',
83                               'format': '$IMGFMT',
84                               'target': 'blkdebug:$BLKDEBUG_CONF:$DEST_IMG',
85                               'sync':   'full',
86                               'mode':   'existing',
87                               'on-source-error': 'stop',
88                               'on-target-error': 'stop' }}"    \
89     "JOB_STATUS_CHANGE.*pause"
90
91echo
92echo '=== Force cancel job paused in error state  ==='
93echo
94
95# Filter out BLOCK_JOB_ERROR events because they may or may not occur.
96# Cancelling the job means resuming it for a bit before it is actually
97# aborted, and in that time it may or may not re-encounter the error.
98success_or_failure="y" _send_qemu_cmd $QEMU_HANDLE \
99    "{'execute': 'block-job-cancel',
100                 'arguments': { 'device': 'testdisk',
101                                'force': true}}" \
102     "BLOCK_JOB_CANCELLED" "Assertion" \
103    | grep -v '"BLOCK_JOB_ERROR"' \
104    | _filter_block_job_offset
105
106# success, all done
107echo "*** done"
108rm -f $seq.full
109status=0
110