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