1#!/usr/bin/env bash
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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29MIG_SOCKET="${SOCK_DIR}/migrate"
30
31_cleanup()
32{
33    rm -f "${MIG_SOCKET}"
34	_cleanup_test_img
35    _cleanup_qemu
36}
37trap "_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
45# Formats that do not support live migration
46_unsupported_fmt qcow vdi vhdx vmdk vpc vvfat parallels
47_supported_proto generic
48_supported_os Linux
49
50size=64M
51_make_test_img $size
52
53echo
54echo === Starting VMs ===
55echo
56
57qemu_comm_method="monitor"
58
59if [ "$IMGOPTSSYNTAX" = "true" ]; then
60    _launch_qemu \
61        -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk
62else
63    _launch_qemu \
64        -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk
65fi
66src=$QEMU_HANDLE
67
68if [ "$IMGOPTSSYNTAX" = "true" ]; then
69    _launch_qemu \
70        -drive "${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,id=disk \
71        -incoming "unix:${MIG_SOCKET}"
72else
73    _launch_qemu \
74        -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=$AIOMODE,driver=$IMGFMT,id=disk \
75        -incoming "unix:${MIG_SOCKET}"
76fi
77dest=$QEMU_HANDLE
78
79echo
80echo === Write something on the source ===
81echo
82
83silent=
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
89echo
90echo === Do postcopy migration to destination ===
91echo
92
93# Slow down migration so much that it definitely won't finish before we can
94# switch to postcopy
95# Enable postcopy-ram capability both on source and destination
96silent=yes
97_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)"
98
99qemu_error_no_exit=yes success_or_failure=yes \
100    _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported"
101if [ ${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'
109fi
110
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
116QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
117    _send_qemu_cmd $src "info migrate" "completed\|failed"
118silent=yes _send_qemu_cmd $src "" "(qemu)"
119
120echo
121echo === Do some I/O on the destination ===
122echo
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
127silent=
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
133echo
134echo === Shut down and check image ===
135echo
136
137_send_qemu_cmd $src 'quit' ""
138_send_qemu_cmd $dest 'quit' ""
139wait=1 _cleanup_qemu
140
141_check_test_img
142
143# success, all done
144echo "*** done"
145rm -f $seq.full
146status=0
147