1bf654b37SAndrey Shinkevich#!/usr/bin/env python3 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 3bf654b37SAndrey Shinkevich# 4bf654b37SAndrey Shinkevich# Test for dumping of qcow2 image metadata 5bf654b37SAndrey Shinkevich# 6bf654b37SAndrey Shinkevich# Copyright (c) 2020 Virtuozzo International GmbH 7bf654b37SAndrey Shinkevich# 8bf654b37SAndrey Shinkevich# This program is free software; you can redistribute it and/or modify 9bf654b37SAndrey Shinkevich# it under the terms of the GNU General Public License as published by 10bf654b37SAndrey Shinkevich# the Free Software Foundation; either version 2 of the License, or 11bf654b37SAndrey Shinkevich# (at your option) any later version. 12bf654b37SAndrey Shinkevich# 13bf654b37SAndrey Shinkevich# This program is distributed in the hope that it will be useful, 14bf654b37SAndrey Shinkevich# but WITHOUT ANY WARRANTY; without even the implied warranty of 15bf654b37SAndrey Shinkevich# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16bf654b37SAndrey Shinkevich# GNU General Public License for more details. 17bf654b37SAndrey Shinkevich# 18bf654b37SAndrey Shinkevich# You should have received a copy of the GNU General Public License 19bf654b37SAndrey Shinkevich# along with this program. If not, see <http://www.gnu.org/licenses/>. 20bf654b37SAndrey Shinkevich# 21bf654b37SAndrey Shinkevich 22bf654b37SAndrey Shinkevichimport iotests 23bf654b37SAndrey Shinkevichimport subprocess 24*093a13acSJohn Snowfrom iotests import qemu_img_create, qemu_io_log, file_path, log, \ 2532911369SHanna Reitz verify_qcow2_zstd_compression 26bf654b37SAndrey Shinkevich 27b30b8077SVladimir Sementsov-Ogievskiyiotests.script_initialize(supported_fmts=['qcow2'], 28b30b8077SVladimir Sementsov-Ogievskiy unsupported_imgopts=['refcount_bits', 'compat']) 2932911369SHanna Reitzverify_qcow2_zstd_compression() 30bf654b37SAndrey Shinkevich 31bf654b37SAndrey Shinkevichdisk = file_path('disk') 32bf654b37SAndrey Shinkevichchunk = 1024 * 1024 33bf654b37SAndrey Shinkevich 34bf654b37SAndrey Shinkevich 35bf654b37SAndrey Shinkevichdef create_bitmap(bitmap_number, disabled): 36bf654b37SAndrey Shinkevich granularity = 1 << (14 + bitmap_number) 37bf654b37SAndrey Shinkevich bitmap_name = 'bitmap-' + str(bitmap_number) 38bf654b37SAndrey Shinkevich args = ['bitmap', '--add', '-g', f'{granularity}', '-f', iotests.imgfmt, 39bf654b37SAndrey Shinkevich disk, bitmap_name] 40bf654b37SAndrey Shinkevich if disabled: 41bf654b37SAndrey Shinkevich args.append('--disable') 42bf654b37SAndrey Shinkevich 433d53818fSJohn Snow iotests.qemu_img(*args) 44bf654b37SAndrey Shinkevich 45bf654b37SAndrey Shinkevich 46bf654b37SAndrey Shinkevichdef write_to_disk(offset, size): 47bf654b37SAndrey Shinkevich write = f'write {offset} {size}' 48*093a13acSJohn Snow qemu_io_log('-c', write, disk) 49bf654b37SAndrey Shinkevich 50bf654b37SAndrey Shinkevich 51bf654b37SAndrey Shinkevichdef add_bitmap(num, begin, end, disabled): 52bf654b37SAndrey Shinkevich log(f'Add bitmap {num}') 53bf654b37SAndrey Shinkevich create_bitmap(num, disabled) 54bf654b37SAndrey Shinkevich for i in range(begin, end): 55bf654b37SAndrey Shinkevich write_to_disk((i) * chunk, chunk) 56bf654b37SAndrey Shinkevich log('') 57bf654b37SAndrey Shinkevich 58bf654b37SAndrey Shinkevich 59677e0baeSVladimir Sementsov-Ogievskiydef test(compression_type: str, json_output: bool) -> None: 60677e0baeSVladimir Sementsov-Ogievskiy qemu_img_create('-f', iotests.imgfmt, 61677e0baeSVladimir Sementsov-Ogievskiy '-o', f'compression_type={compression_type}', 62677e0baeSVladimir Sementsov-Ogievskiy disk, '10M') 63bf654b37SAndrey Shinkevich add_bitmap(1, 0, 6, False) 64bf654b37SAndrey Shinkevich add_bitmap(2, 6, 8, True) 65677e0baeSVladimir Sementsov-Ogievskiy 66677e0baeSVladimir Sementsov-Ogievskiy cmd = ['./qcow2.py', disk, 'dump-header'] 67677e0baeSVladimir Sementsov-Ogievskiy if json_output: 68677e0baeSVladimir Sementsov-Ogievskiy cmd.append('-j') 69677e0baeSVladimir Sementsov-Ogievskiy 70677e0baeSVladimir Sementsov-Ogievskiy subprocess.run(cmd) 71677e0baeSVladimir Sementsov-Ogievskiy 72677e0baeSVladimir Sementsov-Ogievskiy 73677e0baeSVladimir Sementsov-Ogievskiytest('zlib', False) 74677e0baeSVladimir Sementsov-Ogievskiytest('zstd', True) 75