Andrey Shinkevich | bf654b3 | 2020-08-06 22:35:47 +0300 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw quick |
Andrey Shinkevich | bf654b3 | 2020-08-06 22:35:47 +0300 | [diff] [blame] | 3 | # |
| 4 | # Test for dumping of qcow2 image metadata |
| 5 | # |
| 6 | # Copyright (c) 2020 Virtuozzo International GmbH |
| 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 | import subprocess |
| 24 | from iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_io |
| 25 | |
| 26 | iotests.script_initialize(supported_fmts=['qcow2']) |
| 27 | |
| 28 | disk = file_path('disk') |
| 29 | chunk = 1024 * 1024 |
| 30 | |
| 31 | |
| 32 | def create_bitmap(bitmap_number, disabled): |
| 33 | granularity = 1 << (14 + bitmap_number) |
| 34 | bitmap_name = 'bitmap-' + str(bitmap_number) |
| 35 | args = ['bitmap', '--add', '-g', f'{granularity}', '-f', iotests.imgfmt, |
| 36 | disk, bitmap_name] |
| 37 | if disabled: |
| 38 | args.append('--disable') |
| 39 | |
| 40 | iotests.qemu_img_pipe(*args) |
| 41 | |
| 42 | |
| 43 | def write_to_disk(offset, size): |
| 44 | write = f'write {offset} {size}' |
| 45 | log(qemu_io('-c', write, disk), filters=[filter_qemu_io]) |
| 46 | |
| 47 | |
| 48 | def add_bitmap(num, begin, end, disabled): |
| 49 | log(f'Add bitmap {num}') |
| 50 | create_bitmap(num, disabled) |
| 51 | for i in range(begin, end): |
| 52 | write_to_disk((i) * chunk, chunk) |
| 53 | log('') |
| 54 | |
| 55 | |
| 56 | qemu_img_create('-f', iotests.imgfmt, disk, '10M') |
| 57 | |
| 58 | add_bitmap(1, 0, 6, False) |
| 59 | add_bitmap(2, 6, 8, True) |
Vladimir Sementsov-Ogievskiy | fb07b5c | 2021-01-16 16:44:15 +0300 | [diff] [blame] | 60 | dump = ['./qcow2.py', disk, 'dump-header'] |
Andrey Shinkevich | bf654b3 | 2020-08-06 22:35:47 +0300 | [diff] [blame] | 61 | subprocess.run(dump) |
Andrey Shinkevich | 76bbbb2 | 2020-08-06 22:35:57 +0300 | [diff] [blame] | 62 | # Dump the metadata in JSON format |
| 63 | dump.append('-j') |
| 64 | subprocess.run(dump) |