1ac6fb43eSKevin Wolf#!/usr/bin/env python 2ac6fb43eSKevin Wolf# 3ac6fb43eSKevin Wolf# Test commit job graph modifications while requests are active 4ac6fb43eSKevin Wolf# 5ac6fb43eSKevin Wolf# Copyright (C) 2019 Red Hat, Inc. 6ac6fb43eSKevin Wolf# 7ac6fb43eSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com> 8ac6fb43eSKevin Wolf# 9ac6fb43eSKevin Wolf# This program is free software; you can redistribute it and/or modify 10ac6fb43eSKevin Wolf# it under the terms of the GNU General Public License as published by 11ac6fb43eSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 12ac6fb43eSKevin Wolf# (at your option) any later version. 13ac6fb43eSKevin Wolf# 14ac6fb43eSKevin Wolf# This program is distributed in the hope that it will be useful, 15ac6fb43eSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 16ac6fb43eSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17ac6fb43eSKevin Wolf# GNU General Public License for more details. 18ac6fb43eSKevin Wolf# 19ac6fb43eSKevin Wolf# You should have received a copy of the GNU General Public License 20ac6fb43eSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 21ac6fb43eSKevin Wolf# 22ac6fb43eSKevin Wolf 23ac6fb43eSKevin Wolfimport iotests 24ac6fb43eSKevin Wolffrom iotests import imgfmt 25ac6fb43eSKevin Wolf 26ac6fb43eSKevin Wolfiotests.verify_image_format(supported_fmts=['qcow2']) 27ac6fb43eSKevin Wolf 28ac6fb43eSKevin Wolfdef blockdev_create(vm, options): 29ac6fb43eSKevin Wolf result = vm.qmp_log('blockdev-create', 30ac6fb43eSKevin Wolf filters=[iotests.filter_qmp_testfiles], 31ac6fb43eSKevin Wolf job_id='job0', options=options) 32ac6fb43eSKevin Wolf 33ac6fb43eSKevin Wolf if 'return' in result: 34ac6fb43eSKevin Wolf assert result['return'] == {} 35ac6fb43eSKevin Wolf vm.run_job('job0') 36ac6fb43eSKevin Wolf iotests.log("") 37ac6fb43eSKevin Wolf 38*74f27eadSMax Reitziotests.log('Finishing a commit job with background reads') 39*74f27eadSMax Reitziotests.log('============================================') 40*74f27eadSMax Reitziotests.log('') 41*74f27eadSMax Reitz 42ac6fb43eSKevin Wolfwith iotests.FilePath('t.qcow2') as disk_path, \ 43ac6fb43eSKevin Wolf iotests.FilePath('t.qcow2.mid') as mid_path, \ 44ac6fb43eSKevin Wolf iotests.FilePath('t.qcow2.base') as base_path, \ 45ac6fb43eSKevin Wolf iotests.VM() as vm: 46ac6fb43eSKevin Wolf 47ac6fb43eSKevin Wolf iotests.log("=== Create backing chain and start VM ===") 48ac6fb43eSKevin Wolf iotests.log("") 49ac6fb43eSKevin Wolf 50ac6fb43eSKevin Wolf size = 128 * 1024 * 1024 51ac6fb43eSKevin Wolf size_str = str(size) 52ac6fb43eSKevin Wolf 53ac6fb43eSKevin Wolf iotests.create_image(base_path, size) 54ac6fb43eSKevin Wolf iotests.qemu_img_log('create', '-f', iotests.imgfmt, mid_path, size_str) 55ac6fb43eSKevin Wolf iotests.qemu_img_log('create', '-f', iotests.imgfmt, disk_path, size_str) 56ac6fb43eSKevin Wolf 57ac6fb43eSKevin Wolf # Create a backing chain like this: 58ac6fb43eSKevin Wolf # base <- [throttled: bps-read=4096] <- mid <- overlay 59ac6fb43eSKevin Wolf 60ac6fb43eSKevin Wolf vm.add_object('throttle-group,x-bps-read=4096,id=throttle0') 61ac6fb43eSKevin Wolf vm.add_blockdev('file,filename=%s,node-name=base' % (base_path)) 62ac6fb43eSKevin Wolf vm.add_blockdev('throttle,throttle-group=throttle0,file=base,node-name=throttled') 63ac6fb43eSKevin Wolf vm.add_blockdev('file,filename=%s,node-name=mid-file' % (mid_path)) 64ac6fb43eSKevin Wolf vm.add_blockdev('qcow2,file=mid-file,node-name=mid,backing=throttled') 65ac6fb43eSKevin Wolf vm.add_drive_raw('if=none,id=overlay,driver=qcow2,file=%s,backing=mid' % (disk_path)) 66ac6fb43eSKevin Wolf 67ac6fb43eSKevin Wolf vm.launch() 68ac6fb43eSKevin Wolf 69ac6fb43eSKevin Wolf iotests.log("=== Start background read requests ===") 70ac6fb43eSKevin Wolf iotests.log("") 71ac6fb43eSKevin Wolf 72ac6fb43eSKevin Wolf def start_requests(): 73ac6fb43eSKevin Wolf vm.hmp_qemu_io('overlay', 'aio_read 0 4k') 74ac6fb43eSKevin Wolf vm.hmp_qemu_io('overlay', 'aio_read 0 4k') 75ac6fb43eSKevin Wolf 76ac6fb43eSKevin Wolf start_requests() 77ac6fb43eSKevin Wolf 78ac6fb43eSKevin Wolf iotests.log("=== Run a commit job ===") 79ac6fb43eSKevin Wolf iotests.log("") 80ac6fb43eSKevin Wolf 81ac6fb43eSKevin Wolf result = vm.qmp_log('block-commit', job_id='job0', auto_finalize=False, 82ac6fb43eSKevin Wolf device='overlay', top_node='mid') 83ac6fb43eSKevin Wolf 84ac6fb43eSKevin Wolf vm.run_job('job0', auto_finalize=False, pre_finalize=start_requests, 85ac6fb43eSKevin Wolf auto_dismiss=True) 86ac6fb43eSKevin Wolf 87ac6fb43eSKevin Wolf vm.shutdown() 88*74f27eadSMax Reitz 89*74f27eadSMax Reitziotests.log('') 90*74f27eadSMax Reitziotests.log('Closing the VM while a job is being cancelled') 91*74f27eadSMax Reitziotests.log('=============================================') 92*74f27eadSMax Reitziotests.log('') 93*74f27eadSMax Reitz 94*74f27eadSMax Reitzwith iotests.FilePath('src.qcow2') as src_path, \ 95*74f27eadSMax Reitz iotests.FilePath('dst.qcow2') as dst_path, \ 96*74f27eadSMax Reitz iotests.VM() as vm: 97*74f27eadSMax Reitz 98*74f27eadSMax Reitz iotests.log('=== Create images and start VM ===') 99*74f27eadSMax Reitz iotests.log('') 100*74f27eadSMax Reitz 101*74f27eadSMax Reitz size = 128 * 1024 * 1024 102*74f27eadSMax Reitz size_str = str(size) 103*74f27eadSMax Reitz 104*74f27eadSMax Reitz iotests.qemu_img_log('create', '-f', iotests.imgfmt, src_path, size_str) 105*74f27eadSMax Reitz iotests.qemu_img_log('create', '-f', iotests.imgfmt, dst_path, size_str) 106*74f27eadSMax Reitz 107*74f27eadSMax Reitz iotests.log(iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 1M', 108*74f27eadSMax Reitz src_path), 109*74f27eadSMax Reitz filters=[iotests.filter_test_dir, iotests.filter_qemu_io]) 110*74f27eadSMax Reitz 111*74f27eadSMax Reitz vm.add_object('throttle-group,x-bps-read=4096,id=throttle0') 112*74f27eadSMax Reitz 113*74f27eadSMax Reitz vm.add_blockdev('file,node-name=src-file,filename=%s' % (src_path)) 114*74f27eadSMax Reitz vm.add_blockdev('%s,node-name=src,file=src-file' % (iotests.imgfmt)) 115*74f27eadSMax Reitz 116*74f27eadSMax Reitz vm.add_blockdev('file,node-name=dst-file,filename=%s' % (dst_path)) 117*74f27eadSMax Reitz vm.add_blockdev('%s,node-name=dst,file=dst-file' % (iotests.imgfmt)) 118*74f27eadSMax Reitz 119*74f27eadSMax Reitz vm.add_blockdev('throttle,node-name=src-throttled,' + 120*74f27eadSMax Reitz 'throttle-group=throttle0,file=src') 121*74f27eadSMax Reitz 122*74f27eadSMax Reitz vm.add_device('virtio-blk,drive=src-throttled') 123*74f27eadSMax Reitz 124*74f27eadSMax Reitz vm.launch() 125*74f27eadSMax Reitz 126*74f27eadSMax Reitz iotests.log('=== Start a mirror job ===') 127*74f27eadSMax Reitz iotests.log('') 128*74f27eadSMax Reitz 129*74f27eadSMax Reitz vm.qmp_log('blockdev-mirror', job_id='job0', device='src-throttled', 130*74f27eadSMax Reitz target='dst', sync='full') 131*74f27eadSMax Reitz 132*74f27eadSMax Reitz vm.qmp_log('block-job-cancel', device='job0') 133*74f27eadSMax Reitz vm.qmp_log('quit') 134*74f27eadSMax Reitz 135*74f27eadSMax Reitz vm.shutdown() 136