xref: /openbmc/qemu/tests/qemu-iotests/254 (revision 835fde4a)
1#!/usr/bin/env python3
2# group: rw backing quick
3#
4# Test external snapshot with bitmap copying and moving.
5#
6# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
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
22import iotests
23from iotests import qemu_img_create, file_path, log
24
25iotests.script_initialize(supported_fmts=['qcow2'])
26
27disk, top = file_path('disk', 'top')
28size = 1024 * 1024
29
30qemu_img_create('-f', iotests.imgfmt, disk, str(size))
31
32vm = iotests.VM().add_drive(disk, opts='node-name=base')
33vm.launch()
34
35vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0')
36vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap1',
37           persistent=True)
38vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap2',
39           persistent=True)
40
41vm.hmp_qemu_io('drive0', 'write 0 512K')
42
43vm.qmp_log('transaction', indent=2, actions=[
44    {'type': 'blockdev-snapshot-sync',
45     'data': {'device': 'drive0', 'snapshot-file': top,
46              'snapshot-node-name': 'snap'}},
47
48    # copy non-persistent bitmap0
49    {'type': 'block-dirty-bitmap-add',
50     'data': {'node': 'snap', 'name': 'bitmap0'}},
51    {'type': 'block-dirty-bitmap-merge',
52     'data': {'node': 'snap', 'target': 'bitmap0',
53              'bitmaps': [{'node': 'base', 'name': 'bitmap0'}]}},
54
55    # copy persistent bitmap1, original will be saved to base image
56    {'type': 'block-dirty-bitmap-add',
57     'data': {'node': 'snap', 'name': 'bitmap1', 'persistent': True}},
58    {'type': 'block-dirty-bitmap-merge',
59     'data': {'node': 'snap', 'target': 'bitmap1',
60              'bitmaps': [{'node': 'base', 'name': 'bitmap1'}]}},
61
62    # move persistent bitmap2, original will be removed and not saved
63    # to base image
64    {'type': 'block-dirty-bitmap-add',
65     'data': {'node': 'snap', 'name': 'bitmap2', 'persistent': True}},
66    {'type': 'block-dirty-bitmap-merge',
67     'data': {'node': 'snap', 'target': 'bitmap2',
68              'bitmaps': [{'node': 'base', 'name': 'bitmap2'}]}},
69    {'type': 'block-dirty-bitmap-remove',
70     'data': {'node': 'base', 'name': 'bitmap2'}}
71], filters=[iotests.filter_qmp_testfiles])
72
73result = vm.qmp('query-block')['return'][0]
74log("query-block: device = {}, node-name = {}, dirty-bitmaps:".format(
75    result['device'], result['inserted']['node-name']))
76log(result['inserted']['dirty-bitmaps'], indent=2)
77log("\nbitmaps in backing image:")
78log(result['inserted']['image']['backing-image']['format-specific'] \
79    ['data']['bitmaps'], indent=2)
80
81vm.shutdown()
82