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