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"
28 status
=1 # failure is the default!
30 MIG_SOCKET
="${TEST_DIR}/migrate"
34 rm -f "${TEST_IMG}.mid"
35 rm -f "${TEST_IMG}.copy"
39 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
51 TEST_IMG
="${TEST_IMG}.base" _make_test_img
$size
54 echo === Starting VM
===
57 qemu_comm_method
="qmp"
60 -drive file="${TEST_IMG}.base",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
62 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
65 echo === Creating backing chain
===
69 "{ 'execute': 'blockdev-snapshot-sync',
70 'arguments': { 'device': 'disk',
71 'snapshot-file': '$TEST_IMG.mid',
73 'mode': 'absolute-paths' } }" \
77 "{ 'execute': 'human-monitor-command',
78 'arguments': { 'command-line':
79 'qemu-io disk \"write 0 4M\"' } }" \
83 "{ 'execute': 'blockdev-snapshot-sync',
84 'arguments': { 'device': 'disk',
85 'snapshot-file': '$TEST_IMG',
87 'mode': 'absolute-paths' } }" \
91 echo === Start commit job and
exit qemu
===
94 # Note that the reference output intentionally includes the 'offset' field in
95 # BLOCK_JOB_CANCELLED events for all of the following block jobs. They are
96 # predictable and any change in the offsets would hint at a bug in the job
99 # In order to achieve these predictable offsets, all of the following tests
100 # use speed=65536. Each job will perform exactly one iteration before it has
101 # to sleep at least for a second, which is plenty of time for the 'quit' QMP
102 # command to be received (after receiving the command, the rest runs
103 # synchronously, so jobs can arbitrarily continue or complete).
105 # The buffer size for commit and streaming is 512k (waiting for 8 seconds after
106 # the first request), for active commit and mirror it's large enough to cover
107 # the full 4M, and for backup it's the qcow2 cluster size, which we know is
108 # 64k. As all of these are at least as large as the speed, we are sure that the
109 # offset doesn't advance after the first iteration before qemu exits.
112 "{ 'execute': 'block-commit',
113 'arguments': { 'device': 'disk',
114 'base':'$TEST_IMG.base',
115 'top': '$TEST_IMG.mid',
116 'speed': 65536 } }" \
119 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
123 echo === Start active commit job and
exit qemu
===
127 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
129 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
132 "{ 'execute': 'block-commit',
133 'arguments': { 'device': 'disk',
134 'base':'$TEST_IMG.base',
135 'speed': 65536 } }" \
138 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
142 echo === Start mirror job and
exit qemu
===
146 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
148 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
151 "{ 'execute': 'drive-mirror',
152 'arguments': { 'device': 'disk',
153 'target': '$TEST_IMG.copy',
156 'speed': 65536 } }" \
159 # If we don't sleep here 'quit' command may be handled before
160 # the first mirror iteration is done
163 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
167 echo === Start backup job and
exit qemu
===
171 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
173 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
176 "{ 'execute': 'drive-backup',
177 'arguments': { 'device': 'disk',
178 'target': '$TEST_IMG.copy',
181 'speed': 65536 } }" \
184 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"
188 echo === Start streaming job and
exit qemu
===
192 -drive file="${TEST_IMG}",cache
=$CACHEMODE,driver
=$IMGFMT,id
=disk
194 _send_qemu_cmd
$h "{ 'execute': 'qmp_capabilities' }" 'return'
197 "{ 'execute': 'block-stream',
198 'arguments': { 'device': 'disk',
199 'speed': 65536 } }" \
202 _send_qemu_cmd
$h "{ 'execute': 'quit' }" "return"