Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 2 | # |
| 3 | # Test postcopy live migration with shared storage |
| 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 |
| 22 | owner=kwolf@redhat.com |
| 23 | |
| 24 | seq=`basename $0` |
| 25 | echo "QA output created by $seq" |
| 26 | |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 27 | status=1 # failure is the default! |
| 28 | |
Max Reitz | 14fa704 | 2019-10-17 15:31:42 +0200 | [diff] [blame] | 29 | MIG_SOCKET="${SOCK_DIR}/migrate" |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 30 | |
| 31 | _cleanup() |
| 32 | { |
| 33 | rm -f "${MIG_SOCKET}" |
| 34 | _cleanup_test_img |
| 35 | _cleanup_qemu |
| 36 | } |
| 37 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 38 | |
| 39 | # get standard environment, filters and checks |
| 40 | . ./common.rc |
| 41 | . ./common.filter |
| 42 | . ./common.qemu |
| 43 | |
| 44 | _supported_fmt generic |
Max Reitz | a9ed6a9 | 2017-06-21 15:11:57 +0200 | [diff] [blame] | 45 | # Formats that do not support live migration |
Kevin Wolf | e147313 | 2018-03-08 17:59:29 +0100 | [diff] [blame] | 46 | _unsupported_fmt qcow vdi vhdx vmdk vpc vvfat parallels |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 47 | _supported_proto generic |
| 48 | _supported_os Linux |
| 49 | |
| 50 | size=64M |
| 51 | _make_test_img $size |
| 52 | |
| 53 | echo |
| 54 | echo === Starting VMs === |
| 55 | echo |
| 56 | |
| 57 | qemu_comm_method="monitor" |
| 58 | |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 59 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 60 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 61 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 62 | else |
| 63 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 64 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 65 | fi |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 66 | src=$QEMU_HANDLE |
| 67 | |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 68 | if [ "$IMGOPTSSYNTAX" = "true" ]; then |
| 69 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 70 | -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk \ |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 71 | -incoming "unix:${MIG_SOCKET}" |
| 72 | else |
| 73 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 74 | -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk \ |
Daniel P. Berrange | 13a1d4a | 2017-06-26 13:35:07 +0100 | [diff] [blame] | 75 | -incoming "unix:${MIG_SOCKET}" |
| 76 | fi |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 77 | dest=$QEMU_HANDLE |
| 78 | |
| 79 | echo |
| 80 | echo === Write something on the source === |
| 81 | echo |
| 82 | |
| 83 | silent= |
| 84 | _send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)" |
| 85 | _send_qemu_cmd $src "" "ops/sec" |
| 86 | _send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" |
| 87 | _send_qemu_cmd $src "" "ops/sec" |
| 88 | |
| 89 | echo |
| 90 | echo === Do postcopy migration to destination === |
| 91 | echo |
| 92 | |
| 93 | # Slow down migration so much that it definitely won't finish before we can |
| 94 | # switch to postcopy |
Vladimir Sementsov-Ogievskiy | 69ff158 | 2017-09-25 17:55:29 +0300 | [diff] [blame] | 95 | # Enable postcopy-ram capability both on source and destination |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 96 | silent=yes |
Vladimir Sementsov-Ogievskiy | 69ff158 | 2017-09-25 17:55:29 +0300 | [diff] [blame] | 97 | _send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)" |
Max Reitz | b05a222 | 2018-04-06 17:17:31 +0200 | [diff] [blame] | 98 | |
| 99 | qemu_error_no_exit=yes success_or_failure=yes \ |
| 100 | _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported" |
| 101 | if [ ${QEMU_STATUS[$dest]} -lt 0 ]; then |
| 102 | _send_qemu_cmd $dest '' "(qemu)" |
| 103 | |
| 104 | _send_qemu_cmd $src 'quit' "" |
| 105 | _send_qemu_cmd $dest 'quit' "" |
| 106 | wait=1 _cleanup_qemu |
| 107 | |
| 108 | _notrun 'Postcopy is not supported' |
| 109 | fi |
| 110 | |
Kevin Wolf | 312758e | 2017-04-13 18:41:46 +0200 | [diff] [blame] | 111 | _send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)" |
| 112 | _send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)" |
| 113 | _send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)" |
| 114 | _send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)" |
| 115 | |
| 116 | QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \ |
| 117 | _send_qemu_cmd $src "info migrate" "completed\|failed" |
| 118 | silent=yes _send_qemu_cmd $src "" "(qemu)" |
| 119 | |
| 120 | echo |
| 121 | echo === Do some I/O on the destination === |
| 122 | echo |
| 123 | |
| 124 | # It is important that we use the BlockBackend of the guest device here instead |
| 125 | # of the node name, which would create a new BlockBackend and not test whether |
| 126 | # the guest has the necessary permissions to access the image now |
| 127 | silent= |
| 128 | _send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)" |
| 129 | _send_qemu_cmd $dest "" "ops/sec" |
| 130 | _send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)" |
| 131 | _send_qemu_cmd $dest "" "ops/sec" |
| 132 | |
| 133 | echo |
| 134 | echo === Shut down and check image === |
| 135 | echo |
| 136 | |
| 137 | _send_qemu_cmd $src 'quit' "" |
| 138 | _send_qemu_cmd $dest 'quit' "" |
| 139 | wait=1 _cleanup_qemu |
| 140 | |
| 141 | _check_test_img |
| 142 | |
| 143 | # success, all done |
| 144 | echo "*** done" |
| 145 | rm -f $seq.full |
| 146 | status=0 |