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