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 9524575bfaSKevin Wolf# BLOCK_JOB_CANCELLED events for all of the following block jobs. They are 9624575bfaSKevin Wolf# predictable and any change in the offsets would hint at a bug in the job 9724575bfaSKevin Wolf# throttling code. 9824575bfaSKevin Wolf# 9924575bfaSKevin Wolf# In order to achieve these predictable offsets, all of the following tests 10024575bfaSKevin Wolf# use speed=65536. Each job will perform exactly one iteration before it has 10124575bfaSKevin Wolf# to sleep at least for a second, which is plenty of time for the 'quit' QMP 10224575bfaSKevin Wolf# command to be received (after receiving the command, the rest runs 10324575bfaSKevin Wolf# synchronously, so jobs can arbitrarily continue or complete). 10424575bfaSKevin Wolf# 10524575bfaSKevin Wolf# The buffer size for commit and streaming is 512k (waiting for 8 seconds after 10624575bfaSKevin Wolf# the first request), for active commit and mirror it's large enough to cover 10724575bfaSKevin Wolf# the full 4M, and for backup it's the qcow2 cluster size, which we know is 10824575bfaSKevin Wolf# 64k. As all of these are at least as large as the speed, we are sure that the 10924575bfaSKevin Wolf# offset doesn't advance after the first iteration before qemu exits. 11024575bfaSKevin Wolf 11124575bfaSKevin Wolf_send_qemu_cmd $h \ 11224575bfaSKevin Wolf "{ 'execute': 'block-commit', 11324575bfaSKevin Wolf 'arguments': { 'device': 'disk', 11424575bfaSKevin Wolf 'base':'$TEST_IMG.base', 11524575bfaSKevin Wolf 'top': '$TEST_IMG.mid', 11624575bfaSKevin Wolf 'speed': 65536 } }" \ 11724575bfaSKevin Wolf "return" 11824575bfaSKevin Wolf 11924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 12024575bfaSKevin Wolfwait=1 _cleanup_qemu 12124575bfaSKevin Wolf 12224575bfaSKevin Wolfecho 12324575bfaSKevin Wolfecho === Start active commit job and exit qemu === 12424575bfaSKevin Wolfecho 12524575bfaSKevin Wolf 12624575bfaSKevin Wolf_launch_qemu \ 12724575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 12824575bfaSKevin Wolfh=$QEMU_HANDLE 12924575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 13024575bfaSKevin Wolf 13124575bfaSKevin Wolf_send_qemu_cmd $h \ 13224575bfaSKevin Wolf "{ 'execute': 'block-commit', 13324575bfaSKevin Wolf 'arguments': { 'device': 'disk', 13424575bfaSKevin Wolf 'base':'$TEST_IMG.base', 13524575bfaSKevin Wolf 'speed': 65536 } }" \ 13624575bfaSKevin Wolf "return" 13724575bfaSKevin Wolf 13824575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 13924575bfaSKevin Wolfwait=1 _cleanup_qemu 14024575bfaSKevin Wolf 14124575bfaSKevin Wolfecho 14224575bfaSKevin Wolfecho === Start mirror job and exit qemu === 14324575bfaSKevin Wolfecho 14424575bfaSKevin Wolf 14524575bfaSKevin Wolf_launch_qemu \ 14624575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 14724575bfaSKevin Wolfh=$QEMU_HANDLE 14824575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 14924575bfaSKevin Wolf 15024575bfaSKevin Wolf_send_qemu_cmd $h \ 15124575bfaSKevin Wolf "{ 'execute': 'drive-mirror', 15224575bfaSKevin Wolf 'arguments': { 'device': 'disk', 15324575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 15424575bfaSKevin Wolf 'format': '$IMGFMT', 15524575bfaSKevin Wolf 'sync': 'full', 15624575bfaSKevin Wolf 'speed': 65536 } }" \ 15724575bfaSKevin Wolf "return" 15824575bfaSKevin Wolf 159*8565c3abSVladimir Sementsov-Ogievskiy# If we don't sleep here 'quit' command may be handled before 160*8565c3abSVladimir Sementsov-Ogievskiy# the first mirror iteration is done 161*8565c3abSVladimir Sementsov-Ogievskiysleep 0.5 162*8565c3abSVladimir Sementsov-Ogievskiy 16324575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 16424575bfaSKevin Wolfwait=1 _cleanup_qemu 16524575bfaSKevin Wolf 16624575bfaSKevin Wolfecho 16724575bfaSKevin Wolfecho === Start backup job and exit qemu === 16824575bfaSKevin Wolfecho 16924575bfaSKevin Wolf 17024575bfaSKevin Wolf_launch_qemu \ 17124575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 17224575bfaSKevin Wolfh=$QEMU_HANDLE 17324575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 17424575bfaSKevin Wolf 17524575bfaSKevin Wolf_send_qemu_cmd $h \ 17624575bfaSKevin Wolf "{ 'execute': 'drive-backup', 17724575bfaSKevin Wolf 'arguments': { 'device': 'disk', 17824575bfaSKevin Wolf 'target': '$TEST_IMG.copy', 17924575bfaSKevin Wolf 'format': '$IMGFMT', 18024575bfaSKevin Wolf 'sync': 'full', 18124575bfaSKevin Wolf 'speed': 65536 } }" \ 18224575bfaSKevin Wolf "return" 18324575bfaSKevin Wolf 18424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 18524575bfaSKevin Wolfwait=1 _cleanup_qemu 18624575bfaSKevin Wolf 18724575bfaSKevin Wolfecho 18824575bfaSKevin Wolfecho === Start streaming job and exit qemu === 18924575bfaSKevin Wolfecho 19024575bfaSKevin Wolf 19124575bfaSKevin Wolf_launch_qemu \ 19224575bfaSKevin Wolf -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 19324575bfaSKevin Wolfh=$QEMU_HANDLE 19424575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return' 19524575bfaSKevin Wolf 19624575bfaSKevin Wolf_send_qemu_cmd $h \ 19724575bfaSKevin Wolf "{ 'execute': 'block-stream', 19824575bfaSKevin Wolf 'arguments': { 'device': 'disk', 19924575bfaSKevin Wolf 'speed': 65536 } }" \ 20024575bfaSKevin Wolf "return" 20124575bfaSKevin Wolf 20224575bfaSKevin Wolf_send_qemu_cmd $h "{ 'execute': 'quit' }" "return" 20324575bfaSKevin Wolfwait=1 _cleanup_qemu 20424575bfaSKevin Wolf 20524575bfaSKevin Wolf_check_test_img 20624575bfaSKevin Wolf 20724575bfaSKevin Wolf# success, all done 20824575bfaSKevin Wolfecho "*** done" 20924575bfaSKevin Wolfrm -f $seq.full 21024575bfaSKevin Wolfstatus=0 211