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