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