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