17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 26dd64919SStefan Hajnoczi# 36dd64919SStefan Hajnoczi# Copyright (C) 2017 Red Hat, Inc. 46dd64919SStefan Hajnoczi# 56dd64919SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 66dd64919SStefan Hajnoczi# it under the terms of the GNU General Public License as published by 76dd64919SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 86dd64919SStefan Hajnoczi# (at your option) any later version. 96dd64919SStefan Hajnoczi# 106dd64919SStefan Hajnoczi# This program is distributed in the hope that it will be useful, 116dd64919SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 126dd64919SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136dd64919SStefan Hajnoczi# GNU General Public License for more details. 146dd64919SStefan Hajnoczi# 156dd64919SStefan Hajnoczi# You should have received a copy of the GNU General Public License 166dd64919SStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 176dd64919SStefan Hajnoczi# 186dd64919SStefan Hajnoczi# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> 196dd64919SStefan Hajnoczi# 206dd64919SStefan Hajnoczi# Check that QMP 'transaction' blockdev-snapshot-sync with multiple drives on a 216dd64919SStefan Hajnoczi# single IOThread completes successfully. This particular command triggered a 226dd64919SStefan Hajnoczi# hang due to recursive AioContext locking and BDRV_POLL_WHILE(). Protect 236dd64919SStefan Hajnoczi# against regressions. 246dd64919SStefan Hajnoczi 256dd64919SStefan Hajnocziimport iotests 266dd64919SStefan Hajnoczi 27*7d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2'], 28*7d814059SJohn Snow supported_platforms=['linux']) 296dd64919SStefan Hajnoczi 306dd64919SStefan Hajnocziwith iotests.FilePath('disk0.img') as disk0_img_path, \ 316dd64919SStefan Hajnoczi iotests.FilePath('disk1.img') as disk1_img_path, \ 326dd64919SStefan Hajnoczi iotests.FilePath('disk0-snap.img') as disk0_snap_img_path, \ 336dd64919SStefan Hajnoczi iotests.FilePath('disk1-snap.img') as disk1_snap_img_path, \ 346dd64919SStefan Hajnoczi iotests.VM() as vm: 356dd64919SStefan Hajnoczi 366dd64919SStefan Hajnoczi img_size = '10M' 376dd64919SStefan Hajnoczi iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk0_img_path, img_size) 386dd64919SStefan Hajnoczi iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk1_img_path, img_size) 396dd64919SStefan Hajnoczi 406dd64919SStefan Hajnoczi iotests.log('Launching VM...') 416dd64919SStefan Hajnoczi vm.launch() 426dd64919SStefan Hajnoczi 436dd64919SStefan Hajnoczi iotests.log('Adding IOThread...') 446dd64919SStefan Hajnoczi iotests.log(vm.qmp('object-add', 456dd64919SStefan Hajnoczi qom_type='iothread', 466dd64919SStefan Hajnoczi id='iothread0')) 476dd64919SStefan Hajnoczi 486dd64919SStefan Hajnoczi iotests.log('Adding blockdevs...') 496dd64919SStefan Hajnoczi iotests.log(vm.qmp('blockdev-add', 506dd64919SStefan Hajnoczi driver=iotests.imgfmt, 516dd64919SStefan Hajnoczi node_name='disk0', 526dd64919SStefan Hajnoczi file={ 536dd64919SStefan Hajnoczi 'driver': 'file', 546dd64919SStefan Hajnoczi 'filename': disk0_img_path, 556dd64919SStefan Hajnoczi })) 566dd64919SStefan Hajnoczi iotests.log(vm.qmp('blockdev-add', 576dd64919SStefan Hajnoczi driver=iotests.imgfmt, 586dd64919SStefan Hajnoczi node_name='disk1', 596dd64919SStefan Hajnoczi file={ 606dd64919SStefan Hajnoczi 'driver': 'file', 616dd64919SStefan Hajnoczi 'filename': disk1_img_path, 626dd64919SStefan Hajnoczi })) 636dd64919SStefan Hajnoczi 646dd64919SStefan Hajnoczi iotests.log('Setting iothread...') 656dd64919SStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 666dd64919SStefan Hajnoczi node_name='disk0', 676dd64919SStefan Hajnoczi iothread='iothread0')) 686dd64919SStefan Hajnoczi iotests.log(vm.qmp('x-blockdev-set-iothread', 696dd64919SStefan Hajnoczi node_name='disk1', 706dd64919SStefan Hajnoczi iothread='iothread0')) 716dd64919SStefan Hajnoczi 726dd64919SStefan Hajnoczi iotests.log('Creating external snapshots...') 736dd64919SStefan Hajnoczi iotests.log(vm.qmp( 746dd64919SStefan Hajnoczi 'transaction', 756dd64919SStefan Hajnoczi actions=[ 766dd64919SStefan Hajnoczi { 776dd64919SStefan Hajnoczi 'data': { 786dd64919SStefan Hajnoczi 'node-name': 'disk0', 796dd64919SStefan Hajnoczi 'snapshot-file': disk0_snap_img_path, 806dd64919SStefan Hajnoczi 'snapshot-node-name': 'disk0-snap', 816dd64919SStefan Hajnoczi 'mode': 'absolute-paths', 826dd64919SStefan Hajnoczi 'format': iotests.imgfmt, 836dd64919SStefan Hajnoczi }, 846dd64919SStefan Hajnoczi 'type': 'blockdev-snapshot-sync' 856dd64919SStefan Hajnoczi }, { 866dd64919SStefan Hajnoczi 'data': { 876dd64919SStefan Hajnoczi 'node-name': 'disk1', 886dd64919SStefan Hajnoczi 'snapshot-file': disk1_snap_img_path, 896dd64919SStefan Hajnoczi 'snapshot-node-name': 'disk1-snap', 906dd64919SStefan Hajnoczi 'mode': 'absolute-paths', 916dd64919SStefan Hajnoczi 'format': iotests.imgfmt 926dd64919SStefan Hajnoczi }, 936dd64919SStefan Hajnoczi 'type': 'blockdev-snapshot-sync' 946dd64919SStefan Hajnoczi } 956dd64919SStefan Hajnoczi ])) 96