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