]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
9dd003a9 | 2 | # group: rw auto quick |
c78dc182 HR |
3 | # |
4 | # Test case for ejecting BDSs with block jobs still running on them | |
5 | # | |
6 | # Copyright (C) 2016 Red Hat, Inc. | |
7 | # | |
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. | |
12 | # | |
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. | |
17 | # | |
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/>. | |
20 | # | |
21 | ||
22 | # creator | |
42a5009d | 23 | owner=hreitz@redhat.com |
c78dc182 HR |
24 | |
25 | seq="$(basename $0)" | |
26 | echo "QA output created by $seq" | |
27 | ||
c78dc182 HR |
28 | status=1 # failure is the default! |
29 | ||
30 | _cleanup() | |
31 | { | |
ecfa1854 | 32 | _cleanup_qemu |
c78dc182 | 33 | _cleanup_test_img |
f91ecbd7 HR |
34 | for img in "$TEST_DIR"/{b,m,o}.$IMGFMT; do |
35 | _rm_test_img "$img" | |
36 | done | |
c78dc182 HR |
37 | } |
38 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
39 | ||
40 | # get standard environment, filters and checks | |
41 | . ./common.rc | |
42 | . ./common.filter | |
43 | . ./common.qemu | |
44 | ||
45 | # Needs backing file and backing format support | |
46 | _supported_fmt qcow2 qed | |
47 | _supported_proto file | |
48 | _supported_os Linux | |
49 | ||
50 | ||
51 | test_blockjob() | |
52 | { | |
53 | _send_qemu_cmd $QEMU_HANDLE \ | |
54 | "{'execute': 'blockdev-add', | |
55 | 'arguments': { | |
0153d2f5 KW |
56 | 'node-name': 'drv0', |
57 | 'driver': '$IMGFMT', | |
58 | 'file': { | |
59 | 'driver': 'file', | |
60 | 'filename': '$TEST_IMG' | |
61 | }}}" \ | |
c78dc182 HR |
62 | 'return' |
63 | ||
9c46f4a0 HR |
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.) | |
c78dc182 HR |
69 | _send_qemu_cmd $QEMU_HANDLE \ |
70 | "$1" \ | |
71 | "$2" \ | |
4b196cd1 | 72 | | _filter_img_create | _filter_qmp_empty_return |
c78dc182 HR |
73 | |
74 | # We want this to return an error because the block job is still running | |
75 | _send_qemu_cmd $QEMU_HANDLE \ | |
79b7a77e | 76 | "{'execute': 'blockdev-del', |
78645881 | 77 | 'arguments': {'node-name': 'drv0'}}" \ |
9c46f4a0 | 78 | 'error' | _filter_generated_node_ids | _filter_qmp_empty_return |
c78dc182 HR |
79 | |
80 | _send_qemu_cmd $QEMU_HANDLE \ | |
81 | "{'execute': 'block-job-cancel', | |
78645881 | 82 | 'arguments': {'device': 'job0'}}" \ |
c78dc182 HR |
83 | "$3" |
84 | ||
85 | _send_qemu_cmd $QEMU_HANDLE \ | |
79b7a77e | 86 | "{'execute': 'blockdev-del', |
78645881 | 87 | 'arguments': {'node-name': 'drv0'}}" \ |
c78dc182 HR |
88 | 'return' |
89 | } | |
90 | ||
91 | ||
92 | TEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M | |
b66ff2c2 EB |
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 | |
c78dc182 HR |
95 | |
96 | _launch_qemu -nodefaults | |
97 | ||
98 | _send_qemu_cmd $QEMU_HANDLE \ | |
99 | "{'execute': 'qmp_capabilities'}" \ | |
100 | 'return' | |
101 | ||
102 | echo | |
103 | echo '=== Testing drive-backup ===' | |
104 | echo | |
105 | ||
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. | |
108 | ||
109 | test_blockjob \ | |
110 | "{'execute': 'drive-backup', | |
78645881 KW |
111 | 'arguments': {'job-id': 'job0', |
112 | 'device': 'drv0', | |
c78dc182 HR |
113 | 'target': '$TEST_DIR/o.$IMGFMT', |
114 | 'format': '$IMGFMT', | |
115 | 'sync': 'none'}}" \ | |
116 | 'return' \ | |
1dac83f1 | 117 | '"status": "null"' |
c78dc182 HR |
118 | |
119 | echo | |
120 | echo '=== Testing drive-mirror ===' | |
121 | echo | |
122 | ||
123 | # drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling | |
124 | # the job will consequently result in BLOCK_JOB_COMPLETED being emitted. | |
125 | ||
126 | test_blockjob \ | |
127 | "{'execute': 'drive-mirror', | |
78645881 KW |
128 | 'arguments': {'job-id': 'job0', |
129 | 'device': 'drv0', | |
c78dc182 HR |
130 | 'target': '$TEST_DIR/o.$IMGFMT', |
131 | 'format': '$IMGFMT', | |
132 | 'sync': 'none'}}" \ | |
133 | 'BLOCK_JOB_READY' \ | |
1dac83f1 | 134 | '"status": "null"' |
c78dc182 HR |
135 | |
136 | echo | |
137 | echo '=== Testing active block-commit ===' | |
138 | echo | |
139 | ||
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 | |
142 | # emitted. | |
143 | ||
144 | test_blockjob \ | |
145 | "{'execute': 'block-commit', | |
78645881 | 146 | 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \ |
c78dc182 | 147 | 'BLOCK_JOB_READY' \ |
1dac83f1 | 148 | '"status": "null"' |
c78dc182 HR |
149 | |
150 | echo | |
151 | echo '=== Testing non-active block-commit ===' | |
152 | echo | |
153 | ||
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. | |
157 | ||
158 | $QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io | |
159 | ||
160 | test_blockjob \ | |
161 | "{'execute': 'block-commit', | |
78645881 KW |
162 | 'arguments': {'job-id': 'job0', |
163 | 'device': 'drv0', | |
c78dc182 HR |
164 | 'top': '$TEST_DIR/m.$IMGFMT', |
165 | 'speed': 1}}" \ | |
166 | 'return' \ | |
1dac83f1 | 167 | '"status": "null"' |
c78dc182 HR |
168 | |
169 | echo | |
170 | echo '=== Testing block-stream ===' | |
171 | echo | |
172 | ||
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. | |
176 | ||
177 | $QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io | |
178 | ||
179 | # With some data to stream (and @speed set to 1), block-stream will not complete | |
1dac83f1 | 180 | # until we send the block-job-cancel command. |
c78dc182 HR |
181 | |
182 | test_blockjob \ | |
183 | "{'execute': 'block-stream', | |
78645881 KW |
184 | 'arguments': {'job-id': 'job0', |
185 | 'device': 'drv0', | |
c78dc182 HR |
186 | 'speed': 1}}" \ |
187 | 'return' \ | |
1dac83f1 | 188 | '"status": "null"' |
c78dc182 HR |
189 | |
190 | _cleanup_qemu | |
191 | ||
192 | # success, all done | |
193 | echo "*** done" | |
194 | rm -f $seq.full | |
195 | status=0 |