1#!/usr/bin/env bash 2# group: rw auto migration quick 3# 4# Test postcopy live migration with shared storage 5# 6# Copyright (C) 2017 Red Hat, Inc. 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program. If not, see <http://www.gnu.org/licenses/>. 20# 21 22# creator 23owner=kwolf@redhat.com 24 25seq=`basename $0` 26echo "QA output created by $seq" 27 28status=1 # failure is the default! 29 30MIG_SOCKET="${SOCK_DIR}/migrate" 31 32_cleanup() 33{ 34 rm -f "${MIG_SOCKET}" 35 _cleanup_test_img 36 _cleanup_qemu 37} 38trap "_cleanup; exit \$status" 0 1 2 3 15 39 40# get standard environment, filters and checks 41. ./common.rc 42. ./common.filter 43. ./common.qemu 44 45_supported_fmt generic 46# Formats that do not support live migration 47_unsupported_fmt qcow vdi vhdx vmdk vpc vvfat parallels 48_supported_proto generic 49_supported_os Linux 50 51size=64M 52_make_test_img $size 53 54echo 55echo === Starting VMs === 56echo 57 58qemu_comm_method="monitor" 59 60if [ "$IMGOPTSSYNTAX" = "true" ]; then 61 _launch_qemu \ 62 -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk 63else 64 _launch_qemu \ 65 -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk 66fi 67src=$QEMU_HANDLE 68 69if [ "$IMGOPTSSYNTAX" = "true" ]; then 70 _launch_qemu \ 71 -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk \ 72 -incoming "unix:${MIG_SOCKET}" 73else 74 _launch_qemu \ 75 -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk \ 76 -incoming "unix:${MIG_SOCKET}" 77fi 78dest=$QEMU_HANDLE 79 80echo 81echo === Write something on the source === 82echo 83 84silent= 85_send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)" 86_send_qemu_cmd $src "" "ops/sec" 87_send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" 88_send_qemu_cmd $src "" "ops/sec" 89 90echo 91echo === Do postcopy migration to destination === 92echo 93 94# Slow down migration so much that it definitely won't finish before we can 95# switch to postcopy 96# Enable postcopy-ram capability both on source and destination 97silent=yes 98_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" 99 100qemu_error_no_exit=yes success_or_failure=yes \ 101 _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported" 102if [ ${QEMU_STATUS[$dest]} -lt 0 ]; then 103 _send_qemu_cmd $dest '' "(qemu)" 104 105 _send_qemu_cmd $src 'quit' "" 106 _send_qemu_cmd $dest 'quit' "" 107 wait=1 _cleanup_qemu 108 109 _notrun 'Postcopy is not supported' 110fi 111 112_send_qemu_cmd $src 'migrate_set_parameter max_bandwidth 4k' "(qemu)" 113_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" 114_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)" 115_send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)" 116 117QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \ 118 _send_qemu_cmd $src "info migrate" "completed\|failed" 119silent=yes _send_qemu_cmd $src "" "(qemu)" 120 121echo 122echo === Do some I/O on the destination === 123echo 124 125# It is important that we use the BlockBackend of the guest device here instead 126# of the node name, which would create a new BlockBackend and not test whether 127# the guest has the necessary permissions to access the image now 128silent= 129_send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" 130_send_qemu_cmd $dest "" "ops/sec" 131_send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)" 132_send_qemu_cmd $dest "" "ops/sec" 133 134echo 135echo === Shut down and check image === 136echo 137 138_send_qemu_cmd $src 'quit' "" 139_send_qemu_cmd $dest 'quit' "" 140wait=1 _cleanup_qemu 141 142_check_test_img 143 144# success, all done 145echo "*** done" 146rm -f $seq.full 147status=0 148