blockjob: do not cancel timer in resume
[qemu/ar7.git] / tests / qemu-iotests / 185
blob9a2d31741426e4e14c4fc718f6ec6016c4a666f0
1 #!/bin/bash
3 # Test exiting qemu while jobs are still running
5 # Copyright (C) 2017 Red Hat, Inc.
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.
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.
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/>.
21 # creator
22 owner=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 here=`pwd`
28 status=1 # failure is the default!
30 MIG_SOCKET="${TEST_DIR}/migrate"
32 _cleanup()
34 rm -f "${TEST_IMG}.mid"
35 rm -f "${TEST_IMG}.copy"
36 _cleanup_test_img
37 _cleanup_qemu
39 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
42 . ./common.rc
43 . ./common.filter
44 . ./common.qemu
46 _supported_fmt qcow2
47 _supported_proto file
48 _supported_os Linux
50 size=64M
51 TEST_IMG="${TEST_IMG}.base" _make_test_img $size
53 echo
54 echo === Starting VM ===
55 echo
57 qemu_comm_method="qmp"
59 _launch_qemu \
60 -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
61 h=$QEMU_HANDLE
62 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
64 echo
65 echo === Creating backing chain ===
66 echo
68 _send_qemu_cmd $h \
69 "{ 'execute': 'blockdev-snapshot-sync',
70 'arguments': { 'device': 'disk',
71 'snapshot-file': '$TEST_IMG.mid',
72 'format': '$IMGFMT',
73 'mode': 'absolute-paths' } }" \
74 "return"
76 _send_qemu_cmd $h \
77 "{ 'execute': 'human-monitor-command',
78 'arguments': { 'command-line':
79 'qemu-io disk \"write 0 4M\"' } }" \
80 "return"
82 _send_qemu_cmd $h \
83 "{ 'execute': 'blockdev-snapshot-sync',
84 'arguments': { 'device': 'disk',
85 'snapshot-file': '$TEST_IMG',
86 'format': '$IMGFMT',
87 'mode': 'absolute-paths' } }" \
88 "return"
90 echo
91 echo === Start commit job and exit qemu ===
92 echo
94 # Note that the reference output intentionally includes the 'offset' field in
95 # BLOCK_JOB_* events for all of the following block jobs. They are predictable
96 # and any change in the offsets would hint at a bug in the job throttling code.
98 # In order to achieve these predictable offsets, all of the following tests
99 # use speed=65536. Each job will perform exactly one iteration before it has
100 # to sleep at least for a second, which is plenty of time for the 'quit' QMP
101 # command to be received (after receiving the command, the rest runs
102 # synchronously, so jobs can arbitrarily continue or complete).
104 # The buffer size for commit and streaming is 512k (waiting for 8 seconds after
105 # the first request), for active commit and mirror it's large enough to cover
106 # the full 4M, and for backup it's the qcow2 cluster size, which we know is
107 # 64k. As all of these are at least as large as the speed, we are sure that the
108 # offset advances exactly once before qemu exits.
110 _send_qemu_cmd $h \
111 "{ 'execute': 'block-commit',
112 'arguments': { 'device': 'disk',
113 'base':'$TEST_IMG.base',
114 'top': '$TEST_IMG.mid',
115 'speed': 65536 } }" \
116 "return"
118 # If we don't sleep here 'quit' command races with disk I/O
119 sleep 0.5
121 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
122 wait=1 _cleanup_qemu
124 echo
125 echo === Start active commit job and exit qemu ===
126 echo
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'
133 _send_qemu_cmd $h \
134 "{ 'execute': 'block-commit',
135 'arguments': { 'device': 'disk',
136 'base':'$TEST_IMG.base',
137 'speed': 65536 } }" \
138 "return"
140 # If we don't sleep here 'quit' command races with disk I/O
141 sleep 0.5
143 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
144 wait=1 _cleanup_qemu
146 echo
147 echo === Start mirror job and exit qemu ===
148 echo
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'
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"
164 # If we don't sleep here 'quit' command may be handled before
165 # the first mirror iteration is done
166 sleep 0.5
168 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
169 wait=1 _cleanup_qemu
171 echo
172 echo === Start backup job and exit qemu ===
173 echo
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'
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"
189 # If we don't sleep here 'quit' command races with disk I/O
190 sleep 0.5
192 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
193 wait=1 _cleanup_qemu
195 echo
196 echo === Start streaming job and exit qemu ===
197 echo
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'
204 _send_qemu_cmd $h \
205 "{ 'execute': 'block-stream',
206 'arguments': { 'device': 'disk',
207 'speed': 65536 } }" \
208 "return"
210 # If we don't sleep here 'quit' command races with disk I/O
211 sleep 0.5
213 _send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
214 wait=1 _cleanup_qemu
216 _check_test_img
218 # success, all done
219 echo "*** done"
220 rm -f $seq.full
221 status=0