xref: /openbmc/qemu/tests/qemu-iotests/254 (revision 37677d7d)
1#!/usr/bin/env python
2#
3# Test external snapshot with bitmap copying.
4#
5# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
6#
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.
11#
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.
16#
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/>.
19#
20
21import iotests
22from iotests import qemu_img_create, file_path, log
23
24disk, top = file_path('disk', 'top')
25size = 1024 * 1024
26
27qemu_img_create('-f', iotests.imgfmt, disk, str(size))
28
29vm = iotests.VM().add_drive(disk, opts='node-name=base')
30vm.launch()
31
32vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0')
33
34vm.hmp_qemu_io('drive0', 'write 0 512K')
35
36vm.qmp_log('transaction', indent=2, actions=[
37    {'type': 'blockdev-snapshot-sync',
38     'data': {'device': 'drive0', 'snapshot-file': top,
39              'snapshot-node-name': 'snap'}},
40    {'type': 'block-dirty-bitmap-add',
41     'data': {'node': 'snap', 'name': 'bitmap0'}},
42    {'type': 'block-dirty-bitmap-merge',
43     'data': {'node': 'snap', 'target': 'bitmap0',
44              'bitmaps': [{'node': 'base', 'name': 'bitmap0'}]}}
45], filters=[iotests.filter_qmp_testfiles])
46
47result = vm.qmp('query-block')['return'][0]
48log("query-block: device = {}, node-name = {}, dirty-bitmaps:".format(
49    result['device'], result['inserted']['node-name']))
50log(result['dirty-bitmaps'], indent=2)
51
52vm.shutdown()
53