]>
Commit | Line | Data |
---|---|---|
24575bfa KW |
1 | #!/bin/bash |
2 | # | |
3 | # Test exiting qemu while jobs are still running | |
4 | # | |
5 | # Copyright (C) 2017 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 | ||
27 | here=`pwd` | |
28 | status=1 # failure is the default! | |
29 | ||
24575bfa KW |
30 | _cleanup() |
31 | { | |
32 | rm -f "${TEST_IMG}.mid" | |
33 | rm -f "${TEST_IMG}.copy" | |
34 | _cleanup_test_img | |
35 | _cleanup_qemu | |
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 | _supported_fmt qcow2 | |
45 | _supported_proto file | |
46 | _supported_os Linux | |
47 | ||
48 | size=64M | |
49 | TEST_IMG="${TEST_IMG}.base" _make_test_img $size | |
50 | ||
51 | echo | |
52 | echo === Starting VM === | |
53 | echo | |
54 | ||
55 | qemu_comm_method="qmp" | |
56 | ||
57 | _launch_qemu \ | |
58 | -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk | |
59 | h=$QEMU_HANDLE | |
60 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' | |
61 | ||
62 | echo | |
63 | echo === Creating backing chain === | |
64 | echo | |
65 | ||
66 | _send_qemu_cmd $h \ | |
67 | "{ 'execute': 'blockdev-snapshot-sync', | |
68 | 'arguments': { 'device': 'disk', | |
69 | 'snapshot-file': '$TEST_IMG.mid', | |
70 | 'format': '$IMGFMT', | |
71 | 'mode': 'absolute-paths' } }" \ | |
72 | "return" | |
73 | ||
74 | _send_qemu_cmd $h \ | |
75 | "{ 'execute': 'human-monitor-command', | |
76 | 'arguments': { 'command-line': | |
77 | 'qemu-io disk \"write 0 4M\"' } }" \ | |
78 | "return" | |
79 | ||
80 | _send_qemu_cmd $h \ | |
81 | "{ 'execute': 'blockdev-snapshot-sync', | |
82 | 'arguments': { 'device': 'disk', | |
83 | 'snapshot-file': '$TEST_IMG', | |
84 | 'format': '$IMGFMT', | |
85 | 'mode': 'absolute-paths' } }" \ | |
86 | "return" | |
87 | ||
88 | echo | |
89 | echo === Start commit job and exit qemu === | |
90 | echo | |
91 | ||
92 | # Note that the reference output intentionally includes the 'offset' field in | |
c1de5696 SH |
93 | # BLOCK_JOB_* events for all of the following block jobs. They are predictable |
94 | # and any change in the offsets would hint at a bug in the job throttling code. | |
24575bfa KW |
95 | # |
96 | # In order to achieve these predictable offsets, all of the following tests | |
97 | # use speed=65536. Each job will perform exactly one iteration before it has | |
98 | # to sleep at least for a second, which is plenty of time for the 'quit' QMP | |
99 | # command to be received (after receiving the command, the rest runs | |
100 | # synchronously, so jobs can arbitrarily continue or complete). | |
101 | # | |
102 | # The buffer size for commit and streaming is 512k (waiting for 8 seconds after | |
103 | # the first request), for active commit and mirror it's large enough to cover | |
104 | # the full 4M, and for backup it's the qcow2 cluster size, which we know is | |
105 | # 64k. As all of these are at least as large as the speed, we are sure that the | |
4c7e813c | 106 | # offset advances exactly once before qemu exits. |
24575bfa KW |
107 | |
108 | _send_qemu_cmd $h \ | |
109 | "{ 'execute': 'block-commit', | |
110 | 'arguments': { 'device': 'disk', | |
111 | 'base':'$TEST_IMG.base', | |
112 | 'top': '$TEST_IMG.mid', | |
113 | 'speed': 65536 } }" \ | |
114 | "return" | |
115 | ||
ddf2d98a SH |
116 | # If we don't sleep here 'quit' command races with disk I/O |
117 | sleep 0.5 | |
118 | ||
1dac83f1 KW |
119 | # Ignore the JOB_STATUS_CHANGE events while shutting down the VM. Depending on |
120 | # the timing, jobs may or may not transition through a paused state. | |
24575bfa | 121 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "return" |
1dac83f1 | 122 | wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE' |
24575bfa KW |
123 | |
124 | echo | |
125 | echo === Start active commit job and exit qemu === | |
126 | echo | |
127 | ||
128 | _launch_qemu \ | |
129 | -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk | |
130 | h=$QEMU_HANDLE | |
131 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' | |
132 | ||
133 | _send_qemu_cmd $h \ | |
134 | "{ 'execute': 'block-commit', | |
135 | 'arguments': { 'device': 'disk', | |
136 | 'base':'$TEST_IMG.base', | |
137 | 'speed': 65536 } }" \ | |
138 | "return" | |
139 | ||
ddf2d98a SH |
140 | # If we don't sleep here 'quit' command races with disk I/O |
141 | sleep 0.5 | |
142 | ||
24575bfa | 143 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "return" |
1dac83f1 | 144 | wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE' |
24575bfa KW |
145 | |
146 | echo | |
147 | echo === Start mirror job and exit qemu === | |
148 | echo | |
149 | ||
150 | _launch_qemu \ | |
151 | -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk | |
152 | h=$QEMU_HANDLE | |
153 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' | |
154 | ||
155 | _send_qemu_cmd $h \ | |
156 | "{ 'execute': 'drive-mirror', | |
157 | 'arguments': { 'device': 'disk', | |
158 | 'target': '$TEST_IMG.copy', | |
159 | 'format': '$IMGFMT', | |
160 | 'sync': 'full', | |
161 | 'speed': 65536 } }" \ | |
162 | "return" | |
163 | ||
8565c3ab VSO |
164 | # If we don't sleep here 'quit' command may be handled before |
165 | # the first mirror iteration is done | |
166 | sleep 0.5 | |
167 | ||
24575bfa | 168 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "return" |
1dac83f1 | 169 | wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE' |
24575bfa KW |
170 | |
171 | echo | |
172 | echo === Start backup job and exit qemu === | |
173 | echo | |
174 | ||
175 | _launch_qemu \ | |
176 | -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk | |
177 | h=$QEMU_HANDLE | |
178 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' | |
179 | ||
180 | _send_qemu_cmd $h \ | |
181 | "{ 'execute': 'drive-backup', | |
182 | 'arguments': { 'device': 'disk', | |
183 | 'target': '$TEST_IMG.copy', | |
184 | 'format': '$IMGFMT', | |
185 | 'sync': 'full', | |
186 | 'speed': 65536 } }" \ | |
187 | "return" | |
188 | ||
ddf2d98a SH |
189 | # If we don't sleep here 'quit' command races with disk I/O |
190 | sleep 0.5 | |
191 | ||
24575bfa | 192 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "return" |
1dac83f1 | 193 | wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE' |
24575bfa KW |
194 | |
195 | echo | |
196 | echo === Start streaming job and exit qemu === | |
197 | echo | |
198 | ||
199 | _launch_qemu \ | |
200 | -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk | |
201 | h=$QEMU_HANDLE | |
202 | _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' | |
203 | ||
204 | _send_qemu_cmd $h \ | |
205 | "{ 'execute': 'block-stream', | |
206 | 'arguments': { 'device': 'disk', | |
207 | 'speed': 65536 } }" \ | |
208 | "return" | |
209 | ||
ddf2d98a SH |
210 | # If we don't sleep here 'quit' command races with disk I/O |
211 | sleep 0.5 | |
212 | ||
24575bfa | 213 | _send_qemu_cmd $h "{ 'execute': 'quit' }" "return" |
1dac83f1 | 214 | wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE' |
24575bfa KW |
215 | |
216 | _check_test_img | |
217 | ||
218 | # success, all done | |
219 | echo "*** done" | |
220 | rm -f $seq.full | |
221 | status=0 |