summaryrefslogtreecommitdiffstats
path: root/tests/qemu-iotests/185
blob: 7bc8fe5767a3fee97c1ce7f2bfe5d824f27a6b0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bash
# group: rw
#
# Test exiting qemu while jobs are still running
#
# Copyright (C) 2017 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# creator
owner=kwolf@redhat.com

seq=`basename $0`
echo "QA output created by $seq"

status=1 # failure is the default!

_cleanup()
{
    _rm_test_img "${TEST_IMG}.mid"
    _rm_test_img "${TEST_IMG}.copy"
    _cleanup_test_img
    _cleanup_qemu
}
trap "_cleanup; exit \$status" 0 1 2 3 15

# get standard environment, filters and checks
. ./common.rc
. ./common.filter
. ./common.qemu

_supported_fmt qcow2
_supported_proto file
_supported_os Linux

size=64M
TEST_IMG="${TEST_IMG}.base" _make_test_img $size

echo
echo === Starting VM ===
echo

qemu_comm_method="qmp"

_launch_qemu \
    -drive file="${TEST_IMG}.base",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
h=$QEMU_HANDLE
_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'

echo
echo === Creating backing chain ===
echo

_send_qemu_cmd $h \
    "{ 'execute': 'blockdev-snapshot-sync',
       'arguments': { 'device': 'disk',
                      'snapshot-file': '$TEST_IMG.mid',
                      'format': '$IMGFMT',
                      'mode': 'absolute-paths' } }" \
    "return"

_send_qemu_cmd $h \
    "{ 'execute': 'human-monitor-command',
       'arguments': { 'command-line':
                      'qemu-io disk \"write 0 4M\"' } }" \
    "return"

_send_qemu_cmd $h \
    "{ 'execute': 'blockdev-snapshot-sync',
       'arguments': { 'device': 'disk',
                      'snapshot-file': '$TEST_IMG',
                      'format': '$IMGFMT',
                      'mode': 'absolute-paths' } }" \
    "return"

echo
echo === Start commit job and exit qemu ===
echo

# Note that the reference output intentionally includes the 'offset' field in
# BLOCK_JOB_* events for all of the following block jobs. They are predictable
# and any change in the offsets would hint at a bug in the job throttling code.
#
# In order to achieve these predictable offsets, all of the following tests
# use speed=65536. Each job will perform exactly one iteration before it has
# to sleep at least for a second, which is plenty of time for the 'quit' QMP
# command to be received (after receiving the command, the rest runs
# synchronously, so jobs can arbitrarily continue or complete).
#
# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
# the first request), for active commit and mirror it's large enough to cover
# the full 4M, and for backup it's the qcow2 cluster size, which we know is
# 64k. As all of these are at least as large as the speed, we are sure that the
# offset advances exactly once before qemu exits.

_send_qemu_cmd $h \
    "{ 'execute': 'block-commit',
       'arguments': { 'device': 'disk',
                      'base':'$TEST_IMG.base',
                      'top': '$TEST_IMG.mid',
                      'speed': 65536 } }" \
    "return"

# If we don't sleep here 'quit' command races with disk I/O
sleep 0.5

# Ignore the JOB_STATUS_CHANGE events while shutting down the VM. Depending on
# the timing, jobs may or may not transition through a paused state.
_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'

echo
echo === Start active commit job and exit qemu ===
echo

_launch_qemu \
    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
h=$QEMU_HANDLE
_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'

_send_qemu_cmd $h \
    "{ 'execute': 'block-commit',
       'arguments': { 'device': 'disk',
                      'base':'$TEST_IMG.base',
                      'speed': 65536 } }" \
    "return"

# If we don't sleep here 'quit' command races with disk I/O
sleep 0.5

_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'

echo
echo === Start mirror job and exit qemu ===
echo

_launch_qemu \
    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
h=$QEMU_HANDLE
_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'

_send_qemu_cmd $h \
    "{ 'execute': 'drive-mirror',
       'arguments': { 'device': 'disk',
                      'target': '$TEST_IMG.copy',
                      'format': '$IMGFMT',
                      'sync': 'full',
                      'speed': 65536 } }" \
    "return"

# If we don't sleep here 'quit' command may be handled before
# the first mirror iteration is done
sleep 0.5

_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'

echo
echo === Start backup job and exit qemu ===
echo

_launch_qemu \
    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
h=$QEMU_HANDLE
_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'

_send_qemu_cmd $h \
    "{ 'execute': 'drive-backup',
       'arguments': { 'device': 'disk',
                      'target': '$TEST_IMG.copy',
                      'format': '$IMGFMT',
                      'sync': 'full',
                      'speed': 65536 } }" \
    "return"

# If we don't sleep here 'quit' command races with disk I/O
sleep 0.5

_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'

echo
echo === Start streaming job and exit qemu ===
echo

_launch_qemu \
    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
h=$QEMU_HANDLE
_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'

_send_qemu_cmd $h \
    "{ 'execute': 'block-stream',
       'arguments': { 'device': 'disk',
                      'speed': 65536 } }" \
    "return"

# If we don't sleep here 'quit' command races with disk I/O
sleep 0.5

_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
wait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'

_check_test_img

# success, all done
echo "*** done"
rm -f $seq.full
status=0