xref: /openbmc/qemu/tests/qemu-iotests/260 (revision 5d9388d4b23a5302acb53052add07514285b2976)
1*5d9388d4SVladimir Sementsov-Ogievskiy#!/usr/bin/env python
2*5d9388d4SVladimir Sementsov-Ogievskiy#
3*5d9388d4SVladimir Sementsov-Ogievskiy# Tests for temporary external snapshot when we have bitmaps.
4*5d9388d4SVladimir Sementsov-Ogievskiy#
5*5d9388d4SVladimir Sementsov-Ogievskiy# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
6*5d9388d4SVladimir Sementsov-Ogievskiy#
7*5d9388d4SVladimir Sementsov-Ogievskiy# This program is free software; you can redistribute it and/or modify
8*5d9388d4SVladimir Sementsov-Ogievskiy# it under the terms of the GNU General Public License as published by
9*5d9388d4SVladimir Sementsov-Ogievskiy# the Free Software Foundation; either version 2 of the License, or
10*5d9388d4SVladimir Sementsov-Ogievskiy# (at your option) any later version.
11*5d9388d4SVladimir Sementsov-Ogievskiy#
12*5d9388d4SVladimir Sementsov-Ogievskiy# This program is distributed in the hope that it will be useful,
13*5d9388d4SVladimir Sementsov-Ogievskiy# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*5d9388d4SVladimir Sementsov-Ogievskiy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*5d9388d4SVladimir Sementsov-Ogievskiy# GNU General Public License for more details.
16*5d9388d4SVladimir Sementsov-Ogievskiy#
17*5d9388d4SVladimir Sementsov-Ogievskiy# You should have received a copy of the GNU General Public License
18*5d9388d4SVladimir Sementsov-Ogievskiy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*5d9388d4SVladimir Sementsov-Ogievskiy#
20*5d9388d4SVladimir Sementsov-Ogievskiy
21*5d9388d4SVladimir Sementsov-Ogievskiyimport iotests
22*5d9388d4SVladimir Sementsov-Ogievskiyfrom iotests import qemu_img_create, file_path, log, filter_qmp_event
23*5d9388d4SVladimir Sementsov-Ogievskiy
24*5d9388d4SVladimir Sementsov-Ogievskiyiotests.verify_image_format(supported_fmts=['qcow2'])
25*5d9388d4SVladimir Sementsov-Ogievskiy
26*5d9388d4SVladimir Sementsov-Ogievskiybase, top = file_path('base', 'top')
27*5d9388d4SVladimir Sementsov-Ogievskiysize = 64 * 1024 * 3
28*5d9388d4SVladimir Sementsov-Ogievskiy
29*5d9388d4SVladimir Sementsov-Ogievskiy
30*5d9388d4SVladimir Sementsov-Ogievskiydef print_bitmap(msg, vm):
31*5d9388d4SVladimir Sementsov-Ogievskiy    result = vm.qmp('query-block')['return'][0]
32*5d9388d4SVladimir Sementsov-Ogievskiy    if 'dirty-bitmaps' in result:
33*5d9388d4SVladimir Sementsov-Ogievskiy        bitmap = result['dirty-bitmaps'][0]
34*5d9388d4SVladimir Sementsov-Ogievskiy        log('{}: name={} dirty-clusters={}'.format(msg, bitmap['name'],
35*5d9388d4SVladimir Sementsov-Ogievskiy            bitmap['count'] // 64 // 1024))
36*5d9388d4SVladimir Sementsov-Ogievskiy    else:
37*5d9388d4SVladimir Sementsov-Ogievskiy        log(msg + ': not found')
38*5d9388d4SVladimir Sementsov-Ogievskiy
39*5d9388d4SVladimir Sementsov-Ogievskiy
40*5d9388d4SVladimir Sementsov-Ogievskiydef test(persistent, restart):
41*5d9388d4SVladimir Sementsov-Ogievskiy    assert persistent or not restart
42*5d9388d4SVladimir Sementsov-Ogievskiy    log("\nTestcase {}persistent {} restart\n".format(
43*5d9388d4SVladimir Sementsov-Ogievskiy            '' if persistent else 'non-', 'with' if restart else 'without'))
44*5d9388d4SVladimir Sementsov-Ogievskiy
45*5d9388d4SVladimir Sementsov-Ogievskiy    qemu_img_create('-f', iotests.imgfmt, base, str(size))
46*5d9388d4SVladimir Sementsov-Ogievskiy
47*5d9388d4SVladimir Sementsov-Ogievskiy    vm = iotests.VM().add_drive(base)
48*5d9388d4SVladimir Sementsov-Ogievskiy    vm.launch()
49*5d9388d4SVladimir Sementsov-Ogievskiy
50*5d9388d4SVladimir Sementsov-Ogievskiy    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0',
51*5d9388d4SVladimir Sementsov-Ogievskiy               persistent=persistent)
52*5d9388d4SVladimir Sementsov-Ogievskiy    vm.hmp_qemu_io('drive0', 'write 0 64K')
53*5d9388d4SVladimir Sementsov-Ogievskiy    print_bitmap('initial bitmap', vm)
54*5d9388d4SVladimir Sementsov-Ogievskiy
55*5d9388d4SVladimir Sementsov-Ogievskiy    vm.qmp_log('blockdev-snapshot-sync', device='drive0', snapshot_file=top,
56*5d9388d4SVladimir Sementsov-Ogievskiy               format=iotests.imgfmt, filters=[iotests.filter_qmp_testfiles])
57*5d9388d4SVladimir Sementsov-Ogievskiy    vm.hmp_qemu_io('drive0', 'write 64K 512')
58*5d9388d4SVladimir Sementsov-Ogievskiy    print_bitmap('check that no bitmaps are in snapshot', vm)
59*5d9388d4SVladimir Sementsov-Ogievskiy
60*5d9388d4SVladimir Sementsov-Ogievskiy    if restart:
61*5d9388d4SVladimir Sementsov-Ogievskiy        log("... Restart ...")
62*5d9388d4SVladimir Sementsov-Ogievskiy        vm.shutdown()
63*5d9388d4SVladimir Sementsov-Ogievskiy        vm = iotests.VM().add_drive(top)
64*5d9388d4SVladimir Sementsov-Ogievskiy        vm.launch()
65*5d9388d4SVladimir Sementsov-Ogievskiy
66*5d9388d4SVladimir Sementsov-Ogievskiy    vm.qmp_log('block-commit', device='drive0', top=top,
67*5d9388d4SVladimir Sementsov-Ogievskiy               filters=[iotests.filter_qmp_testfiles])
68*5d9388d4SVladimir Sementsov-Ogievskiy    ev = vm.events_wait((('BLOCK_JOB_READY', None),
69*5d9388d4SVladimir Sementsov-Ogievskiy                         ('BLOCK_JOB_COMPLETED', None)))
70*5d9388d4SVladimir Sementsov-Ogievskiy    log(filter_qmp_event(ev))
71*5d9388d4SVladimir Sementsov-Ogievskiy    if (ev['event'] == 'BLOCK_JOB_COMPLETED'):
72*5d9388d4SVladimir Sementsov-Ogievskiy        vm.shutdown()
73*5d9388d4SVladimir Sementsov-Ogievskiy        log(vm.get_log())
74*5d9388d4SVladimir Sementsov-Ogievskiy        exit()
75*5d9388d4SVladimir Sementsov-Ogievskiy
76*5d9388d4SVladimir Sementsov-Ogievskiy    vm.qmp_log('block-job-complete', device='drive0')
77*5d9388d4SVladimir Sementsov-Ogievskiy    ev = vm.event_wait('BLOCK_JOB_COMPLETED')
78*5d9388d4SVladimir Sementsov-Ogievskiy    log(filter_qmp_event(ev))
79*5d9388d4SVladimir Sementsov-Ogievskiy    print_bitmap('check bitmap after commit', vm)
80*5d9388d4SVladimir Sementsov-Ogievskiy
81*5d9388d4SVladimir Sementsov-Ogievskiy    vm.hmp_qemu_io('drive0', 'write 128K 64K')
82*5d9388d4SVladimir Sementsov-Ogievskiy    print_bitmap('check updated bitmap', vm)
83*5d9388d4SVladimir Sementsov-Ogievskiy
84*5d9388d4SVladimir Sementsov-Ogievskiy    vm.shutdown()
85*5d9388d4SVladimir Sementsov-Ogievskiy
86*5d9388d4SVladimir Sementsov-Ogievskiy
87*5d9388d4SVladimir Sementsov-Ogievskiytest(persistent=False, restart=False)
88*5d9388d4SVladimir Sementsov-Ogievskiytest(persistent=True, restart=False)
89*5d9388d4SVladimir Sementsov-Ogievskiytest(persistent=True, restart=True)
90