1*7a9dda0dSStefan Hajnoczi#!/usr/bin/env python 2*7a9dda0dSStefan Hajnoczi# 3*7a9dda0dSStefan Hajnoczi# Copyright (C) 2017 Red Hat, Inc. 4*7a9dda0dSStefan Hajnoczi# 5*7a9dda0dSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 6*7a9dda0dSStefan Hajnoczi# it under the terms of the GNU General Public License as published by 7*7a9dda0dSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 8*7a9dda0dSStefan Hajnoczi# (at your option) any later version. 9*7a9dda0dSStefan Hajnoczi# 10*7a9dda0dSStefan Hajnoczi# This program is distributed in the hope that it will be useful, 11*7a9dda0dSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 12*7a9dda0dSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*7a9dda0dSStefan Hajnoczi# GNU General Public License for more details. 14*7a9dda0dSStefan Hajnoczi# 15*7a9dda0dSStefan Hajnoczi# You should have received a copy of the GNU General Public License 16*7a9dda0dSStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 17*7a9dda0dSStefan Hajnoczi# 18*7a9dda0dSStefan Hajnoczi# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> 19*7a9dda0dSStefan Hajnoczi# 20*7a9dda0dSStefan Hajnoczi# Check that QMP 'migrate' with multiple drives on a single IOThread completes 21*7a9dda0dSStefan Hajnoczi# successfully. This particular command triggered a hang in the source QEMU 22*7a9dda0dSStefan Hajnoczi# process due to recursive AioContext locking in bdrv_invalidate_all() and 23*7a9dda0dSStefan Hajnoczi# BDRV_POLL_WHILE(). 24*7a9dda0dSStefan Hajnoczi 25*7a9dda0dSStefan Hajnocziimport iotests 26*7a9dda0dSStefan Hajnoczi 27*7a9dda0dSStefan Hajnocziiotests.verify_image_format(supported_fmts=['qcow2']) 28*7a9dda0dSStefan Hajnocziiotests.verify_platform(['linux']) 29*7a9dda0dSStefan Hajnoczi 30*7a9dda0dSStefan Hajnocziwith iotests.FilePath('disk0.img') as disk0_img_path, \ 31*7a9dda0dSStefan Hajnoczi iotests.FilePath('disk1.img') as disk1_img_path, \ 32*7a9dda0dSStefan Hajnoczi iotests.VM() as vm: 33*7a9dda0dSStefan Hajnoczi 34*7a9dda0dSStefan Hajnoczi img_size = '10M' 35*7a9dda0dSStefan Hajnoczi iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk0_img_path, img_size) 36*7a9dda0dSStefan Hajnoczi iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk1_img_path, img_size) 37*7a9dda0dSStefan Hajnoczi 38*7a9dda0dSStefan Hajnoczi iotests.log('Launching VM...') 39*7a9dda0dSStefan Hajnoczi (vm.add_object('iothread,id=iothread0') 40*7a9dda0dSStefan Hajnoczi .add_drive(disk0_img_path, 'node-name=drive0-node', interface='none') 41*7a9dda0dSStefan Hajnoczi .add_drive(disk1_img_path, 'node-name=drive1-node', interface='none') 42*7a9dda0dSStefan Hajnoczi .launch()) 43*7a9dda0dSStefan Hajnoczi 44*7a9dda0dSStefan Hajnoczi iotests.log('Setting IOThreads...') 45*7a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 46*7a9dda0dSStefan Hajnoczi node_name='drive0-node', iothread='iothread0', 47*7a9dda0dSStefan Hajnoczi force=True)) 48*7a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 49*7a9dda0dSStefan Hajnoczi node_name='drive1-node', iothread='iothread0', 50*7a9dda0dSStefan Hajnoczi force=True)) 51*7a9dda0dSStefan Hajnoczi 52*7a9dda0dSStefan Hajnoczi iotests.log('Starting migration...') 53*7a9dda0dSStefan Hajnoczi iotests.log(vm.qmp('migrate', uri='exec:cat >/dev/null')) 54*7a9dda0dSStefan Hajnoczi while True: 55*7a9dda0dSStefan Hajnoczi vm.get_qmp_event(wait=60.0) 56*7a9dda0dSStefan Hajnoczi result = vm.qmp('query-migrate') 57*7a9dda0dSStefan Hajnoczi status = result.get('return', {}).get('status', None) 58*7a9dda0dSStefan Hajnoczi if status == 'completed': 59*7a9dda0dSStefan Hajnoczi break 60