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