1*7c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2db5e8210SVladimir Sementsov-Ogievskiy# 3db5e8210SVladimir Sementsov-Ogievskiy# Simple mirror test 4db5e8210SVladimir Sementsov-Ogievskiy# 5db5e8210SVladimir Sementsov-Ogievskiy# Copyright (c) 2018 Virtuozzo International GmbH. All rights reserved. 6db5e8210SVladimir Sementsov-Ogievskiy# 7db5e8210SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify 8db5e8210SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by 9db5e8210SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or 10db5e8210SVladimir Sementsov-Ogievskiy# (at your option) any later version. 11db5e8210SVladimir Sementsov-Ogievskiy# 12db5e8210SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful, 13db5e8210SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of 14db5e8210SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15db5e8210SVladimir Sementsov-Ogievskiy# GNU General Public License for more details. 16db5e8210SVladimir Sementsov-Ogievskiy# 17db5e8210SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License 18db5e8210SVladimir Sementsov-Ogievskiy# along with this program. If not, see <http://www.gnu.org/licenses/>. 19db5e8210SVladimir Sementsov-Ogievskiy# 20db5e8210SVladimir Sementsov-Ogievskiy 21db5e8210SVladimir Sementsov-Ogievskiyimport sys 22db5e8210SVladimir Sementsov-Ogievskiyimport os 23db5e8210SVladimir Sementsov-Ogievskiyimport iotests 24db5e8210SVladimir Sementsov-Ogievskiyfrom iotests import qemu_img_create, qemu_io, file_path, log 25db5e8210SVladimir Sementsov-Ogievskiy 268f8fd9edSCleber Rosasys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) 27db5e8210SVladimir Sementsov-Ogievskiy 28abf0bf99SJohn Snowfrom qemu.machine import QEMUMachine 29db5e8210SVladimir Sementsov-Ogievskiy 30db5e8210SVladimir Sementsov-Ogievskiy# Note: 31db5e8210SVladimir Sementsov-Ogievskiy# This test was added to check that mirror dead-lock was fixed (see previous 32db5e8210SVladimir Sementsov-Ogievskiy# commit before this test addition). 33db5e8210SVladimir Sementsov-Ogievskiy# And it didn't reproduce if at least one of the following: 34db5e8210SVladimir Sementsov-Ogievskiy# 1. use small image size 35db5e8210SVladimir Sementsov-Ogievskiy# 2. use raw format (not qcow2) 36db5e8210SVladimir Sementsov-Ogievskiy# 3. drop kvm and use iotests.VM() (maybe, because of qtest) (however, it still 37db5e8210SVladimir Sementsov-Ogievskiy# reproduces, if just drop kvm, but gdb failed to produce full backtraces 38db5e8210SVladimir Sementsov-Ogievskiy# for me) 39db5e8210SVladimir Sementsov-Ogievskiy# 4. add iothread 40db5e8210SVladimir Sementsov-Ogievskiy 41db5e8210SVladimir Sementsov-Ogievskiysize = 1 * 1024 * 1024 * 1024 42db5e8210SVladimir Sementsov-Ogievskiy 43db5e8210SVladimir Sementsov-Ogievskiyiotests.verify_image_format(supported_fmts=['qcow2']) 44db5e8210SVladimir Sementsov-Ogievskiy 45db5e8210SVladimir Sementsov-Ogievskiydisk = file_path('disk') 46db5e8210SVladimir Sementsov-Ogievskiy 47db5e8210SVladimir Sementsov-Ogievskiy# prepare source image 48db5e8210SVladimir Sementsov-Ogievskiyqemu_img_create('-f', iotests.imgfmt, '-o', 'preallocation=metadata', disk, 49db5e8210SVladimir Sementsov-Ogievskiy str(size)) 50db5e8210SVladimir Sementsov-Ogievskiy 51db5e8210SVladimir Sementsov-Ogievskiyvm = QEMUMachine(iotests.qemu_prog) 5275ab574bSPhilippe Mathieu-Daudévm.add_args('-accel', 'kvm', '-accel', 'tcg') 532c26e648SChristian Borntraegerif iotests.qemu_default_machine == 's390-ccw-virtio': 542c26e648SChristian Borntraeger vm.add_args('-no-shutdown') 55db5e8210SVladimir Sementsov-Ogievskiyvm.add_args('-drive', 'id=src,file=' + disk) 56db5e8210SVladimir Sementsov-Ogievskiyvm.launch() 57db5e8210SVladimir Sementsov-Ogievskiy 58db5e8210SVladimir Sementsov-Ogievskiylog(vm.qmp('object-add', qom_type='throttle-group', id='tg0', 59db5e8210SVladimir Sementsov-Ogievskiy props={ 'x-bps-total': size })) 60db5e8210SVladimir Sementsov-Ogievskiy 61db5e8210SVladimir Sementsov-Ogievskiylog(vm.qmp('blockdev-add', 62db5e8210SVladimir Sementsov-Ogievskiy **{ 'node-name': 'target', 63db5e8210SVladimir Sementsov-Ogievskiy 'driver': 'throttle', 64db5e8210SVladimir Sementsov-Ogievskiy 'throttle-group': 'tg0', 65db5e8210SVladimir Sementsov-Ogievskiy 'file': { 66db5e8210SVladimir Sementsov-Ogievskiy 'driver': 'null-co', 67db5e8210SVladimir Sementsov-Ogievskiy 'size': size 68db5e8210SVladimir Sementsov-Ogievskiy } })) 69db5e8210SVladimir Sementsov-Ogievskiy 70db5e8210SVladimir Sementsov-Ogievskiylog(vm.qmp('blockdev-mirror', device='src', target='target', sync='full')) 71db5e8210SVladimir Sementsov-Ogievskiy 72db5e8210SVladimir Sementsov-Ogievskiytry: 73db5e8210SVladimir Sementsov-Ogievskiy vm.event_wait('BLOCK_JOB_READY', timeout=10.0) 74db5e8210SVladimir Sementsov-Ogievskiyexcept: 75db5e8210SVladimir Sementsov-Ogievskiy vm.shutdown() 76db5e8210SVladimir Sementsov-Ogievskiy raise 77db5e8210SVladimir Sementsov-Ogievskiy 78db5e8210SVladimir Sementsov-Ogievskiyvm.shutdown() 79