#!/usr/bin/env python3
#
# 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.script_initialize(
    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)
