| 1 | #!/usr/bin/env bash |
| 2 | # group: rw migration quick |
| 3 | # |
| 4 | # Test savevm and loadvm after live migration with postcopy flag |
| 5 | # |
| 6 | # Copyright (C) 2017, IBM Corporation. |
| 7 | # |
| 8 | # This file is derived from tests/qemu-iotests/181 by Kevin Wolf |
| 9 | # |
| 10 | # This program is free software; you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation; either version 2 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # This program is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | seq=`basename $0` |
| 24 | echo "QA output created by $seq" |
| 25 | |
| 26 | status=1 # failure is the default! |
| 27 | |
| 28 | MIG_SOCKET="${SOCK_DIR}/migrate" |
| 29 | |
| 30 | # get standard environment, filters and checks |
| 31 | . ./common.rc |
| 32 | . ./common.filter |
| 33 | . ./common.qemu |
| 34 | |
| 35 | _cleanup() |
| 36 | { |
| 37 | rm -f "${MIG_SOCKET}" |
| 38 | _cleanup_test_img |
| 39 | _cleanup_qemu |
| 40 | } |
| 41 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 42 | |
| 43 | _supported_fmt qcow2 |
| 44 | _supported_proto generic |
| 45 | _supported_os Linux |
| 46 | |
| 47 | # Internal snapshots are (currently) impossible with refcount_bits=1, |
| 48 | # and generally impossible with external data files |
| 49 | _unsupported_imgopts 'refcount_bits=1[^0-9]' data_file |
| 50 | _require_hmp |
| 51 | |
| 52 | size=64M |
| 53 | _make_test_img $size |
| 54 | |
| 55 | echo |
| 56 | echo === Starting VMs === |
| 57 | echo |
| 58 | |
| 59 | qemu_comm_method="monitor" |
| 60 | |
| 61 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 62 | _launch_qemu \ |
| 63 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk |
| 64 | else |
| 65 | _launch_qemu \ |
| 66 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk |
| 67 | fi |
| 68 | src=$QEMU_HANDLE |
| 69 | |
| 70 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 71 | _launch_qemu \ |
| 72 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk \ |
| 73 | -incoming "unix:${MIG_SOCKET}" |
| 74 | else |
| 75 | _launch_qemu \ |
| 76 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk \ |
| 77 | -incoming "unix:${MIG_SOCKET}" |
| 78 | fi |
| 79 | dest=$QEMU_HANDLE |
| 80 | |
| 81 | echo |
| 82 | echo === Set \'migrate_set_capability postcopy-ram on\' and migrate === |
| 83 | echo |
| 84 | |
| 85 | silent=yes |
| 86 | _send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" |
| 87 | |
| 88 | qemu_error_no_exit=yes success_or_failure=yes \ |
| 89 | _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported" |
| 90 | if [ ${QEMU_STATUS[$dest]} -lt 0 ]; then |
| 91 | _send_qemu_cmd $dest '' "(qemu)" |
| 92 | |
| 93 | _send_qemu_cmd $src 'quit' "" |
| 94 | _send_qemu_cmd $dest 'quit' "" |
| 95 | wait=1 _cleanup_qemu |
| 96 | |
| 97 | _notrun 'Postcopy is not supported' |
| 98 | fi |
| 99 | |
| 100 | _send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" |
| 101 | _send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)" |
| 102 | |
| 103 | QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \ |
| 104 | _send_qemu_cmd $src "info migrate" "completed\|failed" |
| 105 | silent=yes _send_qemu_cmd $src "" "(qemu)" |
| 106 | |
| 107 | echo |
| 108 | echo === Check if migration was successful === |
| 109 | echo |
| 110 | |
| 111 | QEMU_COMM_TIMEOUT=1 silent=yes \ |
| 112 | _send_qemu_cmd $src "info migrate" "completed" |
| 113 | silent=yes _send_qemu_cmd $src "" "(qemu)" |
| 114 | |
| 115 | echo |
| 116 | echo === On destination, execute savevm and loadvm === |
| 117 | echo |
| 118 | |
| 119 | silent= |
| 120 | _send_qemu_cmd $dest 'savevm state1' "(qemu)" |
| 121 | _send_qemu_cmd $dest 'loadvm state1' "(qemu)" |
| 122 | |
| 123 | echo |
| 124 | echo === Shut down and check image === |
| 125 | echo |
| 126 | |
| 127 | _send_qemu_cmd $src 'quit' "" |
| 128 | _send_qemu_cmd $dest 'quit' "" |
| 129 | wait=1 _cleanup_qemu |
| 130 | |
| 131 | _check_test_img |
| 132 | |
| 133 | # success, all done |
| 134 | echo "*** done" |
| 135 | status=0 |