xref: /openbmc/qemu/tests/qemu-iotests/141 (revision c78dc182)
1*c78dc182SMax Reitz#!/bin/bash
2*c78dc182SMax Reitz#
3*c78dc182SMax Reitz# Test case for ejecting BDSs with block jobs still running on them
4*c78dc182SMax Reitz#
5*c78dc182SMax Reitz# Copyright (C) 2016 Red Hat, Inc.
6*c78dc182SMax Reitz#
7*c78dc182SMax Reitz# This program is free software; you can redistribute it and/or modify
8*c78dc182SMax Reitz# it under the terms of the GNU General Public License as published by
9*c78dc182SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*c78dc182SMax Reitz# (at your option) any later version.
11*c78dc182SMax Reitz#
12*c78dc182SMax Reitz# This program is distributed in the hope that it will be useful,
13*c78dc182SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c78dc182SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c78dc182SMax Reitz# GNU General Public License for more details.
16*c78dc182SMax Reitz#
17*c78dc182SMax Reitz# You should have received a copy of the GNU General Public License
18*c78dc182SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*c78dc182SMax Reitz#
20*c78dc182SMax Reitz
21*c78dc182SMax Reitz# creator
22*c78dc182SMax Reitzowner=mreitz@redhat.com
23*c78dc182SMax Reitz
24*c78dc182SMax Reitzseq="$(basename $0)"
25*c78dc182SMax Reitzecho "QA output created by $seq"
26*c78dc182SMax Reitz
27*c78dc182SMax Reitzhere="$PWD"
28*c78dc182SMax Reitztmp=/tmp/$$
29*c78dc182SMax Reitzstatus=1	# failure is the default!
30*c78dc182SMax Reitz
31*c78dc182SMax Reitz_cleanup()
32*c78dc182SMax Reitz{
33*c78dc182SMax Reitz    _cleanup_test_img
34*c78dc182SMax Reitz    rm -f "$TEST_DIR/{b,m,o}.$IMGFMT"
35*c78dc182SMax Reitz}
36*c78dc182SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
37*c78dc182SMax Reitz
38*c78dc182SMax Reitz# get standard environment, filters and checks
39*c78dc182SMax Reitz. ./common.rc
40*c78dc182SMax Reitz. ./common.filter
41*c78dc182SMax Reitz. ./common.qemu
42*c78dc182SMax Reitz
43*c78dc182SMax Reitz# Needs backing file and backing format support
44*c78dc182SMax Reitz_supported_fmt qcow2 qed
45*c78dc182SMax Reitz_supported_proto file
46*c78dc182SMax Reitz_supported_os Linux
47*c78dc182SMax Reitz
48*c78dc182SMax Reitz
49*c78dc182SMax Reitztest_blockjob()
50*c78dc182SMax Reitz{
51*c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
52*c78dc182SMax Reitz        "{'execute': 'blockdev-add',
53*c78dc182SMax Reitz          'arguments': {
54*c78dc182SMax Reitz              'options': {
55*c78dc182SMax Reitz                  'id': 'drv0',
56*c78dc182SMax Reitz                  'driver': '$IMGFMT',
57*c78dc182SMax Reitz                  'file': {
58*c78dc182SMax Reitz                      'driver': 'file',
59*c78dc182SMax Reitz                      'filename': '$TEST_IMG'
60*c78dc182SMax Reitz                  }}}}" \
61*c78dc182SMax Reitz        'return'
62*c78dc182SMax Reitz
63*c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
64*c78dc182SMax Reitz        "$1" \
65*c78dc182SMax Reitz        "$2" \
66*c78dc182SMax Reitz        | _filter_img_create
67*c78dc182SMax Reitz
68*c78dc182SMax Reitz    # We want this to return an error because the block job is still running
69*c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
70*c78dc182SMax Reitz        "{'execute': 'x-blockdev-remove-medium',
71*c78dc182SMax Reitz          'arguments': {'device': 'drv0'}}" \
72*c78dc182SMax Reitz        'error'
73*c78dc182SMax Reitz
74*c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
75*c78dc182SMax Reitz        "{'execute': 'block-job-cancel',
76*c78dc182SMax Reitz          'arguments': {'device': 'drv0'}}" \
77*c78dc182SMax Reitz        "$3"
78*c78dc182SMax Reitz
79*c78dc182SMax Reitz    _send_qemu_cmd $QEMU_HANDLE \
80*c78dc182SMax Reitz        "{'execute': 'x-blockdev-del',
81*c78dc182SMax Reitz          'arguments': {'id': 'drv0'}}" \
82*c78dc182SMax Reitz        'return'
83*c78dc182SMax Reitz}
84*c78dc182SMax Reitz
85*c78dc182SMax Reitz
86*c78dc182SMax ReitzTEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M
87*c78dc182SMax ReitzTEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" 1M
88*c78dc182SMax Reitz_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M
89*c78dc182SMax Reitz
90*c78dc182SMax Reitz_launch_qemu -nodefaults
91*c78dc182SMax Reitz
92*c78dc182SMax Reitz_send_qemu_cmd $QEMU_HANDLE \
93*c78dc182SMax Reitz    "{'execute': 'qmp_capabilities'}" \
94*c78dc182SMax Reitz    'return'
95*c78dc182SMax Reitz
96*c78dc182SMax Reitzecho
97*c78dc182SMax Reitzecho '=== Testing drive-backup ==='
98*c78dc182SMax Reitzecho
99*c78dc182SMax Reitz
100*c78dc182SMax Reitz# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job
101*c78dc182SMax Reitz# will consequently result in BLOCK_JOB_CANCELLED being emitted.
102*c78dc182SMax Reitz
103*c78dc182SMax Reitztest_blockjob \
104*c78dc182SMax Reitz    "{'execute': 'drive-backup',
105*c78dc182SMax Reitz      'arguments': {'device': 'drv0',
106*c78dc182SMax Reitz                    'target': '$TEST_DIR/o.$IMGFMT',
107*c78dc182SMax Reitz                    'format': '$IMGFMT',
108*c78dc182SMax Reitz                    'sync': 'none'}}" \
109*c78dc182SMax Reitz    'return' \
110*c78dc182SMax Reitz    'BLOCK_JOB_CANCELLED'
111*c78dc182SMax Reitz
112*c78dc182SMax Reitzecho
113*c78dc182SMax Reitzecho '=== Testing drive-mirror ==='
114*c78dc182SMax Reitzecho
115*c78dc182SMax Reitz
116*c78dc182SMax Reitz# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling
117*c78dc182SMax Reitz# the job will consequently result in BLOCK_JOB_COMPLETED being emitted.
118*c78dc182SMax Reitz
119*c78dc182SMax Reitztest_blockjob \
120*c78dc182SMax Reitz    "{'execute': 'drive-mirror',
121*c78dc182SMax Reitz      'arguments': {'device': 'drv0',
122*c78dc182SMax Reitz                    'target': '$TEST_DIR/o.$IMGFMT',
123*c78dc182SMax Reitz                    'format': '$IMGFMT',
124*c78dc182SMax Reitz                    'sync': 'none'}}" \
125*c78dc182SMax Reitz    'BLOCK_JOB_READY' \
126*c78dc182SMax Reitz    'BLOCK_JOB_COMPLETED'
127*c78dc182SMax Reitz
128*c78dc182SMax Reitzecho
129*c78dc182SMax Reitzecho '=== Testing active block-commit ==='
130*c78dc182SMax Reitzecho
131*c78dc182SMax Reitz
132*c78dc182SMax Reitz# An active block-commit will send BLOCK_JOB_READY basically immediately, and
133*c78dc182SMax Reitz# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being
134*c78dc182SMax Reitz# emitted.
135*c78dc182SMax Reitz
136*c78dc182SMax Reitztest_blockjob \
137*c78dc182SMax Reitz    "{'execute': 'block-commit',
138*c78dc182SMax Reitz      'arguments': {'device': 'drv0'}}" \
139*c78dc182SMax Reitz    'BLOCK_JOB_READY' \
140*c78dc182SMax Reitz    'BLOCK_JOB_COMPLETED'
141*c78dc182SMax Reitz
142*c78dc182SMax Reitzecho
143*c78dc182SMax Reitzecho '=== Testing non-active block-commit ==='
144*c78dc182SMax Reitzecho
145*c78dc182SMax Reitz
146*c78dc182SMax Reitz# Give block-commit something to work on, otherwise it would be done
147*c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
148*c78dc182SMax Reitz# fine without the block job still running.
149*c78dc182SMax Reitz
150*c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io
151*c78dc182SMax Reitz
152*c78dc182SMax Reitztest_blockjob \
153*c78dc182SMax Reitz    "{'execute': 'block-commit',
154*c78dc182SMax Reitz      'arguments': {'device': 'drv0',
155*c78dc182SMax Reitz                    'top':    '$TEST_DIR/m.$IMGFMT',
156*c78dc182SMax Reitz                    'speed':  1}}" \
157*c78dc182SMax Reitz    'return' \
158*c78dc182SMax Reitz    'BLOCK_JOB_CANCELLED'
159*c78dc182SMax Reitz
160*c78dc182SMax Reitzecho
161*c78dc182SMax Reitzecho '=== Testing block-stream ==='
162*c78dc182SMax Reitzecho
163*c78dc182SMax Reitz
164*c78dc182SMax Reitz# Give block-stream something to work on, otherwise it would be done
165*c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
166*c78dc182SMax Reitz# fine without the block job still running.
167*c78dc182SMax Reitz
168*c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io
169*c78dc182SMax Reitz
170*c78dc182SMax Reitz# With some data to stream (and @speed set to 1), block-stream will not complete
171*c78dc182SMax Reitz# until we send the block-job-cancel command. Therefore, no event other than
172*c78dc182SMax Reitz# BLOCK_JOB_CANCELLED will be emitted.
173*c78dc182SMax Reitz
174*c78dc182SMax Reitztest_blockjob \
175*c78dc182SMax Reitz    "{'execute': 'block-stream',
176*c78dc182SMax Reitz      'arguments': {'device': 'drv0',
177*c78dc182SMax Reitz                    'speed': 1}}" \
178*c78dc182SMax Reitz    'return' \
179*c78dc182SMax Reitz    'BLOCK_JOB_CANCELLED'
180*c78dc182SMax Reitz
181*c78dc182SMax Reitz_cleanup_qemu
182*c78dc182SMax Reitz
183*c78dc182SMax Reitz# success, all done
184*c78dc182SMax Reitzecho "*** done"
185*c78dc182SMax Reitzrm -f $seq.full
186*c78dc182SMax Reitzstatus=0
187