| 1 | #!/usr/bin/env python3 |
| 2 | # group: rw quick |
| 3 | # |
| 4 | # Tests for temporary external snapshot when we have bitmaps. |
| 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 | |
| 22 | import iotests |
| 23 | from iotests import qemu_img_create, file_path, log, filter_qmp_event |
| 24 | |
| 25 | iotests.script_initialize( |
| 26 | supported_fmts=['qcow2'], |
| 27 | unsupported_imgopts=['compat'], |
| 28 | require_hmp=True, |
| 29 | ) |
| 30 | |
| 31 | base, top = file_path('base', 'top') |
| 32 | size = 64 * 1024 * 3 |
| 33 | |
| 34 | |
| 35 | def print_bitmap(msg, vm): |
| 36 | result = vm.qmp('query-block')['return'][0] |
| 37 | info = result.get("inserted", {}) |
| 38 | if 'dirty-bitmaps' in info: |
| 39 | bitmap = info['dirty-bitmaps'][0] |
| 40 | log('{}: name={} dirty-clusters={}'.format(msg, bitmap['name'], |
| 41 | bitmap['count'] // 64 // 1024)) |
| 42 | else: |
| 43 | log(msg + ': not found') |
| 44 | |
| 45 | |
| 46 | def test(persistent, restart): |
| 47 | assert persistent or not restart |
| 48 | log("\nTestcase {}persistent {} restart\n".format( |
| 49 | '' if persistent else 'non-', 'with' if restart else 'without')) |
| 50 | |
| 51 | qemu_img_create('-f', iotests.imgfmt, base, str(size)) |
| 52 | |
| 53 | vm = iotests.VM().add_drive(base) |
| 54 | vm.launch() |
| 55 | |
| 56 | vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0', |
| 57 | persistent=persistent) |
| 58 | vm.hmp_qemu_io('drive0', 'write 0 64K') |
| 59 | print_bitmap('initial bitmap', vm) |
| 60 | |
| 61 | vm.qmp_log('blockdev-snapshot-sync', device='drive0', snapshot_file=top, |
| 62 | format=iotests.imgfmt, filters=[iotests.filter_qmp_testfiles]) |
| 63 | vm.hmp_qemu_io('drive0', 'write 64K 512') |
| 64 | print_bitmap('check that no bitmaps are in snapshot', vm) |
| 65 | |
| 66 | if restart: |
| 67 | log("... Restart ...") |
| 68 | vm.shutdown() |
| 69 | vm = iotests.VM().add_drive(top) |
| 70 | vm.launch() |
| 71 | |
| 72 | vm.qmp_log('block-commit', device='drive0', top=top, |
| 73 | filters=[iotests.filter_qmp_testfiles]) |
| 74 | ev = vm.events_wait((('BLOCK_JOB_READY', None), |
| 75 | ('BLOCK_JOB_COMPLETED', None))) |
| 76 | log(filter_qmp_event(ev)) |
| 77 | if (ev['event'] == 'BLOCK_JOB_COMPLETED'): |
| 78 | vm.shutdown() |
| 79 | log(vm.get_log()) |
| 80 | exit() |
| 81 | |
| 82 | vm.qmp_log('block-job-complete', device='drive0') |
| 83 | ev = vm.event_wait('BLOCK_JOB_COMPLETED') |
| 84 | log(filter_qmp_event(ev)) |
| 85 | print_bitmap('check bitmap after commit', vm) |
| 86 | |
| 87 | vm.hmp_qemu_io('drive0', 'write 128K 64K') |
| 88 | print_bitmap('check updated bitmap', vm) |
| 89 | |
| 90 | vm.shutdown() |
| 91 | |
| 92 | |
| 93 | test(persistent=False, restart=False) |
| 94 | test(persistent=True, restart=False) |
| 95 | test(persistent=True, restart=True) |