1#!/bin/bash 2# 3# Test old-style block migration (migrate -b) 4# 5# Copyright (C) 2017 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27status=1 # failure is the default! 28 29MIG_SOCKET="${TEST_DIR}/migrate" 30 31_cleanup() 32{ 33 rm -f "${MIG_SOCKET}" 34 rm -f "${TEST_IMG}.dest" 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 qcow2 raw qed quorum 46_supported_proto file 47_supported_os Linux 48 49size=64M 50_make_test_img $size 51TEST_IMG="${TEST_IMG}.dest" _make_test_img $size 52 53echo 54echo === Starting VMs === 55echo 56 57qemu_comm_method="qmp" 58 59_launch_qemu \ 60 -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk 61src=$QEMU_HANDLE 62_send_qemu_cmd $src "{ 'execute': 'qmp_capabilities' }" 'return' 63 64_launch_qemu \ 65 -drive file="${TEST_IMG}.dest",cache=$CACHEMODE,driver=$IMGFMT,id=disk \ 66 -incoming "unix:${MIG_SOCKET}" 67dest=$QEMU_HANDLE 68_send_qemu_cmd $dest "{ 'execute': 'qmp_capabilities' }" 'return' 69 70echo 71echo === Write something on the source === 72echo 73 74_send_qemu_cmd $src \ 75 "{ 'execute': 'human-monitor-command', 76 'arguments': { 'command-line': 77 'qemu-io disk \"write -P 0x55 0 64k\"' } }" \ 78 'return' 79_send_qemu_cmd $src \ 80 "{ 'execute': 'human-monitor-command', 81 'arguments': { 'command-line': 82 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ 83 'return' 84 85echo 86echo === Do block migration to destination === 87echo 88 89reply="$(_send_qemu_cmd $src \ 90 "{ 'execute': 'migrate', 91 'arguments': { 'uri': 'unix:${MIG_SOCKET}', 'blk': true } }" \ 92 'return\|error')" 93echo "$reply" 94if echo "$reply" | grep "compiled without old-style" > /dev/null; then 95 _notrun "migrate -b support not compiled in" 96fi 97 98QEMU_COMM_TIMEOUT=0.1 qemu_cmd_repeat=50 silent=yes \ 99 _send_qemu_cmd $src "{ 'execute': 'query-migrate' }" '"status": "completed"' 100_send_qemu_cmd $src "{ 'execute': 'query-status' }" "return" 101 102echo 103echo === Do some I/O on the destination === 104echo 105 106# It is important that we use the BlockBackend of the guest device here instead 107# of the node name, which would create a new BlockBackend and not test whether 108# the guest has the necessary permissions to access the image now 109silent=yes _send_qemu_cmd $dest "" "100 %" 110_send_qemu_cmd $dest "{ 'execute': 'query-status' }" "return" 111_send_qemu_cmd $dest \ 112 "{ 'execute': 'human-monitor-command', 113 'arguments': { 'command-line': 114 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ 115 'return' 116_send_qemu_cmd $dest \ 117 "{ 'execute': 'human-monitor-command', 118 'arguments': { 'command-line': 119 'qemu-io disk \"write -P 0x66 1M 64k\"' } }" \ 120 'return' 121 122echo 123echo === Shut down and check image === 124echo 125 126_send_qemu_cmd $src '{"execute":"quit"}' 'return' 127_send_qemu_cmd $dest '{"execute":"quit"}' 'return' 128wait=1 _cleanup_qemu 129 130_check_test_img 131TEST_IMG="${TEST_IMG}.dest" _check_test_img 132 133$QEMU_IO -c 'write -P 0x66 1M 64k' "$TEST_IMG" | _filter_qemu_io 134$QEMU_IMG compare "$TEST_IMG.dest" "$TEST_IMG" 135 136# success, all done 137echo "*** done" 138rm -f $seq.full 139status=0 140