xref: /openbmc/qemu/tests/qemu-iotests/185 (revision ad6fe44bea25e9b0efe050d00751466ad2779631)
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
36*ad6fe44bSHanna Reitz
37*ad6fe44bSHanna Reitz    if [ -f "$TEST_DIR/qsd.pid" ]; then
38*ad6fe44bSHanna Reitz        kill -SIGKILL "$(cat "$TEST_DIR/qsd.pid")"
39*ad6fe44bSHanna Reitz        rm -f "$TEST_DIR/qsd.pid"
40*ad6fe44bSHanna Reitz    fi
41*ad6fe44bSHanna 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
54*ad6fe44bSHanna 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
225*ad6fe44bSHanna Reitzecho
226*ad6fe44bSHanna Reitzecho === Start mirror to throttled QSD and exit qemu ===
227*ad6fe44bSHanna Reitzecho
228*ad6fe44bSHanna Reitz
229*ad6fe44bSHanna Reitz# Mirror to a throttled QSD instance (so that qemu cannot drain the
230*ad6fe44bSHanna Reitz# throttling), wait for READY, then write some data to the device,
231*ad6fe44bSHanna Reitz# and then quit qemu.
232*ad6fe44bSHanna Reitz# (qemu should force-cancel the job and not wait for the data to be
233*ad6fe44bSHanna Reitz# written to the target.)
234*ad6fe44bSHanna Reitz
235*ad6fe44bSHanna Reitz_make_test_img $size
236*ad6fe44bSHanna Reitz
237*ad6fe44bSHanna Reitz# Will be used by this and the next case
238*ad6fe44bSHanna Reitzset_up_throttled_qsd() {
239*ad6fe44bSHanna Reitz    $QSD \
240*ad6fe44bSHanna Reitz        --object throttle-group,id=thrgr,limits.bps-total=1048576 \
241*ad6fe44bSHanna Reitz        --blockdev null-co,node-name=null,size=$size \
242*ad6fe44bSHanna Reitz        --blockdev throttle,node-name=throttled,throttle-group=thrgr,file=null \
243*ad6fe44bSHanna Reitz        --nbd-server addr.type=unix,addr.path="$SOCK_DIR/qsd.sock" \
244*ad6fe44bSHanna Reitz        --export nbd,id=exp,node-name=throttled,name=target,writable=true \
245*ad6fe44bSHanna Reitz        --pidfile "$TEST_DIR/qsd.pid" \
246*ad6fe44bSHanna Reitz        --daemonize
247*ad6fe44bSHanna Reitz}
248*ad6fe44bSHanna Reitz
249*ad6fe44bSHanna Reitzset_up_throttled_qsd
250*ad6fe44bSHanna Reitz
251*ad6fe44bSHanna Reitz# Need a virtio-blk device so that qemu-io writes will not block the monitor
252*ad6fe44bSHanna Reitz_launch_qemu \
253*ad6fe44bSHanna Reitz    --blockdev file,node-name=source-proto,filename="$TEST_IMG" \
254*ad6fe44bSHanna Reitz    --blockdev qcow2,node-name=source-fmt,file=source-proto \
255*ad6fe44bSHanna Reitz    --device virtio-blk,id=vblk,drive=source-fmt \
256*ad6fe44bSHanna Reitz    --blockdev "{\"driver\": \"nbd\",
257*ad6fe44bSHanna Reitz                 \"node-name\": \"target\",
258*ad6fe44bSHanna Reitz                 \"server\": {
259*ad6fe44bSHanna Reitz                     \"type\": \"unix\",
260*ad6fe44bSHanna Reitz                     \"path\": \"$SOCK_DIR/qsd.sock\"
261*ad6fe44bSHanna Reitz                 },
262*ad6fe44bSHanna Reitz                 \"export\": \"target\"}"
263*ad6fe44bSHanna Reitz
264*ad6fe44bSHanna Reitzh=$QEMU_HANDLE
265*ad6fe44bSHanna Reitz_send_qemu_cmd $h '{"execute": "qmp_capabilities"}' 'return'
266*ad6fe44bSHanna Reitz
267*ad6fe44bSHanna Reitz# Use sync=top, so the first pass will not copy the whole image
268*ad6fe44bSHanna Reitz_send_qemu_cmd $h \
269*ad6fe44bSHanna Reitz    '{"execute": "blockdev-mirror",
270*ad6fe44bSHanna Reitz      "arguments": {
271*ad6fe44bSHanna Reitz          "job-id": "mirror",
272*ad6fe44bSHanna Reitz          "device": "source-fmt",
273*ad6fe44bSHanna Reitz          "target": "target",
274*ad6fe44bSHanna Reitz          "sync": "top"
275*ad6fe44bSHanna Reitz      }}' \
276*ad6fe44bSHanna Reitz    'return' \
277*ad6fe44bSHanna Reitz    | grep -v JOB_STATUS_CHANGE # Ignore these events during creation
278*ad6fe44bSHanna Reitz
279*ad6fe44bSHanna Reitz# This too will be used by this and the next case
280*ad6fe44bSHanna Reitz# $1: QEMU handle
281*ad6fe44bSHanna Reitz# $2: Image size
282*ad6fe44bSHanna Reitzwait_for_job_and_quit() {
283*ad6fe44bSHanna Reitz    h=$1
284*ad6fe44bSHanna Reitz    size=$2
285*ad6fe44bSHanna Reitz
286*ad6fe44bSHanna Reitz    # List of expected events
287*ad6fe44bSHanna Reitz    capture_events='BLOCK_JOB_READY JOB_STATUS_CHANGE'
288*ad6fe44bSHanna Reitz    _wait_event $h 'BLOCK_JOB_READY'
289*ad6fe44bSHanna Reitz    QEMU_EVENTS= # Ignore all JOB_STATUS_CHANGE events that came before READY
290*ad6fe44bSHanna Reitz
291*ad6fe44bSHanna Reitz    # Write something to the device for post-READY mirroring.  Write it in
292*ad6fe44bSHanna Reitz    # blocks matching the cluster size, each spaced one block apart, so
293*ad6fe44bSHanna Reitz    # that the mirror job will have to spawn one request per cluster.
294*ad6fe44bSHanna Reitz    # Because the number of concurrent requests is limited (to 16), this
295*ad6fe44bSHanna Reitz    # limits the number of bytes concurrently in flight, which speeds up
296*ad6fe44bSHanna Reitz    # cancelling the job (in-flight requests still are waited for).
297*ad6fe44bSHanna Reitz    # To limit the number of bytes in flight, we could alternatively pass
298*ad6fe44bSHanna Reitz    # something for blockdev-mirror's @buf-size parameter, but
299*ad6fe44bSHanna Reitz    # block-commit does not have such a parameter, so we need to figure
300*ad6fe44bSHanna Reitz    # something out that works for both.
301*ad6fe44bSHanna Reitz
302*ad6fe44bSHanna Reitz    cluster_size=65536
303*ad6fe44bSHanna Reitz    step=$((cluster_size * 2))
304*ad6fe44bSHanna Reitz
305*ad6fe44bSHanna Reitz    echo '--- Writing data to the virtio-blk device ---'
306*ad6fe44bSHanna Reitz
307*ad6fe44bSHanna Reitz    for ofs in $(seq 0 $step $((size - step))); do
308*ad6fe44bSHanna Reitz        qemu_io_cmd="qemu-io -d vblk/virtio-backend "
309*ad6fe44bSHanna Reitz        qemu_io_cmd+="\\\"aio_write $ofs $cluster_size\\\""
310*ad6fe44bSHanna Reitz
311*ad6fe44bSHanna Reitz        # Do not include these requests in the reference output
312*ad6fe44bSHanna Reitz        # (it's just too much)
313*ad6fe44bSHanna Reitz        silent=yes _send_qemu_cmd $h \
314*ad6fe44bSHanna Reitz            "{\"execute\": \"human-monitor-command\",
315*ad6fe44bSHanna Reitz              \"arguments\": {
316*ad6fe44bSHanna Reitz                  \"command-line\": \"$qemu_io_cmd\"
317*ad6fe44bSHanna Reitz              }}" \
318*ad6fe44bSHanna Reitz            'return'
319*ad6fe44bSHanna Reitz    done
320*ad6fe44bSHanna Reitz
321*ad6fe44bSHanna Reitz    # Wait until the job's length is updated to reflect the write requests
322*ad6fe44bSHanna Reitz
323*ad6fe44bSHanna Reitz    # We have written to half of the device, so this is the expected job length
324*ad6fe44bSHanna Reitz    final_len=$((size / 2))
325*ad6fe44bSHanna Reitz    timeout=100 # unit: 0.1 seconds
326*ad6fe44bSHanna Reitz    while true; do
327*ad6fe44bSHanna Reitz        len=$(
328*ad6fe44bSHanna Reitz            _send_qemu_cmd $h \
329*ad6fe44bSHanna Reitz                '{"execute": "query-block-jobs"}' \
330*ad6fe44bSHanna Reitz                'return.*"len": [0-9]\+' \
331*ad6fe44bSHanna Reitz                | grep 'return.*"len": [0-9]\+' \
332*ad6fe44bSHanna Reitz                | sed -e 's/.*"len": \([0-9]\+\).*/\1/'
333*ad6fe44bSHanna Reitz        )
334*ad6fe44bSHanna Reitz        if [ "$len" -eq "$final_len" ]; then
335*ad6fe44bSHanna Reitz            break
336*ad6fe44bSHanna Reitz        fi
337*ad6fe44bSHanna Reitz        timeout=$((timeout - 1))
338*ad6fe44bSHanna Reitz        if [ "$timeout" -eq 0 ]; then
339*ad6fe44bSHanna Reitz            echo "ERROR: Timeout waiting for job to reach len=$final_len"
340*ad6fe44bSHanna Reitz            break
341*ad6fe44bSHanna Reitz        fi
342*ad6fe44bSHanna Reitz        sleep 0.1
343*ad6fe44bSHanna Reitz    done
344*ad6fe44bSHanna Reitz
345*ad6fe44bSHanna Reitz    sleep 1
346*ad6fe44bSHanna Reitz
347*ad6fe44bSHanna Reitz    _send_qemu_cmd $h \
348*ad6fe44bSHanna Reitz        '{"execute": "quit"}' \
349*ad6fe44bSHanna Reitz        'return'
350*ad6fe44bSHanna Reitz
351*ad6fe44bSHanna Reitz    # List of expected events
352*ad6fe44bSHanna Reitz    capture_events='BLOCK_JOB_CANCELLED JOB_STATUS_CHANGE SHUTDOWN'
353*ad6fe44bSHanna Reitz    _wait_event $h 'SHUTDOWN'
354*ad6fe44bSHanna Reitz    QEMU_EVENTS= # Ignore all JOB_STATUS_CHANGE events that came before SHUTDOWN
355*ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # standby
356*ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # ready
357*ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # aborting
358*ad6fe44bSHanna Reitz    # Filter the offset (depends on when exactly `quit` was issued)
359*ad6fe44bSHanna Reitz    _wait_event $h 'BLOCK_JOB_CANCELLED' \
360*ad6fe44bSHanna Reitz        | sed -e 's/"offset": [0-9]\+/"offset": (filtered)/'
361*ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # concluded
362*ad6fe44bSHanna Reitz    _wait_event $h 'JOB_STATUS_CHANGE' # null
363*ad6fe44bSHanna Reitz
364*ad6fe44bSHanna Reitz    wait=yes _cleanup_qemu
365*ad6fe44bSHanna Reitz
366*ad6fe44bSHanna Reitz    kill -SIGTERM "$(cat "$TEST_DIR/qsd.pid")"
367*ad6fe44bSHanna Reitz}
368*ad6fe44bSHanna Reitz
369*ad6fe44bSHanna Reitzwait_for_job_and_quit $h $size
370*ad6fe44bSHanna Reitz
371*ad6fe44bSHanna Reitzecho
372*ad6fe44bSHanna Reitzecho === Start active commit to throttled QSD and exit qemu ===
373*ad6fe44bSHanna Reitzecho
374*ad6fe44bSHanna Reitz
375*ad6fe44bSHanna Reitz# Same as the above, but instead of mirroring, do an active commit
376*ad6fe44bSHanna Reitz
377*ad6fe44bSHanna Reitz_make_test_img $size
378*ad6fe44bSHanna Reitz
379*ad6fe44bSHanna Reitzset_up_throttled_qsd
380*ad6fe44bSHanna Reitz
381*ad6fe44bSHanna Reitz_launch_qemu \
382*ad6fe44bSHanna Reitz    --blockdev "{\"driver\": \"nbd\",
383*ad6fe44bSHanna Reitz                 \"node-name\": \"target\",
384*ad6fe44bSHanna Reitz                 \"server\": {
385*ad6fe44bSHanna Reitz                     \"type\": \"unix\",
386*ad6fe44bSHanna Reitz                     \"path\": \"$SOCK_DIR/qsd.sock\"
387*ad6fe44bSHanna Reitz                 },
388*ad6fe44bSHanna Reitz                 \"export\": \"target\"}" \
389*ad6fe44bSHanna Reitz    --blockdev file,node-name=source-proto,filename="$TEST_IMG" \
390*ad6fe44bSHanna Reitz    --blockdev qcow2,node-name=source-fmt,file=source-proto,backing=target \
391*ad6fe44bSHanna Reitz    --device virtio-blk,id=vblk,drive=source-fmt
392*ad6fe44bSHanna Reitz
393*ad6fe44bSHanna Reitzh=$QEMU_HANDLE
394*ad6fe44bSHanna Reitz_send_qemu_cmd $h '{"execute": "qmp_capabilities"}' 'return'
395*ad6fe44bSHanna Reitz
396*ad6fe44bSHanna Reitz_send_qemu_cmd $h \
397*ad6fe44bSHanna Reitz    '{"execute": "block-commit",
398*ad6fe44bSHanna Reitz      "arguments": {
399*ad6fe44bSHanna Reitz          "job-id": "commit",
400*ad6fe44bSHanna Reitz          "device": "source-fmt"
401*ad6fe44bSHanna Reitz      }}' \
402*ad6fe44bSHanna Reitz    'return' \
403*ad6fe44bSHanna Reitz    | grep -v JOB_STATUS_CHANGE # Ignore these events during creation
404*ad6fe44bSHanna Reitz
405*ad6fe44bSHanna Reitzwait_for_job_and_quit $h $size
406*ad6fe44bSHanna Reitz
40724575bfaSKevin Wolf# success, all done
40824575bfaSKevin Wolfecho "*** done"
40924575bfaSKevin Wolfrm -f $seq.full
41024575bfaSKevin Wolfstatus=0
411