From nobody Mon Feb 9 18:45:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1591910700; cv=none; d=zohomail.com; s=zohoarc; b=fCdMeX+VRn9hWgObx2G1ayatdtlLTN3gtycPvxV9TdNRof79R7+nlm4l02cKIJbd83EsQsuVBszLCgKlAzJZgndM4jzS8URwdKRNFqDbaoQ90+cBc8H2Cr/iNkCilpqU4Ruj4l0VN/fCWPMvg35IX5zNmW9F/U0zEkfbmO/fVgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591910700; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Sjw7PhxfjetVrYvr/X3l3P4P/DBWt5PuTwqCyGqyjWA=; b=MIiPk64TLV7QcjQzwibddSErM+Rtf1nWAMeOb3Prcu8GWFIlCt4ynpglerl3vhrXUhhp/eY6pY4g3a62w6blfZF7Bq9Zf9Zbxm3lAgXMEf02rKIjWnjnO9zXmcEd/DkgiECb+Slp3xX2gK/0IsJ59blehRj/bJ+zBMghBvYTbvw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591910700915433.5033802016045; Thu, 11 Jun 2020 14:25:00 -0700 (PDT) Received: from localhost ([::1]:48006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjUh1-0002kY-Au for importer@patchew.org; Thu, 11 Jun 2020 17:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjUbi-00034W-HL; Thu, 11 Jun 2020 17:19:30 -0400 Received: from relay.sw.ru ([185.231.240.75]:40360 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjUbf-00057s-2N; Thu, 11 Jun 2020 17:19:30 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjUbW-0001xE-Pv; Fri, 12 Jun 2020 00:19:18 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v6 3/8] qcow2_format.py: Dump bitmap directory info Date: Fri, 12 Jun 2020 00:19:15 +0300 Message-Id: <1591910360-867499-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591910360-867499-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591910360-867499-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/11 17:19:22 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Read and dump entries from the bitmap directory of QCOW2 image with the script qcow2.py. Header extension: magic 0x23852875 (Bitmaps) ... Bitmap name bitmap-1 flag auto table size 8 (bytes) bitmap_table_offset 0x90000 bitmap_table_size 1 flags 0 type 1 granularity_bits 16 name_size 8 extra_data_size 0 Suggested-by: Kevin Wolf Signed-off-by: Andrey Shinkevich Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 75 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 75 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index d4f0000..a7868a7 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -103,6 +103,10 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): print('{:<25} {}'.format(f[2], value_str)) =20 =20 +# seek relative to the current position in the file +FROM_CURRENT =3D 1 + + class Qcow2BitmapExt(Qcow2Struct): =20 fields =3D ( @@ -112,6 +116,73 @@ class Qcow2BitmapExt(Qcow2Struct): ('u64', '{:#x}', 'bitmap_directory_offset') ) =20 + def read_bitmap_directory(self, fd): + self.bitmaps =3D [] + fd.seek(self.bitmap_directory_offset) + buf_size =3D struct.calcsize(Qcow2BitmapDirEntry.fmt) + + for n in range(self.nb_bitmaps): + buf =3D fd.read(buf_size) + dir_entry =3D Qcow2BitmapDirEntry(data=3Dbuf) + fd.seek(dir_entry.extra_data_size, FROM_CURRENT) + bitmap_name =3D fd.read(dir_entry.name_size) + dir_entry.name =3D bitmap_name.decode('ascii') + self.bitmaps.append(dir_entry) + entry_raw_size =3D dir_entry.bitmap_dir_entry_raw_size() + shift =3D ((entry_raw_size + 7) & ~7) - entry_raw_size + fd.seek(shift, FROM_CURRENT) + + def load(self, fd): + self.read_bitmap_directory(fd) + + def dump(self): + super().dump() + for bm in self.bitmaps: + bm.dump_bitmap_dir_entry() + + +BME_FLAG_IN_USE =3D 1 << 0 +BME_FLAG_AUTO =3D 1 << 1 + + +class Qcow2BitmapDirEntry(Qcow2Struct): + + name =3D '' + + fields =3D ( + ('u64', '{:#x}', 'bitmap_table_offset'), + ('u32', '{}', 'bitmap_table_size'), + ('u32', '{}', 'flags'), + ('u8', '{}', 'type'), + ('u8', '{}', 'granularity_bits'), + ('u16', '{}', 'name_size'), + ('u32', '{}', 'extra_data_size') + ) + + def __init__(self, data): + super().__init__(data=3Ddata) + + self.bitmap_table_bytes =3D self.bitmap_table_size \ + * struct.calcsize('Q') + + self.bitmap_flags =3D [] + if (self.flags & BME_FLAG_IN_USE): + self.bitmap_flags.append("in-use") + if (self.flags & BME_FLAG_AUTO): + self.bitmap_flags.append("auto") + + def bitmap_dir_entry_raw_size(self): + return struct.calcsize(self.fmt) + self.name_size + \ + self.extra_data_size + + def dump_bitmap_dir_entry(self): + print() + print(f'{"Bitmap name":<25} {self.name}') + for fl in self.bitmap_flags: + print(f'{"flag":<25} {fl}') + print(f'{"table size ":<25} {self.bitmap_table_bytes} {"(bytes)"}') + super().dump() + =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 @@ -253,6 +324,10 @@ class QcowHeader(Qcow2Struct): else: self.extensions.append(ext) =20 + for ext in self.extensions: + if ext.obj is not None: + ext.obj.load(fd) + def update_extensions(self, fd): =20 fd.seek(self.header_length) --=20 1.8.3.1