xref: /openbmc/qemu/tests/qemu-iotests/185 (revision f389309d2937e66960dd371014a1971678fb4ce7)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw
324575bfaSKevin Wolf#
424575bfaSKevin Wolf# Test exiting qemu while jobs are still running
524575bfaSKevin Wolf#
624575bfaSKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
724575bfaSKevin Wolf#
824575bfaSKevin Wolf# This program is free software; you can redistribute it and/or modify
924575bfaSKevin Wolf# it under the terms of the GNU General Public License as published by
1024575bfaSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1124575bfaSKevin Wolf# (at your option) any later version.
1224575bfaSKevin Wolf#
1324575bfaSKevin Wolf# This program is distributed in the hope that it will be useful,
1424575bfaSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1524575bfaSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1624575bfaSKevin Wolf# GNU General Public License for more details.
1724575bfaSKevin Wolf#
1824575bfaSKevin Wolf# You should have received a copy of the GNU General Public License
1924575bfaSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2024575bfaSKevin Wolf#
2124575bfaSKevin Wolf
2224575bfaSKevin Wolf# creator
2324575bfaSKevin Wolfowner=kwolf@redhat.com
2424575bfaSKevin Wolf
2524575bfaSKevin Wolfseq=`basename $0`
2624575bfaSKevin Wolfecho "QA output created by $seq"
2724575bfaSKevin Wolf
2824575bfaSKevin Wolfstatus=1 # failure is the default!
2924575bfaSKevin Wolf
3024575bfaSKevin Wolf_cleanup()
3124575bfaSKevin Wolf{
32f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.mid"
33f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.copy"
3424575bfaSKevin Wolf    _cleanup_test_img
3524575bfaSKevin Wolf    _cleanup_qemu
36ad6fe44bSHanna Reitz
37ad6fe44bSHanna Reitz    if [ -f "$TEST_DIR/qsd.pid" ]; then
38ad6fe44bSHanna Reitz        kill -SIGKILL "$(cat "$TEST_DIR/qsd.pid")"
39ad6fe44bSHanna Reitz        rm -f "$TEST_DIR/qsd.pid"
40ad6fe44bSHanna Reitz    fi
41ad6fe44bSHanna Reitz    rm -f "$SOCK_DIR/qsd.sock"
4224575bfaSKevin Wolf}
4324575bfaSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
4424575bfaSKevin Wolf
4524575bfaSKevin Wolf# get standard environment, filters and checks
4624575bfaSKevin Wolf. ./common.rc
4724575bfaSKevin Wolf. ./common.filter
4824575bfaSKevin Wolf. ./common.qemu
4924575bfaSKevin Wolf
5024575bfaSKevin Wolf_supported_fmt qcow2
5124575bfaSKevin Wolf_supported_proto file
5224575bfaSKevin Wolf_supported_os Linux
5324575bfaSKevin Wolf
54ad6fe44bSHanna Reitzsize=$((64 * 1048576))
5524575bfaSKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size
5624575bfaSKevin Wolf
5724575bfaSKevin Wolfecho
5824575bfaSKevin Wolfecho === Starting VM ===
5924575bfaSKevin Wolfecho
6024575bfaSKevin Wolf
6124575bfaSKevin Wolfqemu_comm_method="qmp"
6224575bfaSKevin Wolf
6324575bfaSKevin Wolf_launch_qemu \
648dff69b9SAarushi Mehta    -drive file="${TEST_IMG}.base",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
6524575bfaSKevin Wolfh=$QEMU_HANDLE
6624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
6724575bfaSKevin Wolf
6824575bfaSKevin Wolfecho
6924575bfaSKevin Wolfecho === Creating backing chain ===
7024575bfaSKevin Wolfecho
7124575bfaSKevin Wolf
7224575bfaSKevin Wolf_send_qemu_cmd $h \
7324575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
7424575bfaSKevin Wolf       'arguments': { 'device': 'disk',
7524575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG.mid',
7624575bfaSKevin Wolf                      'format': '$IMGFMT',
7724575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
7824575bfaSKevin Wolf    "return"
7924575bfaSKevin Wolf
8024575bfaSKevin Wolf_send_qemu_cmd $h \
8124575bfaSKevin Wolf    "{ 'execute': 'human-monitor-command',
8224575bfaSKevin Wolf       'arguments': { 'command-line':
8324575bfaSKevin Wolf                      'qemu-io disk \"write 0 4M\"' } }" \
8424575bfaSKevin Wolf    "return"
8524575bfaSKevin Wolf
8624575bfaSKevin Wolf_send_qemu_cmd $h \
8724575bfaSKevin Wolf    "{ 'execute': 'blockdev-snapshot-sync',
8824575bfaSKevin Wolf       'arguments': { 'device': 'disk',
8924575bfaSKevin Wolf                      'snapshot-file': '$TEST_IMG',
9024575bfaSKevin Wolf                      'format': '$IMGFMT',
9124575bfaSKevin Wolf                      'mode': 'absolute-paths' } }" \
9224575bfaSKevin Wolf    "return"
9324575bfaSKevin Wolf
9424575bfaSKevin Wolfecho
9524575bfaSKevin Wolfecho === Start commit job and exit qemu ===
9624575bfaSKevin Wolfecho
9724575bfaSKevin Wolf
9824575bfaSKevin Wolf# Note that the reference output intentionally includes the 'offset' field in
99c1de5696SStefan Hajnoczi# BLOCK_JOB_* events for all of the following block jobs. They are predictable
100c1de5696SStefan Hajnoczi# and any change in the offsets would hint at a bug in the job throttling code.
10124575bfaSKevin Wolf#
10224575bfaSKevin Wolf# In order to achieve these predictable offsets, all of the following tests
10324575bfaSKevin Wolf# use speed=65536. Each job will perform exactly one iteration before it has
10424575bfaSKevin Wolf# to sleep at least for a second, which is plenty of time for the 'quit' QMP
10524575bfaSKevin Wolf# command to be received (after receiving the command, the rest runs
10624575bfaSKevin Wolf# synchronously, so jobs can arbitrarily continue or complete).
10724575bfaSKevin Wolf#
10824575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
10924575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover
11024575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is
11124575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the
1124c7e813cSStefan Hajnoczi# offset advances exactly once before qemu exits.
11324575bfaSKevin Wolf
11424575bfaSKevin Wolf_send_qemu_cmd $h \
11524575bfaSKevin Wolf    "{ 'execute': 'block-commit',
11624575bfaSKevin Wolf       'arguments': { 'device': 'disk',
11724575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
11824575bfaSKevin Wolf                      'top': '$TEST_IMG.mid',
11924575bfaSKevin Wolf                      'speed': 65536 } }" \
12024575bfaSKevin Wolf    "return"
12124575bfaSKevin Wolf
122ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
123ddf2d98aSStefan Hajnoczisleep 0.5
124ddf2d98aSStefan Hajnoczi
1251dac83f1SKevin Wolf# Ignore the JOB_STATUS_CHANGE events while shutting down the VM. Depending on
1261dac83f1SKevin Wolf# the timing, jobs may or may not transition through a paused state.
12724575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1281dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
12924575bfaSKevin Wolf
13024575bfaSKevin Wolfecho
13124575bfaSKevin Wolfecho === Start active commit job and exit qemu ===
13224575bfaSKevin Wolfecho
13324575bfaSKevin Wolf
13424575bfaSKevin Wolf_launch_qemu \
1358dff69b9SAarushi Mehta    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
13624575bfaSKevin Wolfh=$QEMU_HANDLE
13724575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
13824575bfaSKevin Wolf
13924575bfaSKevin Wolf_send_qemu_cmd $h \
14024575bfaSKevin Wolf    "{ 'execute': 'block-commit',
14124575bfaSKevin Wolf       'arguments': { 'device': 'disk',
14224575bfaSKevin Wolf                      'base':'$TEST_IMG.base',
14324575bfaSKevin Wolf                      'speed': 65536 } }" \
14424575bfaSKevin Wolf    "return"
14524575bfaSKevin Wolf
146ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
147ddf2d98aSStefan Hajnoczisleep 0.5
148ddf2d98aSStefan Hajnoczi
14924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1501dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
15124575bfaSKevin Wolf
15224575bfaSKevin Wolfecho
15324575bfaSKevin Wolfecho === Start mirror job and exit qemu ===
15424575bfaSKevin Wolfecho
15524575bfaSKevin Wolf
15624575bfaSKevin Wolf_launch_qemu \
1578dff69b9SAarushi Mehta    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
15824575bfaSKevin Wolfh=$QEMU_HANDLE
15924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
16024575bfaSKevin Wolf
16124575bfaSKevin Wolf_send_qemu_cmd $h \
16224575bfaSKevin Wolf    "{ 'execute': 'drive-mirror',
16324575bfaSKevin Wolf       'arguments': { 'device': 'disk',
16424575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
16524575bfaSKevin Wolf                      'format': '$IMGFMT',
16624575bfaSKevin Wolf                      'sync': 'full',
16724575bfaSKevin Wolf                      'speed': 65536 } }" \
16824575bfaSKevin Wolf    "return"
16924575bfaSKevin Wolf
1708565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before
1718565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done
1728565c3abSVladimir Sementsov-Ogievskiysleep 0.5
1738565c3abSVladimir Sementsov-Ogievskiy
17424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
1751dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
17624575bfaSKevin Wolf
17724575bfaSKevin Wolfecho
17824575bfaSKevin Wolfecho === Start backup job and exit qemu ===
17924575bfaSKevin Wolfecho
18024575bfaSKevin Wolf
18124575bfaSKevin Wolf_launch_qemu \
1828dff69b9SAarushi Mehta    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
18324575bfaSKevin Wolfh=$QEMU_HANDLE
18424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
18524575bfaSKevin Wolf
18624575bfaSKevin Wolf_send_qemu_cmd $h \
18724575bfaSKevin Wolf    "{ 'execute': 'drive-backup',
18824575bfaSKevin Wolf       'arguments': { 'device': 'disk',
18924575bfaSKevin Wolf                      'target': '$TEST_IMG.copy',
19024575bfaSKevin Wolf                      'format': '$IMGFMT',
19124575bfaSKevin Wolf                      'sync': 'full',
19261623f82SVladimir Sementsov-Ogievskiy                      'speed': 65536,
19361623f82SVladimir Sementsov-Ogievskiy                      'x-perf': {'max-chunk': 65536} } }" \
19424575bfaSKevin Wolf    "return"
19524575bfaSKevin Wolf
196ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
197ddf2d98aSStefan Hajnoczisleep 0.5
198ddf2d98aSStefan Hajnoczi
19924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
2001dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
20124575bfaSKevin Wolf
20224575bfaSKevin Wolfecho
20324575bfaSKevin Wolfecho === Start streaming job and exit qemu ===
20424575bfaSKevin Wolfecho
20524575bfaSKevin Wolf
20624575bfaSKevin Wolf_launch_qemu \
2078dff69b9SAarushi Mehta    -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk
20824575bfaSKevin Wolfh=$QEMU_HANDLE
20924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
21024575bfaSKevin Wolf
21124575bfaSKevin Wolf_send_qemu_cmd $h \
21224575bfaSKevin Wolf    "{ 'execute': 'block-stream',
21324575bfaSKevin Wolf       'arguments': { 'device': 'disk',
21424575bfaSKevin Wolf                      'speed': 65536 } }" \
21524575bfaSKevin Wolf    "return"
21624575bfaSKevin Wolf
217ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O
218ddf2d98aSStefan Hajnoczisleep 0.5
219ddf2d98aSStefan Hajnoczi
22024575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
2211dac83f1SKevin Wolfwait=1 _cleanup_qemu | grep -v 'JOB_STATUS_CHANGE'
22224575bfaSKevin Wolf
22324575bfaSKevin Wolf_check_test_img
22424575bfaSKevin Wolf
225ad6fe44bSHanna Reitzecho
226ad6fe44bSHanna Reitzecho === Start mirror to throttled QSD and exit qemu ===
227ad6fe44bSHanna Reitzecho
228ad6fe44bSHanna Reitz
229ad6fe44bSHanna Reitz# Mirror to a throttled QSD instance (so that qemu cannot drain the
230ad6fe44bSHanna Reitz# throttling), wait for READY, then write some data to the device,
231ad6fe44bSHanna Reitz# and then quit qemu.
232ad6fe44bSHanna Reitz# (qemu should force-cancel the job and not wait for the data to be
233ad6fe44bSHanna Reitz# written to the target.)
234ad6fe44bSHanna Reitz
235ad6fe44bSHanna Reitz_make_test_img $size
236ad6fe44bSHanna Reitz
237ad6fe44bSHanna Reitz# Will be used by this and the next case
238ad6fe44bSHanna Reitzset_up_throttled_qsd() {
239ad6fe44bSHanna Reitz    $QSD \
240ad6fe44bSHanna Reitz        --object throttle-group,id=thrgr,limits.bps-total=1048576 \
241ad6fe44bSHanna Reitz        --blockdev null-co,node-name=null,size=$size \
242ad6fe44bSHanna Reitz        --blockdev throttle,node-name=throttled,throttle-group=thrgr,file=null \
243ad6fe44bSHanna Reitz        --nbd-server addr.type=unix,addr.path="$SOCK_DIR/qsd.sock" \
244ad6fe44bSHanna Reitz        --export nbd,id=exp,node-name=throttled,name=target,writable=true \
245ad6fe44bSHanna Reitz        --pidfile "$TEST_DIR/qsd.pid" \
246ad6fe44bSHanna Reitz        --daemonize
247ad6fe44bSHanna Reitz}
248ad6fe44bSHanna Reitz
249ad6fe44bSHanna Reitzset_up_throttled_qsd
250ad6fe44bSHanna Reitz
251ad6fe44bSHanna Reitz# Need a virtio-blk device so that qemu-io writes will not block the monitor
252ad6fe44bSHanna Reitz_launch_qemu \
253ad6fe44bSHanna Reitz    --blockdev file,node-name=source-proto,filename="$TEST_IMG" \
254ad6fe44bSHanna Reitz    --blockdev qcow2,node-name=source-fmt,file=source-proto \
255ad6fe44bSHanna Reitz    --device virtio-blk,id=vblk,drive=source-fmt \
256ad6fe44bSHanna Reitz    --blockdev "{\"driver\": \"nbd\",
257ad6fe44bSHanna Reitz                 \"node-name\": \"target\",
258ad6fe44bSHanna Reitz                 \"server\": {
259ad6fe44bSHanna Reitz                     \"type\": \"unix\",
260ad6fe44bSHanna Reitz                     \"path\": \"$SOCK_DIR/qsd.sock\"
261ad6fe44bSHanna Reitz                 },
262ad6fe44bSHanna Reitz                 \"export\": \"target\"}"
263ad6fe44bSHanna Reitz
264ad6fe44bSHanna Reitzh=$QEMU_HANDLE
265ad6fe44bSHanna Reitz_send_qemu_cmd $h '{"execute": "qmp_capabilities"}' 'return'
266ad6fe44bSHanna Reitz
267ad6fe44bSHanna Reitz# Use sync=top, so the first pass will not copy the whole image
268ad6fe44bSHanna Reitz_send_qemu_cmd $h \
269ad6fe44bSHanna Reitz    '{"execute": "blockdev-mirror",
270ad6fe44bSHanna Reitz      "arguments": {
271ad6fe44bSHanna Reitz          "job-id": "mirror",
272ad6fe44bSHanna Reitz          "device": "source-fmt",
273ad6fe44bSHanna Reitz          "target": "target",
274ad6fe44bSHanna Reitz          "sync": "top"
275ad6fe44bSHanna Reitz      }}' \
276ad6fe44bSHanna Reitz    'return' \
277ad6fe44bSHanna Reitz    | grep -v JOB_STATUS_CHANGE # Ignore these events during creation
278ad6fe44bSHanna Reitz
279ad6fe44bSHanna Reitz# This too will be used by this and the next case
280ad6fe44bSHanna Reitz# $1: QEMU handle
281ad6fe44bSHanna Reitz# $2: Image size
282ad6fe44bSHanna Reitzwait_for_job_and_quit() {
283ad6fe44bSHanna Reitz    h=$1
284ad6fe44bSHanna Reitz    size=$2
285ad6fe44bSHanna Reitz
286ad6fe44bSHanna Reitz    # List of expected events
287ad6fe44bSHanna Reitz    capture_events='BLOCK_JOB_READY JOB_STATUS_CHANGE'
288ad6fe44bSHanna Reitz    _wait_event $h 'BLOCK_JOB_READY'
289ad6fe44bSHanna Reitz    QEMU_EVENTS= # Ignore all JOB_STATUS_CHANGE events that came before READY
290ad6fe44bSHanna Reitz
291ad6fe44bSHanna Reitz    # Write something to the device for post-READY mirroring.  Write it in
292ad6fe44bSHanna Reitz    # blocks matching the cluster size, each spaced one block apart, so
293ad6fe44bSHanna Reitz    # that the mirror job will have to spawn one request per cluster.
294ad6fe44bSHanna Reitz    # Because the number of concurrent requests is limited (to 16), this
295ad6fe44bSHanna Reitz    # limits the number of bytes concurrently in flight, which speeds up
296ad6fe44bSHanna Reitz    # cancelling the job (in-flight requests still are waited for).
297ad6fe44bSHanna Reitz    # To limit the number of bytes in flight, we could alternatively pass
298ad6fe44bSHanna Reitz    # something for blockdev-mirror's @buf-size parameter, but
299ad6fe44bSHanna Reitz    # block-commit does not have such a parameter, so we need to figure
300ad6fe44bSHanna Reitz    # something out that works for both.
301ad6fe44bSHanna Reitz
302ad6fe44bSHanna Reitz    cluster_size=65536
303ad6fe44bSHanna Reitz    step=$((cluster_size * 2))
304ad6fe44bSHanna Reitz
305ad6fe44bSHanna Reitz    echo '--- Writing data to the virtio-blk device ---'
306ad6fe44bSHanna Reitz
307ad6fe44bSHanna Reitz    for ofs in $(seq 0 $step $((size - step))); do
308ad6fe44bSHanna Reitz        qemu_io_cmd="qemu-io -d vblk/virtio-backend "
309ad6fe44bSHanna Reitz        qemu_io_cmd+="\\\"aio_write $ofs $cluster_size\\\""
310ad6fe44bSHanna Reitz
311ad6fe44bSHanna Reitz        # Do not include these requests in the reference output
312ad6fe44bSHanna Reitz        # (it's just too much)
313ad6fe44bSHanna Reitz        silent=yes _send_qemu_cmd $h \
314ad6fe44bSHanna Reitz            "{\"execute\": \"human-monitor-command\",
315ad6fe44bSHanna Reitz              \"arguments\": {
316ad6fe44bSHanna Reitz                  \"command-line\": \"$qemu_io_cmd\"
317ad6fe44bSHanna Reitz              }}" \
318ad6fe44bSHanna Reitz            'return'
319ad6fe44bSHanna Reitz    done
320ad6fe44bSHanna Reitz
321ad6fe44bSHanna Reitz    # Wait until the job's length is updated to reflect the write requests
322ad6fe44bSHanna Reitz
323ad6fe44bSHanna Reitz    # We have written to half of the device, so this is the expected job length
324ad6fe44bSHanna Reitz    final_len=$((size / 2))
325ad6fe44bSHanna Reitz    timeout=100 # unit: 0.1 seconds
326ad6fe44bSHanna Reitz    while true; do
327ad6fe44bSHanna Reitz        len=$(
328ad6fe44bSHanna Reitz            _send_qemu_cmd $h \
329ad6fe44bSHanna Reitz                '{"execute": "query-block-jobs"}' \
330ad6fe44bSHanna Reitz                'return.*"len": [0-9]\+' \
331ad6fe44bSHanna Reitz                | grep 'return.*"len": [0-9]\+' \
332ad6fe44bSHanna Reitz                | sed -e 's/.*"len": \([0-9]\+\).*/\1/'
333ad6fe44bSHanna Reitz        )
334ad6fe44bSHanna Reitz        if [ "$len" -eq "$final_len" ]; then
335ad6fe44bSHanna Reitz            break
336ad6fe44bSHanna Reitz        fi
337ad6fe44bSHanna Reitz        timeout=$((timeout - 1))
338ad6fe44bSHanna Reitz        if [ "$timeout" -eq 0 ]; then
339ad6fe44bSHanna Reitz            echo "ERROR: Timeout waiting for job to reach len=$final_len"
340ad6fe44bSHanna Reitz            break
341ad6fe44bSHanna Reitz        fi
342ad6fe44bSHanna Reitz        sleep 0.1
343ad6fe44bSHanna Reitz    done
344ad6fe44bSHanna Reitz
345ad6fe44bSHanna Reitz    sleep 1
346ad6fe44bSHanna Reitz
347*f389309dSStefan Hajnoczi    # List of expected events
348*f389309dSStefan Hajnoczi    capture_events='BLOCK_JOB_CANCELLED JOB_STATUS_CHANGE SHUTDOWN'
349*f389309dSStefan Hajnoczi
350ad6fe44bSHanna Reitz    _send_qemu_cmd $h \
351ad6fe44bSHanna Reitz        '{"execute": "quit"}' \
352ad6fe44bSHanna Reitz        'return'
353ad6fe44bSHanna Reitz
354ad6fe44bSHanna Reitz    _wait_event $h 'SHUTDOWN'
355ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # standby
356ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # ready
35765c23ef1SFiona Ebner    _wait_event $h 'JOB_STATUS_CHANGE' # standby
35865c23ef1SFiona Ebner    _wait_event $h 'JOB_STATUS_CHANGE' # ready
359ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # aborting
360ad6fe44bSHanna Reitz    # Filter the offset (depends on when exactly `quit` was issued)
361ad6fe44bSHanna Reitz    _wait_event $h 'BLOCK_JOB_CANCELLED' \
362ad6fe44bSHanna Reitz        | sed -e 's/"offset": [0-9]\+/"offset": (filtered)/'
363ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # concluded
364ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # null
365ad6fe44bSHanna Reitz
366ad6fe44bSHanna Reitz    wait=yes _cleanup_qemu
367ad6fe44bSHanna Reitz
368ad6fe44bSHanna Reitz    kill -SIGTERM "$(cat "$TEST_DIR/qsd.pid")"
369ad6fe44bSHanna Reitz}
370ad6fe44bSHanna Reitz
371ad6fe44bSHanna Reitzwait_for_job_and_quit $h $size
372ad6fe44bSHanna Reitz
373ad6fe44bSHanna Reitzecho
374ad6fe44bSHanna Reitzecho === Start active commit to throttled QSD and exit qemu ===
375ad6fe44bSHanna Reitzecho
376ad6fe44bSHanna Reitz
377ad6fe44bSHanna Reitz# Same as the above, but instead of mirroring, do an active commit
378ad6fe44bSHanna Reitz
379ad6fe44bSHanna Reitz_make_test_img $size
380ad6fe44bSHanna Reitz
381ad6fe44bSHanna Reitzset_up_throttled_qsd
382ad6fe44bSHanna Reitz
383ad6fe44bSHanna Reitz_launch_qemu \
384ad6fe44bSHanna Reitz    --blockdev "{\"driver\": \"nbd\",
385ad6fe44bSHanna Reitz                 \"node-name\": \"target\",
386ad6fe44bSHanna Reitz                 \"server\": {
387ad6fe44bSHanna Reitz                     \"type\": \"unix\",
388ad6fe44bSHanna Reitz                     \"path\": \"$SOCK_DIR/qsd.sock\"
389ad6fe44bSHanna Reitz                 },
390ad6fe44bSHanna Reitz                 \"export\": \"target\"}" \
391ad6fe44bSHanna Reitz    --blockdev file,node-name=source-proto,filename="$TEST_IMG" \
392ad6fe44bSHanna Reitz    --blockdev qcow2,node-name=source-fmt,file=source-proto,backing=target \
393ad6fe44bSHanna Reitz    --device virtio-blk,id=vblk,drive=source-fmt
394ad6fe44bSHanna Reitz
395ad6fe44bSHanna Reitzh=$QEMU_HANDLE
396ad6fe44bSHanna Reitz_send_qemu_cmd $h '{"execute": "qmp_capabilities"}' 'return'
397ad6fe44bSHanna Reitz
398ad6fe44bSHanna Reitz_send_qemu_cmd $h \
399ad6fe44bSHanna Reitz    '{"execute": "block-commit",
400ad6fe44bSHanna Reitz      "arguments": {
401ad6fe44bSHanna Reitz          "job-id": "commit",
402ad6fe44bSHanna Reitz          "device": "source-fmt"
403ad6fe44bSHanna Reitz      }}' \
404ad6fe44bSHanna Reitz    'return' \
405ad6fe44bSHanna Reitz    | grep -v JOB_STATUS_CHANGE # Ignore these events during creation
406ad6fe44bSHanna Reitz
407ad6fe44bSHanna Reitzwait_for_job_and_quit $h $size
408ad6fe44bSHanna Reitz
40924575bfaSKevin Wolf# success, all done
41024575bfaSKevin Wolfecho "*** done"
41124575bfaSKevin Wolfrm -f $seq.full
41224575bfaSKevin Wolfstatus=0
413