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 95*c1de5696SStefan Hajnoczi# BLOCK_JOB_* events for all of the following block jobs. They are predictable 96*c1de5696SStefan 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# 104*c1de5696SStefan Hajnoczi# Jobs present while QEMU is terminating iterate once more due to 105*c1de5696SStefan Hajnoczi# bdrv_drain_all(). 106*c1de5696SStefan Hajnoczi# 10724575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after 10824575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover 10924575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is 11024575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the 111*c1de5696SStefan Hajnoczi# offset advances exactly twice before qemu exits. 11224575bfaSKevin Wolf 11324575bfaSKevin Wolf_send_qemu_cmd $h \ 11424575bfaSKevin Wolf "{ 'execute': 'block-commit', 11524575bfaSKevin Wolf 'arguments': { 'device': 'disk', 11624575bfaSKevin Wolf 'base':'$TEST_IMG.base', 11724575bfaSKevin Wolf 'top': '$TEST_IMG.mid', 11824575bfaSKevin Wolf 'speed': 65536 } }" \ 11924575bfaSKevin Wolf "return" 12024575bfaSKevin Wolf 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 14024575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 14124575bfaSKevin Wolfwait=1 _cleanup_qemu 14224575bfaSKevin Wolf 14324575bfaSKevin Wolfecho 14424575bfaSKevin Wolfecho === Start mirror job and exit qemu === 14524575bfaSKevin Wolfecho 14624575bfaSKevin Wolf 14724575bfaSKevin Wolf_launch_qemu \ 14824575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 14924575bfaSKevin Wolfh=$QEMU_HANDLE 15024575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 15124575bfaSKevin Wolf 15224575bfaSKevin Wolf_send_qemu_cmd $h \ 15324575bfaSKevin Wolf "{ 'execute': 'drive-mirror', 15424575bfaSKevin Wolf 'arguments': { 'device': 'disk', 15524575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 15624575bfaSKevin Wolf 'format': '$IMGFMT', 15724575bfaSKevin Wolf 'sync': 'full', 15824575bfaSKevin Wolf 'speed': 65536 } }" \ 15924575bfaSKevin Wolf "return" 16024575bfaSKevin Wolf 1618565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before 1628565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done 1638565c3abSVladimir Sementsov-Ogievskiysleep 0.5 1648565c3abSVladimir Sementsov-Ogievskiy 16524575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 16624575bfaSKevin Wolfwait=1 _cleanup_qemu 16724575bfaSKevin Wolf 16824575bfaSKevin Wolfecho 16924575bfaSKevin Wolfecho === Start backup job and exit qemu === 17024575bfaSKevin Wolfecho 17124575bfaSKevin Wolf 17224575bfaSKevin Wolf_launch_qemu \ 17324575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 17424575bfaSKevin Wolfh=$QEMU_HANDLE 17524575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 17624575bfaSKevin Wolf 17724575bfaSKevin Wolf_send_qemu_cmd $h \ 17824575bfaSKevin Wolf "{ 'execute': 'drive-backup', 17924575bfaSKevin Wolf 'arguments': { 'device': 'disk', 18024575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 18124575bfaSKevin Wolf 'format': '$IMGFMT', 18224575bfaSKevin Wolf 'sync': 'full', 18324575bfaSKevin Wolf 'speed': 65536 } }" \ 18424575bfaSKevin Wolf "return" 18524575bfaSKevin Wolf 18624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 18724575bfaSKevin Wolfwait=1 _cleanup_qemu 18824575bfaSKevin Wolf 18924575bfaSKevin Wolfecho 19024575bfaSKevin Wolfecho === Start streaming job and exit qemu === 19124575bfaSKevin Wolfecho 19224575bfaSKevin Wolf 19324575bfaSKevin Wolf_launch_qemu \ 19424575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 19524575bfaSKevin Wolfh=$QEMU_HANDLE 19624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 19724575bfaSKevin Wolf 19824575bfaSKevin Wolf_send_qemu_cmd $h \ 19924575bfaSKevin Wolf "{ 'execute': 'block-stream', 20024575bfaSKevin Wolf 'arguments': { 'device': 'disk', 20124575bfaSKevin Wolf 'speed': 65536 } }" \ 20224575bfaSKevin Wolf "return" 20324575bfaSKevin Wolf 20424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 20524575bfaSKevin Wolfwait=1 _cleanup_qemu 20624575bfaSKevin Wolf 20724575bfaSKevin Wolf_check_test_img 20824575bfaSKevin Wolf 20924575bfaSKevin Wolf# success, all done 21024575bfaSKevin Wolfecho "*** done" 21124575bfaSKevin Wolfrm -f $seq.full 21224575bfaSKevin Wolfstatus=0 213