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.verify_virtio_scsi_pci_or_ccw()
29 iotests.script_initialize(supported_fmts=['qcow2'])
30 size = 64 * 1024 * 1024
32 with iotests.FilePath('img0') as img0_path, \
33 iotests.FilePath('img1') as img1_path, \
34 iotests.FilePath('img0-full') as img0_full_path, \
35 iotests.FilePath('img1-full') as img1_full_path, \
36 iotests.FilePath('img0-incr') as img0_incr_path, \
37 iotests.FilePath('img1-incr') as img1_incr_path, \
40 def create_target(filepath, name, size):
41 basename = os.path.basename(filepath)
42 nodename = "file_{}".format(basename)
43 log(vm.cmd('blockdev-create', job_id='job1',
50 log(vm.cmd('blockdev-add', driver='file',
51 node_name=nodename, filename=filepath))
52 log(vm.cmd('blockdev-create', job_id='job2',
54 'driver': iotests.imgfmt,
59 log(vm.cmd('blockdev-add', driver=iotests.imgfmt,
63 log('--- Preparing images & VM ---\n')
64 vm.add_object('iothread,id=iothread0')
65 vm.add_object('iothread,id=iothread1')
66 vm.add_device('virtio-scsi,id=scsi0,iothread=iothread0')
67 vm.add_device('virtio-scsi,id=scsi1,iothread=iothread1')
68 iotests.qemu_img_create('-f', iotests.imgfmt, img0_path, str(size))
69 iotests.qemu_img_create('-f', iotests.imgfmt, img1_path, str(size))
70 vm.add_drive(img0_path, interface='none')
71 vm.add_device('scsi-hd,id=device0,drive=drive0,bus=scsi0.0')
72 vm.add_drive(img1_path, interface='none')
73 vm.add_device('scsi-hd,id=device1,drive=drive1,bus=scsi1.0')
75 log('--- Starting VM ---\n')
78 log('--- Create Targets & Full Backups ---\n')
79 create_target(img0_full_path, 'img0-full', size)
80 create_target(img1_full_path, 'img1-full', size)
81 ret = vm.qmp_log('transaction', indent=2, actions=[
82 { 'type': 'block-dirty-bitmap-add',
83 'data': { 'node': 'drive0', 'name': 'bitmap0' }},
84 { 'type': 'block-dirty-bitmap-add',
85 'data': { 'node': 'drive1', 'name': 'bitmap1' }},
86 { 'type': 'blockdev-backup',
87 'data': { 'device': 'drive0',
88 'target': 'img0-full',
91 { 'type': 'blockdev-backup',
92 'data': { 'device': 'drive1',
93 'target': 'img1-full',
98 raise Exception(ret['error']['desc'])
99 vm.run_job('j0', auto_dismiss=True)
100 vm.run_job('j1', auto_dismiss=True)
102 log('\n--- Create Targets & Incremental Backups ---\n')
103 create_target(img0_incr_path, 'img0-incr', size)
104 create_target(img1_incr_path, 'img1-incr', size)
105 ret = vm.qmp_log('transaction', indent=2, actions=[
106 { 'type': 'blockdev-backup',
107 'data': { 'device': 'drive0',
108 'target': 'img0-incr',
109 'sync': 'incremental',
112 { 'type': 'blockdev-backup',
113 'data': { 'device': 'drive1',
114 'target': 'img1-incr',
115 'sync': 'incremental',
120 raise Exception(ret['error']['desc'])
121 vm.run_job('j2', auto_dismiss=True)
122 vm.run_job('j3', auto_dismiss=True)
124 log('\n--- Done ---')