1#!/usr/bin/env python3 2# 3# Test parallels load bitmap 4# 5# Copyright (c) 2021 Virtuozzo International GmbH. 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 21import json 22import iotests 23from iotests import qemu_nbd_popen, qemu_img_pipe, log, file_path 24 25iotests.script_initialize(supported_fmts=['parallels']) 26 27nbd_sock = file_path('nbd-sock', base_dir=iotests.sock_dir) 28disk = iotests.file_path('disk') 29bitmap = 'e4f2eed0-37fe-4539-b50b-85d2e7fd235f' 30nbd_opts = f'driver=nbd,server.type=unix,server.path={nbd_sock}' \ 31 f',x-dirty-bitmap=qemu:dirty-bitmap:{bitmap}' 32 33 34iotests.unarchive_sample_image('parallels-with-bitmap', disk) 35 36 37with qemu_nbd_popen('--read-only', f'--socket={nbd_sock}', 38 f'--bitmap={bitmap}', '-f', iotests.imgfmt, disk): 39 out = qemu_img_pipe('map', '--output=json', '--image-opts', nbd_opts) 40 chunks = json.loads(out) 41 cluster = 64 * 1024 42 43 log('dirty clusters (cluster size is 64K):') 44 for c in chunks: 45 assert c['start'] % cluster == 0 46 assert c['length'] % cluster == 0 47 if c['data']: 48 continue 49 50 a = c['start'] // cluster 51 b = (c['start'] + c['length']) // cluster 52 if b - a > 1: 53 log(f'{a}-{b-1}') 54 else: 55 log(a) 56