| 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 |
| 23 | owner=kwolf@redhat.com |
| 24 | |
| 25 | seq=`basename $0` |
| 26 | echo "QA output created by $seq" |
| 27 | |
| 28 | status=1 # failure is the default! |
| 29 | |
| 30 | MIG_SOCKET="${SOCK_DIR}/migrate" |
| 31 | |
| 32 | _cleanup() |
| 33 | { |
| 34 | rm -f "${MIG_SOCKET}" |
| 35 | _cleanup_test_img |
| 36 | _cleanup_qemu |
| 37 | } |
| 38 | trap "_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 | _require_hmp |
| 51 | |
| 52 | _flaky_test https://gitlab.com/qemu-project/qemu/-/work_items/3515 |
| 53 | |
| 54 | size=64M |
| 55 | _make_test_img $size |
| 56 | |
| 57 | echo |
| 58 | echo === Starting VMs === |
| 59 | echo |
| 60 | |
| 61 | qemu_comm_method="monitor" |
| 62 | |
| 63 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 64 | _launch_qemu \ |
| 65 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk |
| 66 | else |
| 67 | _launch_qemu \ |
| 68 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk |
| 69 | fi |
| 70 | src=$QEMU_HANDLE |
| 71 | |
| 72 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 73 | _launch_qemu \ |
| 74 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk \ |
| 75 | -incoming "unix:${MIG_SOCKET}" |
| 76 | else |
| 77 | _launch_qemu \ |
| 78 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk \ |
| 79 | -incoming "unix:${MIG_SOCKET}" |
| 80 | fi |
| 81 | dest=$QEMU_HANDLE |
| 82 | |
| 83 | echo |
| 84 | echo === Write something on the source === |
| 85 | echo |
| 86 | |
| 87 | silent= |
| 88 | _send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)" |
| 89 | _send_qemu_cmd $src "" "ops/sec" |
| 90 | _send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" |
| 91 | _send_qemu_cmd $src "" "ops/sec" |
| 92 | |
| 93 | echo |
| 94 | echo === Do postcopy migration to destination === |
| 95 | echo |
| 96 | |
| 97 | # Slow down migration so much that it definitely won't finish before we can |
| 98 | # switch to postcopy |
| 99 | # Enable postcopy-ram capability both on source and destination |
| 100 | silent=yes |
| 101 | _send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" |
| 102 | |
| 103 | qemu_error_no_exit=yes success_or_failure=yes \ |
| 104 | _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported" |
| 105 | if [ ${QEMU_STATUS[$dest]} -lt 0 ]; then |
| 106 | _send_qemu_cmd $dest '' "(qemu)" |
| 107 | |
| 108 | _send_qemu_cmd $src 'quit' "" |
| 109 | _send_qemu_cmd $dest 'quit' "" |
| 110 | wait=1 _cleanup_qemu |
| 111 | |
| 112 | _notrun 'Postcopy is not supported' |
| 113 | fi |
| 114 | |
| 115 | _send_qemu_cmd $src 'migrate_set_parameter max-bandwidth 4k' "(qemu)" |
| 116 | _send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" |
| 117 | _send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)" |
| 118 | _send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)" |
| 119 | |
| 120 | QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \ |
| 121 | _send_qemu_cmd $src "info migrate" "completed\|failed" |
| 122 | silent=yes _send_qemu_cmd $src "" "(qemu)" |
| 123 | |
| 124 | echo |
| 125 | echo === Do some I/O on the destination === |
| 126 | echo |
| 127 | |
| 128 | # It is important that we use the BlockBackend of the guest device here instead |
| 129 | # of the node name, which would create a new BlockBackend and not test whether |
| 130 | # the guest has the necessary permissions to access the image now |
| 131 | silent= |
| 132 | _send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" |
| 133 | _send_qemu_cmd $dest "" "ops/sec" |
| 134 | _send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)" |
| 135 | _send_qemu_cmd $dest "" "ops/sec" |
| 136 | |
| 137 | echo |
| 138 | echo === Shut down and check image === |
| 139 | echo |
| 140 | |
| 141 | _send_qemu_cmd $src 'quit' "" |
| 142 | _send_qemu_cmd $dest 'quit' "" |
| 143 | wait=1 _cleanup_qemu |
| 144 | |
| 145 | _check_test_img |
| 146 | |
| 147 | # success, all done |
| 148 | echo "*** done" |
| 149 | rm -f $seq.full |
| 150 | status=0 |