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