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