Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw migration quick |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 3 | # |
| 4 | # Test old-style block migration (migrate -b) |
| 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 | |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 28 | status=1 # failure is the default! |
| 29 | |
Max Reitz | 6ab72e5 | 2019-10-17 15:31:44 +0200 | [diff] [blame] | 30 | MIG_SOCKET="${SOCK_DIR}/migrate" |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 31 | |
| 32 | _cleanup() |
| 33 | { |
| 34 | rm -f "${MIG_SOCKET}" |
Max Reitz | f91ecbd | 2019-11-07 17:37:01 +0100 | [diff] [blame] | 35 | _rm_test_img "${TEST_IMG}.dest" |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 36 | _cleanup_test_img |
| 37 | _cleanup_qemu |
| 38 | } |
| 39 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 40 | |
| 41 | # get standard environment, filters and checks |
| 42 | . ./common.rc |
| 43 | . ./common.filter |
| 44 | . ./common.qemu |
| 45 | |
Thomas Huth | 30ad36f | 2020-01-21 10:52:02 +0100 | [diff] [blame] | 46 | _supported_os Linux FreeBSD NetBSD |
Kevin Wolf | ad53ea4 | 2018-04-10 10:40:04 +0200 | [diff] [blame] | 47 | _supported_fmt qcow2 raw qed quorum |
Max Reitz | 57284d2 | 2020-10-27 20:05:59 +0100 | [diff] [blame] | 48 | _supported_proto file fuse |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 49 | |
| 50 | size=64M |
| 51 | _make_test_img $size |
| 52 | TEST_IMG="${TEST_IMG}.dest" _make_test_img $size |
| 53 | |
| 54 | echo |
| 55 | echo === Starting VMs === |
| 56 | echo |
| 57 | |
| 58 | qemu_comm_method="qmp" |
| 59 | |
| 60 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 61 | -drive file="${TEST_IMG}",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 62 | src=$QEMU_HANDLE |
| 63 | _send_qemu_cmd $src "{ 'execute': 'qmp_capabilities' }" 'return' |
| 64 | |
| 65 | _launch_qemu \ |
Aarushi Mehta | 8dff69b | 2020-01-20 14:18:58 +0000 | [diff] [blame] | 66 | -drive file="${TEST_IMG}.dest",cache=$CACHEMODE,aio=$AIOMODE,driver=$IMGFMT,id=disk \ |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 67 | -incoming "unix:${MIG_SOCKET}" |
| 68 | dest=$QEMU_HANDLE |
| 69 | _send_qemu_cmd $dest "{ 'execute': 'qmp_capabilities' }" 'return' |
| 70 | |
| 71 | echo |
| 72 | echo === Write something on the source === |
| 73 | echo |
| 74 | |
| 75 | _send_qemu_cmd $src \ |
| 76 | "{ 'execute': 'human-monitor-command', |
| 77 | 'arguments': { 'command-line': |
| 78 | 'qemu-io disk \"write -P 0x55 0 64k\"' } }" \ |
| 79 | 'return' |
| 80 | _send_qemu_cmd $src \ |
| 81 | "{ 'execute': 'human-monitor-command', |
| 82 | 'arguments': { 'command-line': |
| 83 | 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ |
| 84 | 'return' |
| 85 | |
| 86 | echo |
| 87 | echo === Do block migration to destination === |
| 88 | echo |
| 89 | |
| 90 | reply="$(_send_qemu_cmd $src \ |
| 91 | "{ 'execute': 'migrate', |
| 92 | 'arguments': { 'uri': 'unix:${MIG_SOCKET}', 'blk': true } }" \ |
| 93 | 'return\|error')" |
| 94 | echo "$reply" |
| 95 | if echo "$reply" | grep "compiled without old-style" > /dev/null; then |
| 96 | _notrun "migrate -b support not compiled in" |
| 97 | fi |
| 98 | |
Andrey Shinkevich | fbd1c37 | 2019-09-04 12:11:23 +0300 | [diff] [blame] | 99 | timeout_comm=$QEMU_COMM_TIMEOUT |
| 100 | if [ "${VALGRIND_QEMU}" == "y" ]; then |
| 101 | QEMU_COMM_TIMEOUT=4 |
| 102 | else |
| 103 | QEMU_COMM_TIMEOUT=0.1 |
| 104 | fi |
| 105 | qemu_cmd_repeat=50 silent=yes \ |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 106 | _send_qemu_cmd $src "{ 'execute': 'query-migrate' }" '"status": "completed"' |
Andrey Shinkevich | fbd1c37 | 2019-09-04 12:11:23 +0300 | [diff] [blame] | 107 | QEMU_COMM_TIMEOUT=$timeout_comm |
Kevin Wolf | 49695ee | 2017-05-23 14:53:10 +0200 | [diff] [blame] | 108 | _send_qemu_cmd $src "{ 'execute': 'query-status' }" "return" |
| 109 | |
| 110 | echo |
| 111 | echo === Do some I/O on the destination === |
| 112 | echo |
| 113 | |
| 114 | # It is important that we use the BlockBackend of the guest device here instead |
| 115 | # of the node name, which would create a new BlockBackend and not test whether |
| 116 | # the guest has the necessary permissions to access the image now |
| 117 | silent=yes _send_qemu_cmd $dest "" "100 %" |
| 118 | _send_qemu_cmd $dest "{ 'execute': 'query-status' }" "return" |
| 119 | _send_qemu_cmd $dest \ |
| 120 | "{ 'execute': 'human-monitor-command', |
| 121 | 'arguments': { 'command-line': |
| 122 | 'qemu-io disk \"read -P 0x55 0 64k\"' } }" \ |
| 123 | 'return' |
| 124 | _send_qemu_cmd $dest \ |
| 125 | "{ 'execute': 'human-monitor-command', |
| 126 | 'arguments': { 'command-line': |
| 127 | 'qemu-io disk \"write -P 0x66 1M 64k\"' } }" \ |
| 128 | 'return' |
| 129 | |
| 130 | echo |
| 131 | echo === Shut down and check image === |
| 132 | echo |
| 133 | |
| 134 | _send_qemu_cmd $src '{"execute":"quit"}' 'return' |
| 135 | _send_qemu_cmd $dest '{"execute":"quit"}' 'return' |
| 136 | wait=1 _cleanup_qemu |
| 137 | |
| 138 | _check_test_img |
| 139 | TEST_IMG="${TEST_IMG}.dest" _check_test_img |
| 140 | |
| 141 | $QEMU_IO -c 'write -P 0x66 1M 64k' "$TEST_IMG" | _filter_qemu_io |
| 142 | $QEMU_IMG compare "$TEST_IMG.dest" "$TEST_IMG" |
| 143 | |
| 144 | # success, all done |
| 145 | echo "*** done" |
| 146 | rm -f $seq.full |
| 147 | status=0 |