From nobody Mon Feb 9 08:05:58 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=1596745635; cv=none; d=zohomail.com; s=zohoarc; b=fU09tEHEthf3UYzFJW2eNV33LgyJzRUofL3XWrguDER4D2OzER7FVYIIX0cC+xSremKYbox6CrcuImJIMqT+wpR6jUIVXwtOnZm/WPelSdtTPpN/saZ/eMQHWm7bOmpCYHYUUJNvd1mSIrxZ2hHQXe0RsZkSeZplw4RwfpPOg7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745635; 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=yRZZdyIIX14B535mX7xfftZCzm1rEg78ItdpI2LXo8s=; b=a9Kw5UyXRTAYZYXR0i/iqjjkA4aJO3toLnVF8oHrb3u7KZoebg7UUDvqil7rn8JRrtClEsensWiX6iwP15qlTWP3CQiqV8LY7nrJdm+1IbeAZ9FNo7N7ojQD4sRJuAcgxe3cvrtr5Qy+2LCUshNpOwSLp2LtOjJchCDXezWYAXQ= 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 1596745635196125.20872623242178; Thu, 6 Aug 2020 13:27:15 -0700 (PDT) Received: from localhost ([::1]:54260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mTp-0007d2-Rl for importer@patchew.org; Thu, 06 Aug 2020 16:27:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgO-0002SI-VX; Thu, 06 Aug 2020 15:36:08 -0400 Received: from relay.sw.ru ([185.231.240.75]:56480 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Kq-95; Thu, 06 Aug 2020 15:36:08 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgC-0003k9-3C; Thu, 06 Aug 2020 22:35:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 10/11] qcow2_format.py: support dumping metadata in JSON format Date: Thu, 6 Aug 2020 22:35:56 +0300 Message-Id: <1596742557-320265-11-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-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/08/06 15:35:59 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 autolearn=ham autolearn_force=no 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" Implementation of dumping QCOW2 image metadata. The sample output: { "Header_extensions": [ { "name": "Feature table", "magic": 1745090647, "length": 192, "data_str": "" }, { "name": "Bitmaps", "magic": 595929205, "length": 24, "data": { "nb_bitmaps": 2, "reserved32": 0, "bitmap_directory_size": 64, "bitmap_directory_offset": 1048576, "bitmap_directory": [ { "name": "bitmap-1", "bitmap_table_offset": 589824, "bitmap_table_size": 1, "flags": 2, "type": 1, "granularity_bits": 15, "name_size": 8, "extra_data_size": 0, "bitmap_table": [ { "type": "serialized", "offset": 655360 }, ... Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 5a298b2..8adc995 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -19,6 +19,15 @@ =20 import struct import string +import json + + +class ComplexEncoder(json.JSONEncoder): + def default(self, obj): + if hasattr(obj, 'to_json'): + return obj.to_json() + else: + return json.JSONEncoder.default(self, obj) =20 =20 class Qcow2Field: @@ -110,6 +119,10 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): for i, field in enumerate(self.fields)) =20 def dump(self, is_json=3DFalse): + if is_json: + print(json.dumps(self.to_json(), indent=3D4, cls=3DComplexEnco= der)) + return + for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -445,6 +458,10 @@ class QcowHeader(Qcow2Struct): fd.write(buf) =20 def dump_extensions(self, is_json=3DFalse): + if is_json: + print(json.dumps(self.extensions, indent=3D4, cls=3DComplexEnc= oder)) + return + for ex in self.extensions: print('Header extension:') ex.dump() --=20 1.8.3.1