xref: /qemu/tests/qemu-iotests/256 (revision 2e8f72ac)
1#!/usr/bin/env python3
2# group: rw auto quick
3#
4# Test incremental/backup across iothread contexts
5#
6# Copyright (c) 2019 John Snow for Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21# owner=jsnow@redhat.com
22
23import os
24import iotests
25from iotests import log
26
27iotests.script_initialize(supported_fmts=['qcow2'])
28size = 64 * 1024 * 1024
29
30with 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, \
36     iotests.VM() as vm:
37
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',
42                       options={
43                           'driver': 'file',
44                           'filename': filepath,
45                           'size': 0,
46                       }))
47        vm.run_job('job1')
48        log(vm.command('blockdev-add', driver='file',
49                       node_name=nodename, filename=filepath))
50        log(vm.command('blockdev-create', job_id='job2',
51                       options={
52                           'driver': iotests.imgfmt,
53                           'file': nodename,
54                           'size': size,
55                       }))
56        vm.run_job('job2')
57        log(vm.command('blockdev-add', driver=iotests.imgfmt,
58                       node_name=name,
59                       file=nodename))
60
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')
72
73    log('--- Starting VM ---\n')
74    vm.launch()
75
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',
87                    'sync': 'full',
88                    'job-id': 'j0' }},
89        { 'type': 'blockdev-backup',
90          'data': { 'device': 'drive1',
91                    'target': 'img1-full',
92                    'sync': 'full',
93                    'job-id': 'j1' }}
94    ])
95    if "error" in ret:
96        raise Exception(ret['error']['desc'])
97    vm.run_job('j0', auto_dismiss=True)
98    vm.run_job('j1', auto_dismiss=True)
99
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',
108                    'bitmap': 'bitmap0',
109                    'job-id': 'j2' }},
110        { 'type': 'blockdev-backup',
111          'data': { 'device': 'drive1',
112                    'target': 'img1-incr',
113                    'sync': 'incremental',
114                    'bitmap': 'bitmap1',
115                    'job-id': 'j3' }}
116    ])
117    if "error" in ret:
118        raise Exception(ret['error']['desc'])
119    vm.run_job('j2', auto_dismiss=True)
120    vm.run_job('j3', auto_dismiss=True)
121
122    log('\n--- Done ---')
123    vm.shutdown()
124