xref: /openbmc/qemu/tests/qemu-iotests/181 (revision a9ed6a919360b998009508be03b056f2b7417ac5)
1312758e2SKevin Wolf#!/bin/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 Wolfhere=`pwd`
28312758e2SKevin Wolfstatus=1	# failure is the default!
29312758e2SKevin Wolf
30312758e2SKevin WolfMIG_SOCKET="${TEST_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
46*a9ed6a91SMax Reitz# Formats that do not support live migration
47*a9ed6a91SMax Reitz_unsupported_fmt qcow vdi vhdx vmdk vpc vvfat
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
60312758e2SKevin Wolf_launch_qemu \
61312758e2SKevin Wolf    -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk
62312758e2SKevin Wolfsrc=$QEMU_HANDLE
63312758e2SKevin Wolf
64312758e2SKevin Wolf_launch_qemu \
65312758e2SKevin Wolf    -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk \
66312758e2SKevin Wolf    -incoming "unix:${MIG_SOCKET}"
67312758e2SKevin Wolfdest=$QEMU_HANDLE
68312758e2SKevin Wolf
69312758e2SKevin Wolfecho
70312758e2SKevin Wolfecho === Write something on the source ===
71312758e2SKevin Wolfecho
72312758e2SKevin Wolf
73312758e2SKevin Wolfsilent=
74312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)"
75312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
76312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
77312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
78312758e2SKevin Wolf
79312758e2SKevin Wolfecho
80312758e2SKevin Wolfecho === Do postcopy migration to destination ===
81312758e2SKevin Wolfecho
82312758e2SKevin Wolf
83312758e2SKevin Wolf# Slow down migration so much that it definitely won't finish before we can
84312758e2SKevin Wolf# switch to postcopy
85312758e2SKevin Wolfsilent=yes
86312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)"
87312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)"
88312758e2SKevin Wolf_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
89312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)"
90312758e2SKevin Wolf
91312758e2SKevin WolfQEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
92312758e2SKevin Wolf    _send_qemu_cmd $src "info migrate" "completed\|failed"
93312758e2SKevin Wolfsilent=yes _send_qemu_cmd $src "" "(qemu)"
94312758e2SKevin Wolf
95312758e2SKevin Wolfecho
96312758e2SKevin Wolfecho === Do some I/O on the destination ===
97312758e2SKevin Wolfecho
98312758e2SKevin Wolf
99312758e2SKevin Wolf# It is important that we use the BlockBackend of the guest device here instead
100312758e2SKevin Wolf# of the node name, which would create a new BlockBackend and not test whether
101312758e2SKevin Wolf# the guest has the necessary permissions to access the image now
102312758e2SKevin Wolfsilent=
103312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
104312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
105312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)"
106312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
107312758e2SKevin Wolf
108312758e2SKevin Wolfecho
109312758e2SKevin Wolfecho === Shut down and check image ===
110312758e2SKevin Wolfecho
111312758e2SKevin Wolf
112312758e2SKevin Wolf_send_qemu_cmd $src 'quit' ""
113312758e2SKevin Wolf_send_qemu_cmd $dest 'quit' ""
114312758e2SKevin Wolfwait=1 _cleanup_qemu
115312758e2SKevin Wolf
116312758e2SKevin Wolf_check_test_img
117312758e2SKevin Wolf
118312758e2SKevin Wolf# success, all done
119312758e2SKevin Wolfecho "*** done"
120312758e2SKevin Wolfrm -f $seq.full
121312758e2SKevin Wolfstatus=0
122