]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/141
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
[mirror_qemu.git] / tests / qemu-iotests / 141
CommitLineData
c78dc182
HR
1#!/bin/bash
2#
3# Test case for ejecting BDSs with block jobs still running on them
4#
5# Copyright (C) 2016 Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20
21# creator
22owner=mreitz@redhat.com
23
24seq="$(basename $0)"
25echo "QA output created by $seq"
26
27here="$PWD"
c78dc182
HR
28status=1 # failure is the default!
29
30_cleanup()
31{
ecfa1854 32 _cleanup_qemu
c78dc182 33 _cleanup_test_img
0a1505d5 34 rm -f "$TEST_DIR"/{b,m,o}.$IMGFMT
c78dc182
HR
35}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41. ./common.qemu
42
43# Needs backing file and backing format support
44_supported_fmt qcow2 qed
45_supported_proto file
46_supported_os Linux
47
48
49test_blockjob()
50{
51 _send_qemu_cmd $QEMU_HANDLE \
52 "{'execute': 'blockdev-add',
53 'arguments': {
0153d2f5
KW
54 'node-name': 'drv0',
55 'driver': '$IMGFMT',
56 'file': {
57 'driver': 'file',
58 'filename': '$TEST_IMG'
59 }}}" \
c78dc182
HR
60 'return'
61
62 _send_qemu_cmd $QEMU_HANDLE \
63 "$1" \
64 "$2" \
65 | _filter_img_create
66
67 # We want this to return an error because the block job is still running
68 _send_qemu_cmd $QEMU_HANDLE \
79b7a77e 69 "{'execute': 'blockdev-del',
78645881 70 'arguments': {'node-name': 'drv0'}}" \
4ef85a9c 71 'error' | _filter_generated_node_ids
c78dc182
HR
72
73 _send_qemu_cmd $QEMU_HANDLE \
74 "{'execute': 'block-job-cancel',
78645881 75 'arguments': {'device': 'job0'}}" \
c78dc182
HR
76 "$3"
77
78 _send_qemu_cmd $QEMU_HANDLE \
79b7a77e 79 "{'execute': 'blockdev-del',
78645881 80 'arguments': {'node-name': 'drv0'}}" \
c78dc182
HR
81 'return'
82}
83
84
85TEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M
86TEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" 1M
87_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M
88
89_launch_qemu -nodefaults
90
91_send_qemu_cmd $QEMU_HANDLE \
92 "{'execute': 'qmp_capabilities'}" \
93 'return'
94
95echo
96echo '=== Testing drive-backup ==='
97echo
98
99# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job
100# will consequently result in BLOCK_JOB_CANCELLED being emitted.
101
102test_blockjob \
103 "{'execute': 'drive-backup',
78645881
KW
104 'arguments': {'job-id': 'job0',
105 'device': 'drv0',
c78dc182
HR
106 'target': '$TEST_DIR/o.$IMGFMT',
107 'format': '$IMGFMT',
108 'sync': 'none'}}" \
109 'return' \
110 'BLOCK_JOB_CANCELLED'
111
112echo
113echo '=== Testing drive-mirror ==='
114echo
115
116# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling
117# the job will consequently result in BLOCK_JOB_COMPLETED being emitted.
118
119test_blockjob \
120 "{'execute': 'drive-mirror',
78645881
KW
121 'arguments': {'job-id': 'job0',
122 'device': 'drv0',
c78dc182
HR
123 'target': '$TEST_DIR/o.$IMGFMT',
124 'format': '$IMGFMT',
125 'sync': 'none'}}" \
126 'BLOCK_JOB_READY' \
127 'BLOCK_JOB_COMPLETED'
128
129echo
130echo '=== Testing active block-commit ==='
131echo
132
133# An active block-commit will send BLOCK_JOB_READY basically immediately, and
134# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being
135# emitted.
136
137test_blockjob \
138 "{'execute': 'block-commit',
78645881 139 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \
c78dc182
HR
140 'BLOCK_JOB_READY' \
141 'BLOCK_JOB_COMPLETED'
142
143echo
144echo '=== Testing non-active block-commit ==='
145echo
146
147# Give block-commit something to work on, otherwise it would be done
148# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
149# fine without the block job still running.
150
151$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io
152
153test_blockjob \
154 "{'execute': 'block-commit',
78645881
KW
155 'arguments': {'job-id': 'job0',
156 'device': 'drv0',
c78dc182
HR
157 'top': '$TEST_DIR/m.$IMGFMT',
158 'speed': 1}}" \
159 'return' \
160 'BLOCK_JOB_CANCELLED'
161
162echo
163echo '=== Testing block-stream ==='
164echo
165
166# Give block-stream something to work on, otherwise it would be done
167# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just
168# fine without the block job still running.
169
170$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io
171
172# With some data to stream (and @speed set to 1), block-stream will not complete
173# until we send the block-job-cancel command. Therefore, no event other than
174# BLOCK_JOB_CANCELLED will be emitted.
175
176test_blockjob \
177 "{'execute': 'block-stream',
78645881
KW
178 'arguments': {'job-id': 'job0',
179 'device': 'drv0',
c78dc182
HR
180 'speed': 1}}" \
181 'return' \
182 'BLOCK_JOB_CANCELLED'
183
184_cleanup_qemu
185
186# success, all done
187echo "*** done"
188rm -f $seq.full
189status=0