#!/usr/bin/env python
#
# Tests for temporary external snapshot when we have bitmaps.
#
# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import iotests
from iotests import qemu_img_create, file_path, log, filter_qmp_event

iotests.verify_image_format(supported_fmts=['qcow2'])

base, top = file_path('base', 'top')
size = 64 * 1024 * 3


def print_bitmap(msg, vm):
    result = vm.qmp('query-block')['return'][0]
    if 'dirty-bitmaps' in result:
        bitmap = result['dirty-bitmaps'][0]
        log('{}: name={} dirty-clusters={}'.format(msg, bitmap['name'],
            bitmap['count'] // 64 // 1024))
    else:
        log(msg + ': not found')


def test(persistent, restart):
    assert persistent or not restart
    log("\nTestcase {}persistent {} restart\n".format(
            '' if persistent else 'non-', 'with' if restart else 'without'))

    qemu_img_create('-f', iotests.imgfmt, base, str(size))

    vm = iotests.VM().add_drive(base)
    vm.launch()

    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0',
               persistent=persistent)
    vm.hmp_qemu_io('drive0', 'write 0 64K')
    print_bitmap('initial bitmap', vm)

    vm.qmp_log('blockdev-snapshot-sync', device='drive0', snapshot_file=top,
               format=iotests.imgfmt, filters=[iotests.filter_qmp_testfiles])
    vm.hmp_qemu_io('drive0', 'write 64K 512')
    print_bitmap('check that no bitmaps are in snapshot', vm)

    if restart:
        log("... Restart ...")
        vm.shutdown()
        vm = iotests.VM().add_drive(top)
        vm.launch()

    vm.qmp_log('block-commit', device='drive0', top=top,
               filters=[iotests.filter_qmp_testfiles])
    ev = vm.events_wait((('BLOCK_JOB_READY', None),
                         ('BLOCK_JOB_COMPLETED', None)))
    log(filter_qmp_event(ev))
    if (ev['event'] == 'BLOCK_JOB_COMPLETED'):
        vm.shutdown()
        log(vm.get_log())
        exit()

    vm.qmp_log('block-job-complete', device='drive0')
    ev = vm.event_wait('BLOCK_JOB_COMPLETED')
    log(filter_qmp_event(ev))
    print_bitmap('check bitmap after commit', vm)

    vm.hmp_qemu_io('drive0', 'write 128K 64K')
    print_bitmap('check updated bitmap', vm)

    vm.shutdown()


test(persistent=False, restart=False)
test(persistent=True, restart=False)
test(persistent=True, restart=True)
