4 # Test case for ejecting BDSs with block jobs still running on them
6 # Copyright (C) 2016 Red Hat, Inc.
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.
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.
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/>.
23 owner=hreitz@redhat.com
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
34 for img in "$TEST_DIR"/{b,m,o}.$IMGFMT; do
38 trap "_cleanup; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
45 # Needs backing file and backing format support
46 _supported_fmt qcow2 qed
53 _send_qemu_cmd $QEMU_HANDLE \
54 "{'execute': 'blockdev-add',
60 'filename': '$TEST_IMG'
64 # If "$2" is an event, we may or may not see it before the
65 # {"return": {}}. Therefore, filter the {"return": {}} out both
66 # here and in the next command. (Naturally, if we do not see it
67 # here, we will see it before the next command can be executed,
68 # so it will appear in the next _send_qemu_cmd's output.)
69 _send_qemu_cmd $QEMU_HANDLE \
72 | _filter_img_create | _filter_qmp_empty_return
74 # We want this to return an error because the block job is still running
75 _send_qemu_cmd $QEMU_HANDLE \
76 "{'execute': 'blockdev-del',
77 'arguments': {'node-name': 'drv0'}}" \
78 'error' | _filter_generated_node_ids | _filter_qmp_empty_return
80 _send_qemu_cmd $QEMU_HANDLE \
81 "{'execute': 'block-job-cancel',
82 'arguments': {'device': 'job0'}}" \
85 _send_qemu_cmd $QEMU_HANDLE \
86 "{'execute': 'blockdev-del',
87 'arguments': {'node-name': 'drv0'}}" \
92 TEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M
93 TEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" -F $IMGFMT 1M
94 _make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M -F $IMGFMT
96 _launch_qemu -nodefaults
98 _send_qemu_cmd $QEMU_HANDLE \
99 "{'execute': 'qmp_capabilities'}" \
103 echo '=== Testing drive-backup ==='
106 # drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job
107 # will consequently result in BLOCK_JOB_CANCELLED being emitted.
110 "{'execute': 'drive-backup',
111 'arguments': {'job-id': 'job0',
113 'target': '$TEST_DIR/o.$IMGFMT',
120 echo '=== Testing drive-mirror ==='
123 # drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling
124 # the job will consequently result in BLOCK_JOB_COMPLETED being emitted.
127 "{'execute': 'drive-mirror',
128 'arguments': {'job-id': 'job0',
130 'target': '$TEST_DIR/o.$IMGFMT',
137 echo '=== Testing active block-commit ==='
140 # An active block-commit will send BLOCK_JOB_READY basically immediately, and
141 # cancelling the job will consequently result in BLOCK_JOB_COMPLETED being
145 "{'execute': 'block-commit',
146 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \
151 echo '=== Testing non-active block-commit ==='
154 # Give block-commit something to work on, otherwise it would be done
155 # immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
156 # fine without the block job still running.
158 $QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io
161 "{'execute': 'block-commit',
162 'arguments': {'job-id': 'job0',
164 'top': '$TEST_DIR/m.$IMGFMT',
170 echo '=== Testing block-stream ==='
173 # Give block-stream something to work on, otherwise it would be done
174 # immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
175 # fine without the block job still running.
177 $QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io
179 # With some data to stream (and @speed set to 1), block-stream will not complete
180 # until we send the block-job-cancel command.
183 "{'execute': 'block-stream',
184 'arguments': {'job-id': 'job0',