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/>.
22 owner
=kwolf@redhat.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
31 rm -f "${TEST_IMG}.mid"
32 rm -f "${TEST_IMG}.copy"
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
48 TEST_IMG
="${TEST_IMG}.base" _make_test_img
$size
51 echo === Starting VM
===
54 qemu_comm_method
="qmp"
57 -drive file="${TEST_IMG}.base",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
59 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
62 echo === Creating backing chain
===
66 "{ 'execute': 'blockdev-snapshot-sync',
67 'arguments': { 'device': 'disk',
68 'snapshot-file': '$TEST_IMG.mid',
70 'mode': 'absolute-paths' } }" \
74 "{ 'execute': 'human-monitor-command',
75 'arguments': { 'command-line':
76 'qemu-io disk \"write 0 4M\"' } }" \
80 "{ 'execute': 'blockdev-snapshot-sync',
81 'arguments': { 'device': 'disk',
82 'snapshot-file': '$TEST_IMG',
84 'mode': 'absolute-paths' } }" \
88 echo === Start commit job and
exit qemu
===
91 # Note that the reference output intentionally includes the 'offset' field in
92 # BLOCK_JOB_* events for all of the following block jobs. They are predictable
93 # and any change in the offsets would hint at a bug in the job throttling code.
95 # In order to achieve these predictable offsets, all of the following tests
96 # use speed=65536. Each job will perform exactly one iteration before it has
97 # to sleep at least for a second, which is plenty of time for the 'quit' QMP
98 # command to be received (after receiving the command, the rest runs
99 # synchronously, so jobs can arbitrarily continue or complete).
101 # The buffer size for commit and streaming is 512k (waiting for 8 seconds after
102 # the first request), for active commit and mirror it's large enough to cover
103 # the full 4M, and for backup it's the qcow2 cluster size, which we know is
104 # 64k. As all of these are at least as large as the speed, we are sure that the
105 # offset advances exactly once before qemu exits.
108 "{ 'execute': 'block-commit',
109 'arguments': { 'device': 'disk',
110 'base':'$TEST_IMG.base',
111 'top': '$TEST_IMG.mid',
112 'speed': 65536 } }" \
115 # If we don't sleep here 'quit' command races with disk I/O
118 # Ignore the JOB_STATUS_CHANGE events while shutting down the VM. Depending on
119 # the timing, jobs may or may not transition through a paused state.
120 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
121 wait=1 _cleanup_qemu |
grep -v 'JOB_STATUS_CHANGE'
124 echo === Start active commit job and
exit qemu
===
128 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
130 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
133 "{ 'execute': 'block-commit',
134 'arguments': { 'device': 'disk',
135 'base':'$TEST_IMG.base',
136 'speed': 65536 } }" \
139 # If we don't sleep here 'quit' command races with disk I/O
142 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
143 wait=1 _cleanup_qemu |
grep -v 'JOB_STATUS_CHANGE'
146 echo === Start mirror job and
exit qemu
===
150 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
152 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
155 "{ 'execute': 'drive-mirror',
156 'arguments': { 'device': 'disk',
157 'target': '$TEST_IMG.copy',
160 'speed': 65536 } }" \
163 # If we don't sleep here 'quit' command may be handled before
164 # the first mirror iteration is done
167 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
168 wait=1 _cleanup_qemu |
grep -v 'JOB_STATUS_CHANGE'
171 echo === Start backup job and
exit qemu
===
175 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
177 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
180 "{ 'execute': 'drive-backup',
181 'arguments': { 'device': 'disk',
182 'target': '$TEST_IMG.copy',
185 'speed': 65536 } }" \
188 # If we don't sleep here 'quit' command races with disk I/O
191 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
192 wait=1 _cleanup_qemu |
grep -v 'JOB_STATUS_CHANGE'
195 echo === Start streaming job and
exit qemu
===
199 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
201 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
204 "{ 'execute': 'block-stream',
205 'arguments': { 'device': 'disk',
206 'speed': 65536 } }" \
209 # If we don't sleep here 'quit' command races with disk I/O
212 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
213 wait=1 _cleanup_qemu |
grep -v 'JOB_STATUS_CHANGE'