| 1 | #!/usr/bin/env python3 |
| 2 | # group: rw quick |
| 3 | # |
| 4 | # Tests dirty-bitmap backup with unaligned bitmap granularity |
| 5 | # |
| 6 | # Copyright (c) 2020 Proxmox Server Solutions |
| 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 | # owner=s.reiter@proxmox.com |
| 22 | |
| 23 | import iotests |
| 24 | from iotests import qemu_img_create, qemu_img_log, file_path |
| 25 | |
| 26 | iotests.script_initialize(supported_fmts=['qcow2'], |
| 27 | supported_protocols=['file'], |
| 28 | require_hmp=True) |
| 29 | |
| 30 | test_img = file_path('test.qcow2') |
| 31 | target_img = file_path('target.qcow2') |
| 32 | |
| 33 | # unaligned by one byte |
| 34 | image_len = 4097 |
| 35 | bitmap_granularity = 4096 |
| 36 | |
| 37 | qemu_img_create('-f', iotests.imgfmt, test_img, str(image_len)) |
| 38 | |
| 39 | # create VM |
| 40 | vm = iotests.VM().add_drive(test_img) |
| 41 | vm.launch() |
| 42 | |
| 43 | # write to the entire image |
| 44 | vm.hmp_qemu_io('drive0', 'write -P0x16 0 4096'); |
| 45 | vm.hmp_qemu_io('drive0', 'write -P0x17 4096 1'); |
| 46 | |
| 47 | # do backup and wait for completion |
| 48 | vm.qmp('drive-backup', **{ |
| 49 | 'device': 'drive0', |
| 50 | 'sync': 'full', |
| 51 | 'target': target_img |
| 52 | }) |
| 53 | |
| 54 | event = vm.event_wait(name='BLOCK_JOB_COMPLETED', |
| 55 | match={'data': {'device': 'drive0'}}, |
| 56 | timeout=5.0) |
| 57 | |
| 58 | # shutdown to sync images |
| 59 | vm.shutdown() |
| 60 | |
| 61 | # backup succeeded, check if image is correct |
| 62 | qemu_img_log('compare', test_img, target_img) |