1#!/usr/bin/env python3 2# group: rw quick auto 3# 4# Copyright (C) 2023 Red Hat, Inc. 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <http://www.gnu.org/licenses/>. 18# 19# Creator/Owner: Kevin Wolf <kwolf@redhat.com> 20 21import iotests 22 23iotests.script_initialize(supported_fmts=['qcow2'], 24 supported_platforms=['linux']) 25iotests.verify_virtio_scsi_pci_or_ccw() 26 27with iotests.FilePath('disk1.img') as base1_path, \ 28 iotests.FilePath('disk1-snap.img') as snap1_path, \ 29 iotests.FilePath('disk2.img') as base2_path, \ 30 iotests.FilePath('disk2-snap.img') as snap2_path, \ 31 iotests.VM() as vm: 32 33 img_size = '10M' 34 35 # Only one iothread for both disks 36 vm.add_object('iothread,id=iothread0') 37 vm.add_device('virtio-scsi,iothread=iothread0') 38 39 iotests.log('Preparing disks...') 40 for i, base_path, snap_path in ((0, base1_path, snap1_path), 41 (1, base2_path, snap2_path)): 42 iotests.qemu_img_create('-f', iotests.imgfmt, base_path, img_size) 43 iotests.qemu_img_create('-f', iotests.imgfmt, '-b', base_path, 44 '-F', iotests.imgfmt, snap_path) 45 46 iotests.qemu_io_log('-c', f'write 0 {img_size}', base_path) 47 48 vm.add_blockdev(f'file,node-name=disk{i}-base-file,' 49 f'filename={base_path}') 50 vm.add_blockdev(f'qcow2,node-name=disk{i}-base,file=disk{i}-base-file') 51 vm.add_blockdev(f'file,node-name=disk{i}-file,filename={snap_path}') 52 vm.add_blockdev(f'qcow2,node-name=disk{i},file=disk{i}-file,' 53 f'backing=disk{i}-base') 54 vm.add_device(f'scsi-hd,drive=disk{i}') 55 56 iotests.log('Launching VM...') 57 vm.launch() 58 59 iotests.log('Starting stream jobs...') 60 iotests.log(vm.qmp('block-stream', device='disk0', job_id='job0')) 61 iotests.log(vm.qmp('block-stream', device='disk1', job_id='job1')) 62 63 finished = 0 64 while True: 65 try: 66 ev = vm.event_wait('JOB_STATUS_CHANGE', timeout=0.1) 67 if ev is not None and ev['data']['status'] == 'null': 68 finished += 1 69 # The test is done once both jobs are gone 70 if finished == 2: 71 break 72 except TimeoutError: 73 pass 74 vm.cmd('query-jobs') 75