xref: /openbmc/qemu/tests/qemu-iotests/181 (revision 14fa704577c9acbdd8c9e117349fededeed5d9c9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2312758e2SKevin Wolf#
3312758e2SKevin Wolf# Test postcopy live migration with shared storage
4312758e2SKevin Wolf#
5312758e2SKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
6312758e2SKevin Wolf#
7312758e2SKevin Wolf# This program is free software; you can redistribute it and/or modify
8312758e2SKevin Wolf# it under the terms of the GNU General Public License as published by
9312758e2SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10312758e2SKevin Wolf# (at your option) any later version.
11312758e2SKevin Wolf#
12312758e2SKevin Wolf# This program is distributed in the hope that it will be useful,
13312758e2SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14312758e2SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15312758e2SKevin Wolf# GNU General Public License for more details.
16312758e2SKevin Wolf#
17312758e2SKevin Wolf# You should have received a copy of the GNU General Public License
18312758e2SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19312758e2SKevin Wolf#
20312758e2SKevin Wolf
21312758e2SKevin Wolf# creator
22312758e2SKevin Wolfowner=kwolf@redhat.com
23312758e2SKevin Wolf
24312758e2SKevin Wolfseq=`basename $0`
25312758e2SKevin Wolfecho "QA output created by $seq"
26312758e2SKevin Wolf
27312758e2SKevin Wolfstatus=1	# failure is the default!
28312758e2SKevin Wolf
29*14fa7045SMax ReitzMIG_SOCKET="${SOCK_DIR}/migrate"
30312758e2SKevin Wolf
31312758e2SKevin Wolf_cleanup()
32312758e2SKevin Wolf{
33312758e2SKevin Wolf    rm -f "${MIG_SOCKET}"
34312758e2SKevin Wolf	_cleanup_test_img
35312758e2SKevin Wolf    _cleanup_qemu
36312758e2SKevin Wolf}
37312758e2SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
38312758e2SKevin Wolf
39312758e2SKevin Wolf# get standard environment, filters and checks
40312758e2SKevin Wolf. ./common.rc
41312758e2SKevin Wolf. ./common.filter
42312758e2SKevin Wolf. ./common.qemu
43312758e2SKevin Wolf
44312758e2SKevin Wolf_supported_fmt generic
45a9ed6a91SMax Reitz# Formats that do not support live migration
46e1473133SKevin Wolf_unsupported_fmt qcow vdi vhdx vmdk vpc vvfat parallels
47312758e2SKevin Wolf_supported_proto generic
48312758e2SKevin Wolf_supported_os Linux
49312758e2SKevin Wolf
50312758e2SKevin Wolfsize=64M
51312758e2SKevin Wolf_make_test_img $size
52312758e2SKevin Wolf
53312758e2SKevin Wolfecho
54312758e2SKevin Wolfecho === Starting VMs ===
55312758e2SKevin Wolfecho
56312758e2SKevin Wolf
57312758e2SKevin Wolfqemu_comm_method="monitor"
58312758e2SKevin Wolf
5913a1d4a7SDaniel P. Berrangeif [ "$IMGOPTSSYNTAX" = "true" ]; then
6013a1d4a7SDaniel P. Berrange    _launch_qemu \
6113a1d4a7SDaniel P. Berrange        -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk
6213a1d4a7SDaniel P. Berrangeelse
63312758e2SKevin Wolf    _launch_qemu \
64312758e2SKevin Wolf        -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk
6513a1d4a7SDaniel P. Berrangefi
66312758e2SKevin Wolfsrc=$QEMU_HANDLE
67312758e2SKevin Wolf
6813a1d4a7SDaniel P. Berrangeif [ "$IMGOPTSSYNTAX" = "true" ]; then
6913a1d4a7SDaniel P. Berrange    _launch_qemu \
7013a1d4a7SDaniel P. Berrange        -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk \
7113a1d4a7SDaniel P. Berrange        -incoming "unix:${MIG_SOCKET}"
7213a1d4a7SDaniel P. Berrangeelse
73312758e2SKevin Wolf    _launch_qemu \
74312758e2SKevin Wolf        -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk \
75312758e2SKevin Wolf        -incoming "unix:${MIG_SOCKET}"
7613a1d4a7SDaniel P. Berrangefi
77312758e2SKevin Wolfdest=$QEMU_HANDLE
78312758e2SKevin Wolf
79312758e2SKevin Wolfecho
80312758e2SKevin Wolfecho === Write something on the source ===
81312758e2SKevin Wolfecho
82312758e2SKevin Wolf
83312758e2SKevin Wolfsilent=
84312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)"
85312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
86312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
87312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
88312758e2SKevin Wolf
89312758e2SKevin Wolfecho
90312758e2SKevin Wolfecho === Do postcopy migration to destination ===
91312758e2SKevin Wolfecho
92312758e2SKevin Wolf
93312758e2SKevin Wolf# Slow down migration so much that it definitely won't finish before we can
94312758e2SKevin Wolf# switch to postcopy
9569ff158bSVladimir Sementsov-Ogievskiy# Enable postcopy-ram capability both on source and destination
96312758e2SKevin Wolfsilent=yes
9769ff158bSVladimir Sementsov-Ogievskiy_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)"
98b05a2225SMax Reitz
99b05a2225SMax Reitzqemu_error_no_exit=yes success_or_failure=yes \
100b05a2225SMax Reitz    _send_qemu_cmd $dest '' "(qemu)" "Postcopy is not supported"
101b05a2225SMax Reitzif [ ${QEMU_STATUS[$dest]} -lt 0 ]; then
102b05a2225SMax Reitz    _send_qemu_cmd $dest '' "(qemu)"
103b05a2225SMax Reitz
104b05a2225SMax Reitz    _send_qemu_cmd $src 'quit' ""
105b05a2225SMax Reitz    _send_qemu_cmd $dest 'quit' ""
106b05a2225SMax Reitz    wait=1 _cleanup_qemu
107b05a2225SMax Reitz
108b05a2225SMax Reitz    _notrun 'Postcopy is not supported'
109b05a2225SMax Reitzfi
110b05a2225SMax Reitz
111312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)"
112312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)"
113312758e2SKevin Wolf_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
114312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)"
115312758e2SKevin Wolf
116312758e2SKevin WolfQEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
117312758e2SKevin Wolf    _send_qemu_cmd $src "info migrate" "completed\|failed"
118312758e2SKevin Wolfsilent=yes _send_qemu_cmd $src "" "(qemu)"
119312758e2SKevin Wolf
120312758e2SKevin Wolfecho
121312758e2SKevin Wolfecho === Do some I/O on the destination ===
122312758e2SKevin Wolfecho
123312758e2SKevin Wolf
124312758e2SKevin Wolf# It is important that we use the BlockBackend of the guest device here instead
125312758e2SKevin Wolf# of the node name, which would create a new BlockBackend and not test whether
126312758e2SKevin Wolf# the guest has the necessary permissions to access the image now
127312758e2SKevin Wolfsilent=
128312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
129312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
130312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)"
131312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
132312758e2SKevin Wolf
133312758e2SKevin Wolfecho
134312758e2SKevin Wolfecho === Shut down and check image ===
135312758e2SKevin Wolfecho
136312758e2SKevin Wolf
137312758e2SKevin Wolf_send_qemu_cmd $src 'quit' ""
138312758e2SKevin Wolf_send_qemu_cmd $dest 'quit' ""
139312758e2SKevin Wolfwait=1 _cleanup_qemu
140312758e2SKevin Wolf
141312758e2SKevin Wolf_check_test_img
142312758e2SKevin Wolf
143312758e2SKevin Wolf# success, all done
144312758e2SKevin Wolfecho "*** done"
145312758e2SKevin Wolfrm -f $seq.full
146312758e2SKevin Wolfstatus=0
147