17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto migration quick 37a9dda0dSStefan Hajnoczi# 47a9dda0dSStefan Hajnoczi# Copyright (C) 2017 Red Hat, Inc. 57a9dda0dSStefan Hajnoczi# 67a9dda0dSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 77a9dda0dSStefan Hajnoczi# it under the terms of the GNU General Public License as published by 87a9dda0dSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 97a9dda0dSStefan Hajnoczi# (at your option) any later version. 107a9dda0dSStefan Hajnoczi# 117a9dda0dSStefan Hajnoczi# This program is distributed in the hope that it will be useful, 127a9dda0dSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 137a9dda0dSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 147a9dda0dSStefan Hajnoczi# GNU General Public License for more details. 157a9dda0dSStefan Hajnoczi# 167a9dda0dSStefan Hajnoczi# You should have received a copy of the GNU General Public License 177a9dda0dSStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 187a9dda0dSStefan Hajnoczi# 197a9dda0dSStefan Hajnoczi# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> 207a9dda0dSStefan Hajnoczi# 217a9dda0dSStefan Hajnoczi# Check that QMP 'migrate' with multiple drives on a single IOThread completes 227a9dda0dSStefan Hajnoczi# successfully. This particular command triggered a hang in the source QEMU 237a9dda0dSStefan Hajnoczi# process due to recursive AioContext locking in bdrv_invalidate_all() and 247a9dda0dSStefan Hajnoczi# BDRV_POLL_WHILE(). 257a9dda0dSStefan Hajnoczi 267a9dda0dSStefan Hajnocziimport iotests 277a9dda0dSStefan Hajnoczi 287d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2'], 297d814059SJohn Snow supported_platforms=['linux']) 307a9dda0dSStefan Hajnoczi 317a9dda0dSStefan Hajnocziwith iotests.FilePath('disk0.img') as disk0_img_path, \ 327a9dda0dSStefan Hajnoczi iotests.FilePath('disk1.img') as disk1_img_path, \ 337a9dda0dSStefan Hajnoczi iotests.VM() as vm: 347a9dda0dSStefan Hajnoczi 357a9dda0dSStefan Hajnoczi img_size = '10M' 36*3d53818fSJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, disk0_img_path, img_size) 37*3d53818fSJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, disk1_img_path, img_size) 387a9dda0dSStefan Hajnoczi 397a9dda0dSStefan Hajnoczi iotests.log('Launching VM...') 407a9dda0dSStefan Hajnoczi (vm.add_object('iothread,id=iothread0') 417a9dda0dSStefan Hajnoczi .add_drive(disk0_img_path, 'node-name=drive0-node', interface='none') 427a9dda0dSStefan Hajnoczi .add_drive(disk1_img_path, 'node-name=drive1-node', interface='none') 437a9dda0dSStefan Hajnoczi .launch()) 447a9dda0dSStefan Hajnoczi 457a9dda0dSStefan Hajnoczi iotests.log('Setting IOThreads...') 467a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 477a9dda0dSStefan Hajnoczi node_name='drive0-node', iothread='iothread0', 487a9dda0dSStefan Hajnoczi force=True)) 497a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 507a9dda0dSStefan Hajnoczi node_name='drive1-node', iothread='iothread0', 517a9dda0dSStefan Hajnoczi force=True)) 527a9dda0dSStefan Hajnoczi 5321794244SStefan Hajnoczi iotests.log('Enabling migration QMP events...') 5421794244SStefan Hajnoczi iotests.log(vm.qmp('migrate-set-capabilities', capabilities=[ 5521794244SStefan Hajnoczi { 5621794244SStefan Hajnoczi 'capability': 'events', 5721794244SStefan Hajnoczi 'state': True 5821794244SStefan Hajnoczi } 5921794244SStefan Hajnoczi ])) 6021794244SStefan Hajnoczi 617a9dda0dSStefan Hajnoczi iotests.log('Starting migration...') 627a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('migrate', uri='exec:cat >/dev/null')) 637a9dda0dSStefan Hajnoczi while True: 6421794244SStefan Hajnoczi event = vm.event_wait('MIGRATION') 6521794244SStefan Hajnoczi iotests.log(event, filters=[iotests.filter_qmp_event]) 6621794244SStefan Hajnoczi if event['data']['status'] == 'completed': 677a9dda0dSStefan Hajnoczi break 68