17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3ba7704f2SJohn Snow# 4ba7704f2SJohn Snow# Test incremental/backup across iothread contexts 5ba7704f2SJohn Snow# 6ba7704f2SJohn Snow# Copyright (c) 2019 John Snow for Red Hat, Inc. 7ba7704f2SJohn Snow# 8ba7704f2SJohn Snow# This program is free software; you can redistribute it and/or modify 9ba7704f2SJohn Snow# it under the terms of the GNU General Public License as published by 10ba7704f2SJohn Snow# the Free Software Foundation; either version 2 of the License, or 11ba7704f2SJohn Snow# (at your option) any later version. 12ba7704f2SJohn Snow# 13ba7704f2SJohn Snow# This program is distributed in the hope that it will be useful, 14ba7704f2SJohn Snow# but WITHOUT ANY WARRANTY; without even the implied warranty of 15ba7704f2SJohn Snow# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16ba7704f2SJohn Snow# GNU General Public License for more details. 17ba7704f2SJohn Snow# 18ba7704f2SJohn Snow# You should have received a copy of the GNU General Public License 19ba7704f2SJohn Snow# along with this program. If not, see <http://www.gnu.org/licenses/>. 20ba7704f2SJohn Snow# 21ba7704f2SJohn Snow# owner=jsnow@redhat.com 22ba7704f2SJohn Snow 23ba7704f2SJohn Snowimport os 24ba7704f2SJohn Snowimport iotests 25ba7704f2SJohn Snowfrom iotests import log 26ba7704f2SJohn Snow 27bc05c638SKevin Wolfiotests.verify_virtio_scsi_pci_or_ccw() 28359a8562SLaurent Vivier 297d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2']) 30ba7704f2SJohn Snowsize = 64 * 1024 * 1024 31ba7704f2SJohn Snow 32ba7704f2SJohn Snowwith iotests.FilePath('img0') as img0_path, \ 33ba7704f2SJohn Snow iotests.FilePath('img1') as img1_path, \ 34ba7704f2SJohn Snow iotests.FilePath('img0-full') as img0_full_path, \ 35ba7704f2SJohn Snow iotests.FilePath('img1-full') as img1_full_path, \ 36ba7704f2SJohn Snow iotests.FilePath('img0-incr') as img0_incr_path, \ 37ba7704f2SJohn Snow iotests.FilePath('img1-incr') as img1_incr_path, \ 38ba7704f2SJohn Snow iotests.VM() as vm: 39ba7704f2SJohn Snow 40ba7704f2SJohn Snow def create_target(filepath, name, size): 41ba7704f2SJohn Snow basename = os.path.basename(filepath) 42ba7704f2SJohn Snow nodename = "file_{}".format(basename) 43*684750abSVladimir Sementsov-Ogievskiy log(vm.cmd('blockdev-create', job_id='job1', 44ba7704f2SJohn Snow options={ 45ba7704f2SJohn Snow 'driver': 'file', 46ba7704f2SJohn Snow 'filename': filepath, 47ba7704f2SJohn Snow 'size': 0, 48ba7704f2SJohn Snow })) 49ba7704f2SJohn Snow vm.run_job('job1') 50*684750abSVladimir Sementsov-Ogievskiy log(vm.cmd('blockdev-add', driver='file', 51ba7704f2SJohn Snow node_name=nodename, filename=filepath)) 52*684750abSVladimir Sementsov-Ogievskiy log(vm.cmd('blockdev-create', job_id='job2', 53ba7704f2SJohn Snow options={ 54ba7704f2SJohn Snow 'driver': iotests.imgfmt, 55ba7704f2SJohn Snow 'file': nodename, 56ba7704f2SJohn Snow 'size': size, 57ba7704f2SJohn Snow })) 58ba7704f2SJohn Snow vm.run_job('job2') 59*684750abSVladimir Sementsov-Ogievskiy log(vm.cmd('blockdev-add', driver=iotests.imgfmt, 60ba7704f2SJohn Snow node_name=name, 61ba7704f2SJohn Snow file=nodename)) 62ba7704f2SJohn Snow 63ba7704f2SJohn Snow log('--- Preparing images & VM ---\n') 64ba7704f2SJohn Snow vm.add_object('iothread,id=iothread0') 65ba7704f2SJohn Snow vm.add_object('iothread,id=iothread1') 66359a8562SLaurent Vivier vm.add_device('virtio-scsi,id=scsi0,iothread=iothread0') 67359a8562SLaurent Vivier vm.add_device('virtio-scsi,id=scsi1,iothread=iothread1') 68ba7704f2SJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, img0_path, str(size)) 69ba7704f2SJohn Snow iotests.qemu_img_create('-f', iotests.imgfmt, img1_path, str(size)) 70ba7704f2SJohn Snow vm.add_drive(img0_path, interface='none') 71ba7704f2SJohn Snow vm.add_device('scsi-hd,id=device0,drive=drive0,bus=scsi0.0') 72ba7704f2SJohn Snow vm.add_drive(img1_path, interface='none') 73ba7704f2SJohn Snow vm.add_device('scsi-hd,id=device1,drive=drive1,bus=scsi1.0') 74ba7704f2SJohn Snow 75ba7704f2SJohn Snow log('--- Starting VM ---\n') 76ba7704f2SJohn Snow vm.launch() 77ba7704f2SJohn Snow 78ba7704f2SJohn Snow log('--- Create Targets & Full Backups ---\n') 79ba7704f2SJohn Snow create_target(img0_full_path, 'img0-full', size) 80ba7704f2SJohn Snow create_target(img1_full_path, 'img1-full', size) 81ba7704f2SJohn Snow ret = vm.qmp_log('transaction', indent=2, actions=[ 82ba7704f2SJohn Snow { 'type': 'block-dirty-bitmap-add', 83ba7704f2SJohn Snow 'data': { 'node': 'drive0', 'name': 'bitmap0' }}, 84ba7704f2SJohn Snow { 'type': 'block-dirty-bitmap-add', 85ba7704f2SJohn Snow 'data': { 'node': 'drive1', 'name': 'bitmap1' }}, 86ba7704f2SJohn Snow { 'type': 'blockdev-backup', 87ba7704f2SJohn Snow 'data': { 'device': 'drive0', 88ba7704f2SJohn Snow 'target': 'img0-full', 89ba7704f2SJohn Snow 'sync': 'full', 90ba7704f2SJohn Snow 'job-id': 'j0' }}, 91ba7704f2SJohn Snow { 'type': 'blockdev-backup', 92ba7704f2SJohn Snow 'data': { 'device': 'drive1', 93ba7704f2SJohn Snow 'target': 'img1-full', 94ba7704f2SJohn Snow 'sync': 'full', 95ba7704f2SJohn Snow 'job-id': 'j1' }} 96ba7704f2SJohn Snow ]) 97ba7704f2SJohn Snow if "error" in ret: 98ba7704f2SJohn Snow raise Exception(ret['error']['desc']) 99ba7704f2SJohn Snow vm.run_job('j0', auto_dismiss=True) 100ba7704f2SJohn Snow vm.run_job('j1', auto_dismiss=True) 101ba7704f2SJohn Snow 102ba7704f2SJohn Snow log('\n--- Create Targets & Incremental Backups ---\n') 103ba7704f2SJohn Snow create_target(img0_incr_path, 'img0-incr', size) 104ba7704f2SJohn Snow create_target(img1_incr_path, 'img1-incr', size) 105ba7704f2SJohn Snow ret = vm.qmp_log('transaction', indent=2, actions=[ 106ba7704f2SJohn Snow { 'type': 'blockdev-backup', 107ba7704f2SJohn Snow 'data': { 'device': 'drive0', 108ba7704f2SJohn Snow 'target': 'img0-incr', 109ba7704f2SJohn Snow 'sync': 'incremental', 110ba7704f2SJohn Snow 'bitmap': 'bitmap0', 111ba7704f2SJohn Snow 'job-id': 'j2' }}, 112ba7704f2SJohn Snow { 'type': 'blockdev-backup', 113ba7704f2SJohn Snow 'data': { 'device': 'drive1', 114ba7704f2SJohn Snow 'target': 'img1-incr', 115ba7704f2SJohn Snow 'sync': 'incremental', 116ba7704f2SJohn Snow 'bitmap': 'bitmap1', 117ba7704f2SJohn Snow 'job-id': 'j3' }} 118ba7704f2SJohn Snow ]) 119ba7704f2SJohn Snow if "error" in ret: 120ba7704f2SJohn Snow raise Exception(ret['error']['desc']) 121ba7704f2SJohn Snow vm.run_job('j2', auto_dismiss=True) 122ba7704f2SJohn Snow vm.run_job('j3', auto_dismiss=True) 123ba7704f2SJohn Snow 124ba7704f2SJohn Snow log('\n--- Done ---') 125ba7704f2SJohn Snow vm.shutdown() 126