xref: /openbmc/qemu/tests/qemu-iotests/181 (revision 312758e23724044adb66ad1cd7fcde399817ec5b)
1*312758e2SKevin Wolf#!/bin/bash
2*312758e2SKevin Wolf#
3*312758e2SKevin Wolf# Test postcopy live migration with shared storage
4*312758e2SKevin Wolf#
5*312758e2SKevin Wolf# Copyright (C) 2017 Red Hat, Inc.
6*312758e2SKevin Wolf#
7*312758e2SKevin Wolf# This program is free software; you can redistribute it and/or modify
8*312758e2SKevin Wolf# it under the terms of the GNU General Public License as published by
9*312758e2SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*312758e2SKevin Wolf# (at your option) any later version.
11*312758e2SKevin Wolf#
12*312758e2SKevin Wolf# This program is distributed in the hope that it will be useful,
13*312758e2SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*312758e2SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*312758e2SKevin Wolf# GNU General Public License for more details.
16*312758e2SKevin Wolf#
17*312758e2SKevin Wolf# You should have received a copy of the GNU General Public License
18*312758e2SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*312758e2SKevin Wolf#
20*312758e2SKevin Wolf
21*312758e2SKevin Wolf# creator
22*312758e2SKevin Wolfowner=kwolf@redhat.com
23*312758e2SKevin Wolf
24*312758e2SKevin Wolfseq=`basename $0`
25*312758e2SKevin Wolfecho "QA output created by $seq"
26*312758e2SKevin Wolf
27*312758e2SKevin Wolfhere=`pwd`
28*312758e2SKevin Wolfstatus=1	# failure is the default!
29*312758e2SKevin Wolf
30*312758e2SKevin WolfMIG_SOCKET="${TEST_DIR}/migrate"
31*312758e2SKevin Wolf
32*312758e2SKevin Wolf_cleanup()
33*312758e2SKevin Wolf{
34*312758e2SKevin Wolf    rm -f "${MIG_SOCKET}"
35*312758e2SKevin Wolf	_cleanup_test_img
36*312758e2SKevin Wolf    _cleanup_qemu
37*312758e2SKevin Wolf}
38*312758e2SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
39*312758e2SKevin Wolf
40*312758e2SKevin Wolf# get standard environment, filters and checks
41*312758e2SKevin Wolf. ./common.rc
42*312758e2SKevin Wolf. ./common.filter
43*312758e2SKevin Wolf. ./common.qemu
44*312758e2SKevin Wolf
45*312758e2SKevin Wolf_supported_fmt generic
46*312758e2SKevin Wolf_supported_proto generic
47*312758e2SKevin Wolf_supported_os Linux
48*312758e2SKevin Wolf
49*312758e2SKevin Wolfsize=64M
50*312758e2SKevin Wolf_make_test_img $size
51*312758e2SKevin Wolf
52*312758e2SKevin Wolfecho
53*312758e2SKevin Wolfecho === Starting VMs ===
54*312758e2SKevin Wolfecho
55*312758e2SKevin Wolf
56*312758e2SKevin Wolfqemu_comm_method="monitor"
57*312758e2SKevin Wolf
58*312758e2SKevin Wolf_launch_qemu \
59*312758e2SKevin Wolf    -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk
60*312758e2SKevin Wolfsrc=$QEMU_HANDLE
61*312758e2SKevin Wolf
62*312758e2SKevin Wolf_launch_qemu \
63*312758e2SKevin Wolf    -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk \
64*312758e2SKevin Wolf    -incoming "unix:${MIG_SOCKET}"
65*312758e2SKevin Wolfdest=$QEMU_HANDLE
66*312758e2SKevin Wolf
67*312758e2SKevin Wolfecho
68*312758e2SKevin Wolfecho === Write something on the source ===
69*312758e2SKevin Wolfecho
70*312758e2SKevin Wolf
71*312758e2SKevin Wolfsilent=
72*312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "write -P 0x55 0 64k"' "(qemu)"
73*312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
74*312758e2SKevin Wolf_send_qemu_cmd $src 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
75*312758e2SKevin Wolf_send_qemu_cmd $src "" "ops/sec"
76*312758e2SKevin Wolf
77*312758e2SKevin Wolfecho
78*312758e2SKevin Wolfecho === Do postcopy migration to destination ===
79*312758e2SKevin Wolfecho
80*312758e2SKevin Wolf
81*312758e2SKevin Wolf# Slow down migration so much that it definitely won't finish before we can
82*312758e2SKevin Wolf# switch to postcopy
83*312758e2SKevin Wolfsilent=yes
84*312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_speed 4k' "(qemu)"
85*312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)"
86*312758e2SKevin Wolf_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
87*312758e2SKevin Wolf_send_qemu_cmd $src 'migrate_start_postcopy' "(qemu)"
88*312758e2SKevin Wolf
89*312758e2SKevin WolfQEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
90*312758e2SKevin Wolf    _send_qemu_cmd $src "info migrate" "completed\|failed"
91*312758e2SKevin Wolfsilent=yes _send_qemu_cmd $src "" "(qemu)"
92*312758e2SKevin Wolf
93*312758e2SKevin Wolfecho
94*312758e2SKevin Wolfecho === Do some I/O on the destination ===
95*312758e2SKevin Wolfecho
96*312758e2SKevin Wolf
97*312758e2SKevin Wolf# It is important that we use the BlockBackend of the guest device here instead
98*312758e2SKevin Wolf# of the node name, which would create a new BlockBackend and not test whether
99*312758e2SKevin Wolf# the guest has the necessary permissions to access the image now
100*312758e2SKevin Wolfsilent=
101*312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "read -P 0x55 0 64k"' "(qemu)"
102*312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
103*312758e2SKevin Wolf_send_qemu_cmd $dest 'qemu-io disk "write -P 0x66 1M 64k"' "(qemu)"
104*312758e2SKevin Wolf_send_qemu_cmd $dest "" "ops/sec"
105*312758e2SKevin Wolf
106*312758e2SKevin Wolfecho
107*312758e2SKevin Wolfecho === Shut down and check image ===
108*312758e2SKevin Wolfecho
109*312758e2SKevin Wolf
110*312758e2SKevin Wolf_send_qemu_cmd $src 'quit' ""
111*312758e2SKevin Wolf_send_qemu_cmd $dest 'quit' ""
112*312758e2SKevin Wolfwait=1 _cleanup_qemu
113*312758e2SKevin Wolf
114*312758e2SKevin Wolf_check_test_img
115*312758e2SKevin Wolf
116*312758e2SKevin Wolf# success, all done
117*312758e2SKevin Wolfecho "*** done"
118*312758e2SKevin Wolfrm -f $seq.full
119*312758e2SKevin Wolfstatus=0
120