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# 104c1de5696SStefan Hajnoczi# Jobs present while QEMU is terminating iterate once more due to 105c1de5696SStefan Hajnoczi# bdrv_drain_all(). 106c1de5696SStefan 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 111c1de5696SStefan 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 121*ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 122*ddf2d98aSStefan Hajnoczisleep 0.5 123*ddf2d98aSStefan Hajnoczi 12424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 12524575bfaSKevin Wolfwait=1 _cleanup_qemu 12624575bfaSKevin Wolf 12724575bfaSKevin Wolfecho 12824575bfaSKevin Wolfecho === Start active commit job and exit qemu === 12924575bfaSKevin Wolfecho 13024575bfaSKevin Wolf 13124575bfaSKevin Wolf_launch_qemu \ 13224575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 13324575bfaSKevin Wolfh=$QEMU_HANDLE 13424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 13524575bfaSKevin Wolf 13624575bfaSKevin Wolf_send_qemu_cmd $h \ 13724575bfaSKevin Wolf "{ 'execute': 'block-commit', 13824575bfaSKevin Wolf 'arguments': { 'device': 'disk', 13924575bfaSKevin Wolf 'base':'$TEST_IMG.base', 14024575bfaSKevin Wolf 'speed': 65536 } }" \ 14124575bfaSKevin Wolf "return" 14224575bfaSKevin Wolf 143*ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 144*ddf2d98aSStefan Hajnoczisleep 0.5 145*ddf2d98aSStefan Hajnoczi 14624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 14724575bfaSKevin Wolfwait=1 _cleanup_qemu 14824575bfaSKevin Wolf 14924575bfaSKevin Wolfecho 15024575bfaSKevin Wolfecho === Start mirror job and exit qemu === 15124575bfaSKevin Wolfecho 15224575bfaSKevin Wolf 15324575bfaSKevin Wolf_launch_qemu \ 15424575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 15524575bfaSKevin Wolfh=$QEMU_HANDLE 15624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 15724575bfaSKevin Wolf 15824575bfaSKevin Wolf_send_qemu_cmd $h \ 15924575bfaSKevin Wolf "{ 'execute': 'drive-mirror', 16024575bfaSKevin Wolf 'arguments': { 'device': 'disk', 16124575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 16224575bfaSKevin Wolf 'format': '$IMGFMT', 16324575bfaSKevin Wolf 'sync': 'full', 16424575bfaSKevin Wolf 'speed': 65536 } }" \ 16524575bfaSKevin Wolf "return" 16624575bfaSKevin Wolf 1678565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before 1688565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done 1698565c3abSVladimir Sementsov-Ogievskiysleep 0.5 1708565c3abSVladimir Sementsov-Ogievskiy 17124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 17224575bfaSKevin Wolfwait=1 _cleanup_qemu 17324575bfaSKevin Wolf 17424575bfaSKevin Wolfecho 17524575bfaSKevin Wolfecho === Start backup job and exit qemu === 17624575bfaSKevin Wolfecho 17724575bfaSKevin Wolf 17824575bfaSKevin Wolf_launch_qemu \ 17924575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 18024575bfaSKevin Wolfh=$QEMU_HANDLE 18124575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 18224575bfaSKevin Wolf 18324575bfaSKevin Wolf_send_qemu_cmd $h \ 18424575bfaSKevin Wolf "{ 'execute': 'drive-backup', 18524575bfaSKevin Wolf 'arguments': { 'device': 'disk', 18624575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 18724575bfaSKevin Wolf 'format': '$IMGFMT', 18824575bfaSKevin Wolf 'sync': 'full', 18924575bfaSKevin Wolf 'speed': 65536 } }" \ 19024575bfaSKevin Wolf "return" 19124575bfaSKevin Wolf 192*ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 193*ddf2d98aSStefan Hajnoczisleep 0.5 194*ddf2d98aSStefan Hajnoczi 19524575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 19624575bfaSKevin Wolfwait=1 _cleanup_qemu 19724575bfaSKevin Wolf 19824575bfaSKevin Wolfecho 19924575bfaSKevin Wolfecho === Start streaming job and exit qemu === 20024575bfaSKevin Wolfecho 20124575bfaSKevin Wolf 20224575bfaSKevin Wolf_launch_qemu \ 20324575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 20424575bfaSKevin Wolfh=$QEMU_HANDLE 20524575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 20624575bfaSKevin Wolf 20724575bfaSKevin Wolf_send_qemu_cmd $h \ 20824575bfaSKevin Wolf "{ 'execute': 'block-stream', 20924575bfaSKevin Wolf 'arguments': { 'device': 'disk', 21024575bfaSKevin Wolf 'speed': 65536 } }" \ 21124575bfaSKevin Wolf "return" 21224575bfaSKevin Wolf 213*ddf2d98aSStefan Hajnoczi# If we don't sleep here 'quit' command races with disk I/O 214*ddf2d98aSStefan Hajnoczisleep 0.5 215*ddf2d98aSStefan Hajnoczi 21624575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 21724575bfaSKevin Wolfwait=1 _cleanup_qemu 21824575bfaSKevin Wolf 21924575bfaSKevin Wolf_check_test_img 22024575bfaSKevin Wolf 22124575bfaSKevin Wolf# success, all done 22224575bfaSKevin Wolfecho "*** done" 22324575bfaSKevin Wolfrm -f $seq.full 22424575bfaSKevin Wolfstatus=0 225