xref: /openbmc/qemu/tests/qemu-iotests/203 (revision 23c983c8)
1#!/usr/bin/env python3
2# group: rw auto migration quick
3#
4# Copyright (C) 2017 Red Hat, Inc.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com>
20#
21# Check that QMP 'migrate' with multiple drives on a single IOThread completes
22# successfully.  This particular command triggered a hang in the source QEMU
23# process due to recursive AioContext locking in bdrv_invalidate_all() and
24# BDRV_POLL_WHILE().  Protect against regressions even though the AioContext
25# lock no longer exists.
26
27import iotests
28
29iotests.script_initialize(supported_fmts=['qcow2'],
30                          supported_platforms=['linux'])
31
32with iotests.FilePath('disk0.img') as disk0_img_path, \
33     iotests.FilePath('disk1.img') as disk1_img_path, \
34     iotests.VM() as vm:
35
36    img_size = '10M'
37    iotests.qemu_img_create('-f', iotests.imgfmt, disk0_img_path, img_size)
38    iotests.qemu_img_create('-f', iotests.imgfmt, disk1_img_path, img_size)
39
40    iotests.log('Launching VM...')
41    (vm.add_object('iothread,id=iothread0')
42       .add_drive(disk0_img_path, 'node-name=drive0-node', interface='none')
43       .add_drive(disk1_img_path, 'node-name=drive1-node', interface='none')
44       .launch())
45
46    iotests.log('Setting IOThreads...')
47    iotests.log(vm.qmp('x-blockdev-set-iothread',
48                       node_name='drive0-node', iothread='iothread0',
49                       force=True))
50    iotests.log(vm.qmp('x-blockdev-set-iothread',
51                       node_name='drive1-node', iothread='iothread0',
52                       force=True))
53
54    iotests.log('Enabling migration QMP events...')
55    iotests.log(vm.qmp('migrate-set-capabilities', capabilities=[
56        {
57            'capability': 'events',
58            'state': True
59        }
60    ]))
61
62    iotests.log('Starting migration...')
63    iotests.log(vm.qmp('migrate', uri='exec:cat >/dev/null'))
64    while True:
65        event = vm.event_wait('MIGRATION')
66        iotests.log(event, filters=[iotests.filter_qmp_event])
67        if event['data']['status'] == 'completed':
68            break
69