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