Philippe Mathieu-Daudé | 7c47752 | 2020-01-30 17:32:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 2 | # |
Vladimir Sementsov-Ogievskiy | 3f7b2fa | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 3 | # Test external snapshot with bitmap copying and moving. |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 4 | # |
| 5 | # Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 2 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | |
| 21 | import iotests |
| 22 | from iotests import qemu_img_create, file_path, log |
| 23 | |
Vladimir Sementsov-Ogievskiy | 549fb88 | 2019-06-05 18:54:05 +0300 | [diff] [blame] | 24 | iotests.verify_image_format(supported_fmts=['qcow2']) |
| 25 | |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 26 | disk, top = file_path('disk', 'top') |
| 27 | size = 1024 * 1024 |
| 28 | |
| 29 | qemu_img_create('-f', iotests.imgfmt, disk, str(size)) |
| 30 | |
| 31 | vm = iotests.VM().add_drive(disk, opts='node-name=base') |
| 32 | vm.launch() |
| 33 | |
| 34 | vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap0') |
Vladimir Sementsov-Ogievskiy | 3f7b2fa | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 35 | vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap1', |
| 36 | persistent=True) |
| 37 | vm.qmp_log('block-dirty-bitmap-add', node='drive0', name='bitmap2', |
| 38 | persistent=True) |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 39 | |
| 40 | vm.hmp_qemu_io('drive0', 'write 0 512K') |
| 41 | |
| 42 | vm.qmp_log('transaction', indent=2, actions=[ |
| 43 | {'type': 'blockdev-snapshot-sync', |
| 44 | 'data': {'device': 'drive0', 'snapshot-file': top, |
| 45 | 'snapshot-node-name': 'snap'}}, |
Vladimir Sementsov-Ogievskiy | 3f7b2fa | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 46 | |
| 47 | # copy non-persistent bitmap0 |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 48 | {'type': 'block-dirty-bitmap-add', |
| 49 | 'data': {'node': 'snap', 'name': 'bitmap0'}}, |
| 50 | {'type': 'block-dirty-bitmap-merge', |
| 51 | 'data': {'node': 'snap', 'target': 'bitmap0', |
Vladimir Sementsov-Ogievskiy | 3f7b2fa | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 52 | 'bitmaps': [{'node': 'base', 'name': 'bitmap0'}]}}, |
| 53 | |
| 54 | # copy persistent bitmap1, original will be saved to base image |
| 55 | {'type': 'block-dirty-bitmap-add', |
| 56 | 'data': {'node': 'snap', 'name': 'bitmap1', 'persistent': True}}, |
| 57 | {'type': 'block-dirty-bitmap-merge', |
| 58 | 'data': {'node': 'snap', 'target': 'bitmap1', |
| 59 | 'bitmaps': [{'node': 'base', 'name': 'bitmap1'}]}}, |
| 60 | |
| 61 | # move persistent bitmap2, original will be removed and not saved |
| 62 | # to base image |
| 63 | {'type': 'block-dirty-bitmap-add', |
| 64 | 'data': {'node': 'snap', 'name': 'bitmap2', 'persistent': True}}, |
| 65 | {'type': 'block-dirty-bitmap-merge', |
| 66 | 'data': {'node': 'snap', 'target': 'bitmap2', |
| 67 | 'bitmaps': [{'node': 'base', 'name': 'bitmap2'}]}}, |
| 68 | {'type': 'block-dirty-bitmap-remove', |
| 69 | 'data': {'node': 'base', 'name': 'bitmap2'}} |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 70 | ], filters=[iotests.filter_qmp_testfiles]) |
| 71 | |
| 72 | result = vm.qmp('query-block')['return'][0] |
| 73 | log("query-block: device = {}, node-name = {}, dirty-bitmaps:".format( |
| 74 | result['device'], result['inserted']['node-name'])) |
| 75 | log(result['dirty-bitmaps'], indent=2) |
Vladimir Sementsov-Ogievskiy | 3f7b2fa | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 76 | log("\nbitmaps in backing image:") |
| 77 | log(result['inserted']['image']['backing-image']['format-specific'] \ |
| 78 | ['data']['bitmaps'], indent=2) |
Vladimir Sementsov-Ogievskiy | 403bb81 | 2019-05-28 19:33:31 -0400 | [diff] [blame] | 79 | |
| 80 | vm.shutdown() |