124575bfaSKevin Wolf#!/bin/bash 224575bfaSKevin Wolf# 324575bfaSKevin Wolf# Test exiting qemu while jobs are still running 424575bfaSKevin Wolf# 524575bfaSKevin Wolf# Copyright (C) 2017 Red Hat, Inc. 624575bfaSKevin Wolf# 724575bfaSKevin Wolf# This program is free software; you can redistribute it and/or modify 824575bfaSKevin Wolf# it under the terms of the GNU General Public License as published by 924575bfaSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1024575bfaSKevin Wolf# (at your option) any later version. 1124575bfaSKevin Wolf# 1224575bfaSKevin Wolf# This program is distributed in the hope that it will be useful, 1324575bfaSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1424575bfaSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1524575bfaSKevin Wolf# GNU General Public License for more details. 1624575bfaSKevin Wolf# 1724575bfaSKevin Wolf# You should have received a copy of the GNU General Public License 1824575bfaSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 1924575bfaSKevin Wolf# 2024575bfaSKevin Wolf 2124575bfaSKevin Wolf# creator 2224575bfaSKevin Wolfowner=kwolf@redhat.com 2324575bfaSKevin Wolf 2424575bfaSKevin Wolfseq=`basename $0` 2524575bfaSKevin Wolfecho "QA output created by $seq" 2624575bfaSKevin Wolf 2724575bfaSKevin Wolfhere=`pwd` 2824575bfaSKevin Wolfstatus=1 # failure is the default! 2924575bfaSKevin Wolf 3024575bfaSKevin WolfMIG_SOCKET="${TEST_DIR}/migrate" 3124575bfaSKevin Wolf 3224575bfaSKevin Wolf_cleanup() 3324575bfaSKevin Wolf{ 3424575bfaSKevin Wolf rm -f "${TEST_IMG}.mid" 3524575bfaSKevin Wolf rm -f "${TEST_IMG}.copy" 3624575bfaSKevin Wolf _cleanup_test_img 3724575bfaSKevin Wolf _cleanup_qemu 3824575bfaSKevin Wolf} 3924575bfaSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 4024575bfaSKevin Wolf 4124575bfaSKevin Wolf# get standard environment, filters and checks 4224575bfaSKevin Wolf. ./common.rc 4324575bfaSKevin Wolf. ./common.filter 4424575bfaSKevin Wolf. ./common.qemu 4524575bfaSKevin Wolf 4624575bfaSKevin Wolf_supported_fmt qcow2 4724575bfaSKevin Wolf_supported_proto file 4824575bfaSKevin Wolf_supported_os Linux 4924575bfaSKevin Wolf 5024575bfaSKevin Wolfsize=64M 5124575bfaSKevin WolfTEST_IMG="${TEST_IMG}.base" _make_test_img $size 5224575bfaSKevin Wolf 5324575bfaSKevin Wolfecho 5424575bfaSKevin Wolfecho === Starting VM === 5524575bfaSKevin Wolfecho 5624575bfaSKevin Wolf 5724575bfaSKevin Wolfqemu_comm_method="qmp" 5824575bfaSKevin Wolf 5924575bfaSKevin Wolf_launch_qemu \ 6024575bfaSKevin Wolf -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk 6124575bfaSKevin Wolfh=$QEMU_HANDLE 6224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 6324575bfaSKevin Wolf 6424575bfaSKevin Wolfecho 6524575bfaSKevin Wolfecho === Creating backing chain === 6624575bfaSKevin Wolfecho 6724575bfaSKevin Wolf 6824575bfaSKevin Wolf_send_qemu_cmd $h \ 6924575bfaSKevin Wolf "{ 'execute': 'blockdev-snapshot-sync', 7024575bfaSKevin Wolf 'arguments': { 'device': 'disk', 7124575bfaSKevin Wolf 'snapshot-file': '$TEST_IMG.mid', 7224575bfaSKevin Wolf 'format': '$IMGFMT', 7324575bfaSKevin Wolf 'mode': 'absolute-paths' } }" \ 7424575bfaSKevin Wolf "return" 7524575bfaSKevin Wolf 7624575bfaSKevin Wolf_send_qemu_cmd $h \ 7724575bfaSKevin Wolf "{ 'execute': 'human-monitor-command', 7824575bfaSKevin Wolf 'arguments': { 'command-line': 7924575bfaSKevin Wolf 'qemu-io disk \"write 0 4M\"' } }" \ 8024575bfaSKevin Wolf "return" 8124575bfaSKevin Wolf 8224575bfaSKevin Wolf_send_qemu_cmd $h \ 8324575bfaSKevin Wolf "{ 'execute': 'blockdev-snapshot-sync', 8424575bfaSKevin Wolf 'arguments': { 'device': 'disk', 8524575bfaSKevin Wolf 'snapshot-file': '$TEST_IMG', 8624575bfaSKevin Wolf 'format': '$IMGFMT', 8724575bfaSKevin Wolf 'mode': 'absolute-paths' } }" \ 8824575bfaSKevin Wolf "return" 8924575bfaSKevin Wolf 9024575bfaSKevin Wolfecho 9124575bfaSKevin Wolfecho === Start commit job and exit qemu === 9224575bfaSKevin Wolfecho 9324575bfaSKevin Wolf 9424575bfaSKevin Wolf# Note that the reference output intentionally includes the 'offset' field in 95c1de5696SStefan Hajnoczi# BLOCK_JOB_* events for all of the following block jobs. They are predictable 96c1de5696SStefan Hajnoczi# and any change in the offsets would hint at a bug in the job throttling code. 9724575bfaSKevin Wolf# 9824575bfaSKevin Wolf# In order to achieve these predictable offsets, all of the following tests 9924575bfaSKevin Wolf# use speed=65536. Each job will perform exactly one iteration before it has 10024575bfaSKevin Wolf# to sleep at least for a second, which is plenty of time for the 'quit' QMP 10124575bfaSKevin Wolf# command to be received (after receiving the command, the rest runs 10224575bfaSKevin Wolf# synchronously, so jobs can arbitrarily continue or complete). 10324575bfaSKevin Wolf# 10424575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after 10524575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover 10624575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is 10724575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the 108*4c7e813cSStefan Hajnoczi# offset advances exactly once before qemu exits. 10924575bfaSKevin Wolf 11024575bfaSKevin Wolf_send_qemu_cmd $h \ 11124575bfaSKevin Wolf "{ 'execute': 'block-commit', 11224575bfaSKevin Wolf 'arguments': { 'device': 'disk', 11324575bfaSKevin Wolf 'base':'$TEST_IMG.base', 11424575bfaSKevin Wolf 'top': '$TEST_IMG.mid', 11524575bfaSKevin Wolf 'speed': 65536 } }" \ 11624575bfaSKevin Wolf "return" 11724575bfaSKevin Wolf 118ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 119ddf2d98aSStefan Hajnoczisleep 0.5 120ddf2d98aSStefan Hajnoczi 12124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 12224575bfaSKevin Wolfwait=1 _cleanup_qemu 12324575bfaSKevin Wolf 12424575bfaSKevin Wolfecho 12524575bfaSKevin Wolfecho === Start active commit job and exit qemu === 12624575bfaSKevin Wolfecho 12724575bfaSKevin Wolf 12824575bfaSKevin Wolf_launch_qemu \ 12924575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 13024575bfaSKevin Wolfh=$QEMU_HANDLE 13124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 13224575bfaSKevin Wolf 13324575bfaSKevin Wolf_send_qemu_cmd $h \ 13424575bfaSKevin Wolf "{ 'execute': 'block-commit', 13524575bfaSKevin Wolf 'arguments': { 'device': 'disk', 13624575bfaSKevin Wolf 'base':'$TEST_IMG.base', 13724575bfaSKevin Wolf 'speed': 65536 } }" \ 13824575bfaSKevin Wolf "return" 13924575bfaSKevin Wolf 140ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 141ddf2d98aSStefan Hajnoczisleep 0.5 142ddf2d98aSStefan Hajnoczi 14324575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 14424575bfaSKevin Wolfwait=1 _cleanup_qemu 14524575bfaSKevin Wolf 14624575bfaSKevin Wolfecho 14724575bfaSKevin Wolfecho === Start mirror job and exit qemu === 14824575bfaSKevin Wolfecho 14924575bfaSKevin Wolf 15024575bfaSKevin Wolf_launch_qemu \ 15124575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 15224575bfaSKevin Wolfh=$QEMU_HANDLE 15324575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 15424575bfaSKevin Wolf 15524575bfaSKevin Wolf_send_qemu_cmd $h \ 15624575bfaSKevin Wolf "{ 'execute': 'drive-mirror', 15724575bfaSKevin Wolf 'arguments': { 'device': 'disk', 15824575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 15924575bfaSKevin Wolf 'format': '$IMGFMT', 16024575bfaSKevin Wolf 'sync': 'full', 16124575bfaSKevin Wolf 'speed': 65536 } }" \ 16224575bfaSKevin Wolf "return" 16324575bfaSKevin Wolf 1648565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before 1658565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done 1668565c3abSVladimir Sementsov-Ogievskiysleep 0.5 1678565c3abSVladimir Sementsov-Ogievskiy 16824575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 16924575bfaSKevin Wolfwait=1 _cleanup_qemu 17024575bfaSKevin Wolf 17124575bfaSKevin Wolfecho 17224575bfaSKevin Wolfecho === Start backup job and exit qemu === 17324575bfaSKevin Wolfecho 17424575bfaSKevin Wolf 17524575bfaSKevin Wolf_launch_qemu \ 17624575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 17724575bfaSKevin Wolfh=$QEMU_HANDLE 17824575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 17924575bfaSKevin Wolf 18024575bfaSKevin Wolf_send_qemu_cmd $h \ 18124575bfaSKevin Wolf "{ 'execute': 'drive-backup', 18224575bfaSKevin Wolf 'arguments': { 'device': 'disk', 18324575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 18424575bfaSKevin Wolf 'format': '$IMGFMT', 18524575bfaSKevin Wolf 'sync': 'full', 18624575bfaSKevin Wolf 'speed': 65536 } }" \ 18724575bfaSKevin Wolf "return" 18824575bfaSKevin Wolf 189ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 190ddf2d98aSStefan Hajnoczisleep 0.5 191ddf2d98aSStefan Hajnoczi 19224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 19324575bfaSKevin Wolfwait=1 _cleanup_qemu 19424575bfaSKevin Wolf 19524575bfaSKevin Wolfecho 19624575bfaSKevin Wolfecho === Start streaming job and exit qemu === 19724575bfaSKevin Wolfecho 19824575bfaSKevin Wolf 19924575bfaSKevin Wolf_launch_qemu \ 20024575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 20124575bfaSKevin Wolfh=$QEMU_HANDLE 20224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 20324575bfaSKevin Wolf 20424575bfaSKevin Wolf_send_qemu_cmd $h \ 20524575bfaSKevin Wolf "{ 'execute': 'block-stream', 20624575bfaSKevin Wolf 'arguments': { 'device': 'disk', 20724575bfaSKevin Wolf 'speed': 65536 } }" \ 20824575bfaSKevin Wolf "return" 20924575bfaSKevin Wolf 210ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 211ddf2d98aSStefan Hajnoczisleep 0.5 212ddf2d98aSStefan Hajnoczi 21324575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 21424575bfaSKevin Wolfwait=1 _cleanup_qemu 21524575bfaSKevin Wolf 21624575bfaSKevin Wolf_check_test_img 21724575bfaSKevin Wolf 21824575bfaSKevin Wolf# success, all done 21924575bfaSKevin Wolfecho "*** done" 22024575bfaSKevin Wolfrm -f $seq.full 22124575bfaSKevin Wolfstatus=0 222