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