From nobody Sun May 19 09:42:11 2024 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=1594973940; cv=none; d=zohomail.com; s=zohoarc; b=KukRs2tQ4xvsxS9OF4QyLtFHz54BgFperKllxA3dLhecH13eLQ4a3RJ8AH5xpQt4SrkoqBCAZCLtpjwE/Ot8TiJBPyxshlivLp15mWEkkv2Sbn46/c1YFihYJrvEv/jQMx0+GCVXckm++BjkvoUYQ6CWHXa59FYzllTOOA/B2qU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973940; 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=JRn6WgKkAnNr4uT3T1noU9bns2+FMssvvBb2GjAN0Gk=; b=CT7xai5EY0H/qOtQYJaxZqgts4xXJv+aoV8PMZ9XYnVxzRKHEj4eK6OZekbHH0auZ7G3djyrrpks1OOw9P5x4wS+MYCneaBWYr7bllbjOCtsvCHuBZpBeaA/mFVmg9kapxZjPyCFCf/e3AK1xVD0jKNTNg6nSnJC20r/vFA0Eec= 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 1594973940055712.1816779542513; Fri, 17 Jul 2020 01:19:00 -0700 (PDT) Received: from localhost ([::1]:53526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLa6-0008SQ-QK for importer@patchew.org; Fri, 17 Jul 2020 04:18:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWT-0001tU-Eo; Fri, 17 Jul 2020 04:15:14 -0400 Received: from relay.sw.ru ([185.231.240.75]:49982 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 1jwLWK-0007JJ-HJ; Fri, 17 Jul 2020 04:15:13 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-Gn; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 01/11] qcow2: Fix capitalization of header extension constant. Date: Fri, 17 Jul 2020 11:14:49 +0300 Message-Id: <1594973699-781898-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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" Make the capitalization of the hexadecimal numbers consistent for the QCOW2 header extension constants in docs/interop/qcow2.txt. Suggested-by: Eric Blake Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/qcow2.c | 2 +- docs/interop/qcow2.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index fadf342..6ad6bdc 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -66,7 +66,7 @@ typedef struct { } QEMU_PACKED QCowExtension; =20 #define QCOW2_EXT_MAGIC_END 0 -#define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA +#define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xe2792aca #define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 #define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 #define QCOW2_EXT_MAGIC_BITMAPS 0x23852875 diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index cb72346..f072e27 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -231,7 +231,7 @@ be stored. Each extension has a structure like the foll= owing: =20 Byte 0 - 3: Header extension type: 0x00000000 - End of the header extension area - 0xE2792ACA - Backing file format name string + 0xe2792aca - Backing file format name string 0x6803f857 - Feature name table 0x23852875 - Bitmaps extension 0x0537be77 - Full disk encryption header pointer --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973909; cv=none; d=zohomail.com; s=zohoarc; b=Y6gcPl/NFAoOt9cVrg5L3vXfbWGACEjXpNbdAEl1EbM69xawDuItVp51ul+JWp3d92Urm/YNDEFOnvN4QWPVjucnlXyC44RQ4JJhXemzGwxNR5ewHmxEVGigH2xyuzWo9oavBqUJL4KA9bt8irvdZyYAKAUO3HnyDF8QieQ0HD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973909; 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=jTaQe+3C4V+UcRj4btutD2ZIpAv4td/tmxwTbSW57kA=; b=NnKqJJQsIzBt4m62AiyteiDx2m0AaGorp8HiEulsEPhBBXkfnczuy1bjOx6Bz3bTZ2dmDMODiPENZGF82nSomdaSt2SWbbmfQGKHSmqL+P2KpwUHCXN/wNzQPkBpI+KrVp29WJ+8mFNBP5RMYYGwYZWp7bF0eor2noFqKgwfX70= 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 1594973909606570.626080318737; Fri, 17 Jul 2020 01:18:29 -0700 (PDT) Received: from localhost ([::1]:50346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLZc-00079t-7g for importer@patchew.org; Fri, 17 Jul 2020 04:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWN-0001qp-Qt; Fri, 17 Jul 2020 04:15:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:49994 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 1jwLWK-0007JP-Cs; Fri, 17 Jul 2020 04:15:07 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-Hu; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 02/11] qcow2_format.py: make printable data an extension class member Date: Fri, 17 Jul 2020 11:14:50 +0300 Message-Id: <1594973699-781898-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" Let us differ binary data type from string one for the extension data variable and keep the string as the QcowHeaderExtension class member. Signed-off-by: Andrey Shinkevich Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index cc432e7..2f3681b 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -165,6 +165,13 @@ class QcowHeaderExtension(Qcow2Struct): self.data =3D fd.read(padded) assert self.data is not None =20 + data_str =3D self.data[:self.length] + if all(c in string.printable.encode('ascii') for c in data_str): + data_str =3D f"'{ data_str.decode('ascii') }'" + else: + data_str =3D '' + self.data_str =3D data_str + if self.magic =3D=3D QCOW2_EXT_MAGIC_BITMAPS: self.obj =3D Qcow2BitmapExt(data=3Dself.data) else: @@ -174,12 +181,7 @@ class QcowHeaderExtension(Qcow2Struct): super().dump() =20 if self.obj is None: - data =3D self.data[:self.length] - if all(c in string.printable.encode('ascii') for c in data): - data =3D f"'{ data.decode('ascii') }'" - else: - data =3D '' - print(f'{"data":<25} {data}') + print(f'{"data":<25} {self.data_str}') else: self.obj.dump() =20 --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594974069; cv=none; d=zohomail.com; s=zohoarc; b=gbsraWfXV2cnT1bV/wMCUd26eQF6Z0P67LIxGdb7Ftny7OB6Wnjg5dR403R0wy5zhnjA5ks+a1aDC2fe1qNdd7h/6LTQaEb6NKzmbRLa1wI/czi9cjmk3n1qOdDqJpS70vJKnRBJtFLWok1gSYkAVMY/YLyi32jtUj+R9sVrgPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594974069; 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=IZ6jlrW18LbEC1dA1PgDAHglN6V5z/E+kVw9I+uYngM=; b=Bp3xhxK2O8Id/3OtyrQ8C0lRwCs8Rvsv+r9bIm1m70JOTkroIu34Hn2ZZ+15fmnD1oEcHrTCe1lS+KuCO+oxF1M9XUau1dcNjFM5QsMgSYz6MNF2pSvMia6e7ZV07xHo0MGB5EKqT1QjU7ty2D76pqSByX2wTK1GkxsuyiBPRd0= 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 1594974069077567.9220658237961; Fri, 17 Jul 2020 01:21:09 -0700 (PDT) Received: from localhost ([::1]:35152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLcB-0004DQ-Qk for importer@patchew.org; Fri, 17 Jul 2020 04:21:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWU-0001tm-C8; Fri, 17 Jul 2020 04:15:14 -0400 Received: from relay.sw.ru ([185.231.240.75]:50006 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 1jwLWK-0007JU-Ch; Fri, 17 Jul 2020 04:15:14 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-J5; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 03/11] qcow2_format.py: change Qcow2BitmapExt initialization method Date: Fri, 17 Jul 2020 11:14:51 +0300 Message-Id: <1594973699-781898-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" There are two ways to initialize a class derived from Qcow2Struct: 1. Pass a block of binary data to the constructor. 2. Pass the file descriptor to allow reading the file from constructor. Let's change the Qcow2BitmapExt initialization method from 1 to 2 to support a scattered reading in the initialization chain. The implementation comes with the patch that follows. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 36 ++++++++++++++++++++++------------= -- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 2f3681b..d4a9974 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -113,6 +113,11 @@ class Qcow2BitmapExt(Qcow2Struct): ('u64', '{:#x}', 'bitmap_directory_offset') ) =20 + def __init__(self, fd): + super().__init__(fd=3Dfd) + tail =3D struct.calcsize(self.fmt) % 8 + if tail: + fd.seek(8 - tail, 1) =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 @@ -161,21 +166,24 @@ class QcowHeaderExtension(Qcow2Struct): else: assert all(v is None for v in (magic, length, data)) super().__init__(fd=3Dfd) - padded =3D (self.length + 7) & ~7 - self.data =3D fd.read(padded) - assert self.data is not None - - data_str =3D self.data[:self.length] - if all(c in string.printable.encode('ascii') for c in data_str): - data_str =3D f"'{ data_str.decode('ascii') }'" - else: - data_str =3D '' - self.data_str =3D data_str + if self.magic =3D=3D QCOW2_EXT_MAGIC_BITMAPS: + self.obj =3D Qcow2BitmapExt(fd=3Dfd) + self.data =3D None + else: + padded =3D (self.length + 7) & ~7 + self.data =3D fd.read(padded) + assert self.data is not None + self.obj =3D None + + if self.data is not None: + data_str =3D self.data[:self.length] + if all(c in string.printable.encode( + 'ascii') for c in data_str): + data_str =3D f"'{ data_str.decode('ascii') }'" + else: + data_str =3D '' + self.data_str =3D data_str =20 - if self.magic =3D=3D QCOW2_EXT_MAGIC_BITMAPS: - self.obj =3D Qcow2BitmapExt(data=3Dself.data) - else: - self.obj =3D None =20 def dump(self): super().dump() --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594974052; cv=none; d=zohomail.com; s=zohoarc; b=HRX1MRW/QofsrSZ4SSnBwv5iGzcavU8WdZRzs/QXdqHmyb43eJ4fXR+4juhf3QnIWdz6L1Y8xtlr7Ogv1Bb5QDzob/Gg6ZeSeBmS0JRVNI0JplTGR1VRsXXWT1KwSsRoO8xpwizIYGj34Vrm5f3QVXPPmViaBhlJ/3HsLW8qFcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594974052; 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=aWjclfz1ZcI/TI94jF7yVLgfxuyJWL9apZHcugkLCsQ=; b=lZYTHNvmEVVqTkz9xjTip4kVCP4+OeuvwSAaE9b1yx8h5lSt+/AUt6cRDeHjMo3Wfw6vRUf/kLaFvFCQKUqwmP9dh5ylCwj9mXFIFuqOXtkIQhUsQTgBUSBpiZrI7tLzbdw+EQi9ZPzI6LTsORnRnq5CAvKFbtqtgiWN7me/D8I= 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 159497405299497.2423703878311; Fri, 17 Jul 2020 01:20:52 -0700 (PDT) Received: from localhost ([::1]:34114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLbv-0003mz-Q3 for importer@patchew.org; Fri, 17 Jul 2020 04:20:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWg-0002Mh-1f; Fri, 17 Jul 2020 04:15:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:49968 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 1jwLWe-0007JD-Go; Fri, 17 Jul 2020 04:15:25 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-KC; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 04/11] qcow2_format.py: dump bitmap flags in human readable way. Date: Fri, 17 Jul 2020 11:14:52 +0300 Message-Id: <1594973699-781898-5-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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" Introduce the class BitmapFlags that parses a bitmap flags mask. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index d4a9974..b447344 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -40,6 +40,22 @@ class Flags64(Qcow2Field): return str(bits) =20 =20 +class BitmapFlags(Qcow2Field): + + flags =3D { + 0x1: 'in-use', + 0x2: 'auto' + } + + def __str__(self): + bits =3D [] + for bit in range(64): + flag =3D self.value & (1 << bit) + if flag: + bits.append(self.flags.get(flag, f'bit-{bit}')) + return f'{self.value:#x} ({bits})' + + class Enum(Qcow2Field): =20 def __str__(self): --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973792; cv=none; d=zohomail.com; s=zohoarc; b=Zpr4VzXG55ZWB3eAivWxE4af92XuzT7gGMhsq43hkM8OW40WvVw3daTfoLYrfHl+HptXMF8rGwSF4o+mWsLUzwPicfOrevrcuANw+XXiIubTMAq+LkqWL4DqK7BkUs1uzb+GrlU5qIW8QhPWi08NDuFfaSBracQXi58fV7w5kR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973792; 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=rv/qsgDgR+mWxnjICdkmoDC9PJilfK9cjFffz1JU82A=; b=U6URUoCKhZsoIq8uzM9DTXi6pAuBUt8SYo49xEfagI0ezE04xQ+4nBsEx4c7CbibFvonAcZAB8+HXQbfNYW2/U7SHacKn/tS01MejXqZ14n1t5v7WCraJkD1Ux5W0zAjVrjb8DyKIbPK5ntrz2+8tEkhfWWA3cE0u9kmRH0rq7g= 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 1594973792447156.06012295283267; Fri, 17 Jul 2020 01:16:32 -0700 (PDT) Received: from localhost ([::1]:41894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLXi-0003gM-AX for importer@patchew.org; Fri, 17 Jul 2020 04:16:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWN-0001pf-3Q; Fri, 17 Jul 2020 04:15:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:49984 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 1jwLWK-0007JN-9h; Fri, 17 Jul 2020 04:15:06 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-LN; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 05/11] qcow2_format.py: Dump bitmap directory information Date: Fri, 17 Jul 2020 11:14:53 +0300 Message-Id: <1594973699-781898-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" Read and dump entries from the bitmap directory of QCOW2 image. Header extension: magic 0x23852875 (Bitmaps) ... Bitmap name bitmap-1 bitmap_table_offset 0xf0000 bitmap_table_size 1 flags 0x2 (['auto']) type 1 granularity_bits 16 name_size 8 extra_data_size 0 Suggested-by: Kevin Wolf Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 47 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index b447344..05a8aa9 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -134,6 +134,53 @@ class Qcow2BitmapExt(Qcow2Struct): tail =3D struct.calcsize(self.fmt) % 8 if tail: fd.seek(8 - tail, 1) + position =3D fd.tell() + self.read_bitmap_directory(fd) + fd.seek(position) + + def read_bitmap_directory(self, fd): + fd.seek(self.bitmap_directory_offset) + self.bitmap_directory =3D \ + [Qcow2BitmapDirEntry(fd) for _ in range(self.nb_bitmaps)] + + def dump(self): + super().dump() + for entry in self.bitmap_directory: + print() + entry.dump() + + +class Qcow2BitmapDirEntry(Qcow2Struct): + + fields =3D ( + ('u64', '{:#x}', 'bitmap_table_offset'), + ('u32', '{}', 'bitmap_table_size'), + ('u32', BitmapFlags, 'flags'), + ('u8', '{}', 'type'), + ('u8', '{}', 'granularity_bits'), + ('u16', '{}', 'name_size'), + ('u32', '{}', 'extra_data_size') + ) + + def __init__(self, fd): + super().__init__(fd=3Dfd) + # Seek relative to the current position in the file + fd.seek(self.extra_data_size, 1) + bitmap_name =3D fd.read(self.name_size) + self.name =3D bitmap_name.decode('ascii') + # Move position to the end of the entry in the directory + entry_raw_size =3D self.bitmap_dir_entry_raw_size() + padding =3D ((entry_raw_size + 7) & ~7) - entry_raw_size + fd.seek(padding, 1) + + def bitmap_dir_entry_raw_size(self): + return struct.calcsize(self.fmt) + self.name_size + \ + self.extra_data_size + + def dump(self): + print(f'{"Bitmap name":<25} {self.name}') + super(Qcow2BitmapDirEntry, self).dump() + =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973928; cv=none; d=zohomail.com; s=zohoarc; b=UJI8ncJO9/y6d93on3trwVKuxg+bqWTsbPqGkhFs79at6vIyt4Q43IsLKjCnAEmbPeKNnd2hU2UUR6Krx7maYpb1BBkGXh5tyU7jc5jQrCI4Sco17hH+YZ00g7iaPUA5lyB3UsreDvMqiMRM2WHfsbXGKGWLlCWYv+mkKSA+r4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973928; 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=+g9p4ALMkB7yCtrpy2vMkuG50zHcXTT9tVR5uufFT50=; b=nmvbUJPIVigz02Y+OChy5Kld4YeIfFnUo1QY1C9h/FXG/qO8eZ12G08/LTXVVFXTdI0y87Um/BqjFSBeOMkyphjXo1H53P5Cypjq7CA9kFBXRvwfYVUiyil7rTx+LxB12PJoOTDxIGWsGNpeeiEgZYsrbRfhTK+mXKCz+5wjcO0= 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 1594973928670189.71701542742846; Fri, 17 Jul 2020 01:18:48 -0700 (PDT) Received: from localhost ([::1]:52372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLZv-0007yF-Gc for importer@patchew.org; Fri, 17 Jul 2020 04:18:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWg-0002OP-Nx; Fri, 17 Jul 2020 04:15:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:49986 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 1jwLWe-0007JM-FR; Fri, 17 Jul 2020 04:15:26 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-Me; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 06/11] qcow2_format.py: pass cluster size to substructures Date: Fri, 17 Jul 2020 11:14:54 +0300 Message-Id: <1594973699-781898-7-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" The cluster size of an image is the QcowHeader class member and may be obtained by dependent extension structures such as Qcow2BitmapExt for further bitmap table details print. Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 05a8aa9..ca0d350 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -129,19 +129,21 @@ class Qcow2BitmapExt(Qcow2Struct): ('u64', '{:#x}', 'bitmap_directory_offset') ) =20 - def __init__(self, fd): + def __init__(self, fd, cluster_size): super().__init__(fd=3Dfd) tail =3D struct.calcsize(self.fmt) % 8 if tail: fd.seek(8 - tail, 1) position =3D fd.tell() + self.cluster_size =3D cluster_size self.read_bitmap_directory(fd) fd.seek(position) =20 def read_bitmap_directory(self, fd): fd.seek(self.bitmap_directory_offset) self.bitmap_directory =3D \ - [Qcow2BitmapDirEntry(fd) for _ in range(self.nb_bitmaps)] + [Qcow2BitmapDirEntry(fd, cluster_size=3Dself.cluster_size) + for _ in range(self.nb_bitmaps)] =20 def dump(self): super().dump() @@ -162,8 +164,9 @@ class Qcow2BitmapDirEntry(Qcow2Struct): ('u32', '{}', 'extra_data_size') ) =20 - def __init__(self, fd): + def __init__(self, fd, cluster_size): super().__init__(fd=3Dfd) + self.cluster_size =3D cluster_size # Seek relative to the current position in the file fd.seek(self.extra_data_size, 1) bitmap_name =3D fd.read(self.name_size) @@ -203,11 +206,13 @@ class QcowHeaderExtension(Qcow2Struct): # then padding to next multiply of 8 ) =20 - def __init__(self, magic=3DNone, length=3DNone, data=3DNone, fd=3DNone= ): + def __init__(self, magic=3DNone, length=3DNone, data=3DNone, fd=3DNone, + cluster_size=3DNone): """ Support both loading from fd and creation from user data. For fd-based creation current position in a file will be used to r= ead the data. + The cluster_size value may be obtained by dependent structures. =20 This should be somehow refactored and functionality should be move= d to superclass (to allow creation of any qcow2 struct), but then, fiel= ds @@ -230,7 +235,7 @@ class QcowHeaderExtension(Qcow2Struct): assert all(v is None for v in (magic, length, data)) super().__init__(fd=3Dfd) if self.magic =3D=3D QCOW2_EXT_MAGIC_BITMAPS: - self.obj =3D Qcow2BitmapExt(fd=3Dfd) + self.obj =3D Qcow2BitmapExt(fd=3Dfd, cluster_size=3Dcluste= r_size) self.data =3D None else: padded =3D (self.length + 7) & ~7 @@ -319,7 +324,7 @@ class QcowHeader(Qcow2Struct): end =3D self.cluster_size =20 while fd.tell() < end: - ext =3D QcowHeaderExtension(fd=3Dfd) + ext =3D QcowHeaderExtension(fd=3Dfd, cluster_size=3Dself.clust= er_size) if ext.magic =3D=3D 0: break else: --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973988; cv=none; d=zohomail.com; s=zohoarc; b=NnWzguF0AVGDwh3mII3hX/LxerSYfBzlCdjkcr+ku8lsA1zZqqEFvZ7D/DlNzES0/9xn+pOdOxKG3VbfmqOo7SJhGWTb50TAi+sPWtNzoCqwIMCMFv1vxibdSA4X1lRrFps47vOtOM2cMrpG9ecudrD1KhyLyikm0mt9TxrTpPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973988; 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=UYQrDLXj7tFsDnJp2Pg2oca7DDprung3pQwg3tU8b8A=; b=VMrLVIBSKxz7J5EdENLv/DRdp6LhWc7m4ugHq9QOR3RFAP46dacnHmQusYIgDMUCO1nIguGsrVyBgsTZCEJF4waP681zgK5xSFQ/JQtD1sYN7/XtovYvzUEPjO1Vm5WT4Mr6G6/Nx5IrI57l6oHM0Kj87OxmvrU9E8XwrqPe1ws= 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 1594973988178560.0877363745551; Fri, 17 Jul 2020 01:19:48 -0700 (PDT) Received: from localhost ([::1]:58130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLas-0001xs-Lc for importer@patchew.org; Fri, 17 Jul 2020 04:19:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWQ-0001rn-Mm; Fri, 17 Jul 2020 04:15:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:49990 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 1jwLWK-0007JS-G1; Fri, 17 Jul 2020 04:15:10 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-Nr; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 07/11] qcow2_format.py: Dump bitmap table serialized entries Date: Fri, 17 Jul 2020 11:14:55 +0300 Message-Id: <1594973699-781898-8-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" Add bitmap table information to the QCOW2 metadata dump. Bitmap name bitmap-1 ... Bitmap table type offset size 0 serialized 4718592 65536 1 serialized 4294967296 65536 2 serialized 5348033147437056 65536 3 serialized 13792273858822144 65536 4 serialized 4718592 65536 5 serialized 4294967296 65536 6 serialized 4503608217305088 65536 7 serialized 14073748835532800 65536 Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 41 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 41 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index ca0d350..ad1918c 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -175,6 +175,10 @@ class Qcow2BitmapDirEntry(Qcow2Struct): entry_raw_size =3D self.bitmap_dir_entry_raw_size() padding =3D ((entry_raw_size + 7) & ~7) - entry_raw_size fd.seek(padding, 1) + self.bitmap_table =3D Qcow2BitmapTable(fd=3Dfd, + offset=3Dself.bitmap_table_of= fset, + size=3Dself.bitmap_table_size, + cluster_size=3Dself.cluster_s= ize) =20 def bitmap_dir_entry_raw_size(self): return struct.calcsize(self.fmt) + self.name_size + \ @@ -183,6 +187,43 @@ class Qcow2BitmapDirEntry(Qcow2Struct): def dump(self): print(f'{"Bitmap name":<25} {self.name}') super(Qcow2BitmapDirEntry, self).dump() + self.bitmap_table.dump() + + +class Qcow2BitmapTableEntry: + + BME_TABLE_ENTRY_OFFSET_MASK =3D 0x00fffffffffffe00 + BME_TABLE_ENTRY_FLAG_ALL_ONES =3D 1 + + def __init__(self, entry): + self.offset =3D entry & self.BME_TABLE_ENTRY_OFFSET_MASK + if self.offset: + self.type =3D 'serialized' + elif entry & self.BME_TABLE_ENTRY_FLAG_ALL_ONES: + self.type =3D 'all-ones' + else: + self.type =3D 'all-zeroes' + + +class Qcow2BitmapTable: + + def __init__(self, fd, offset, size, cluster_size): + self.entries =3D [] + self.cluster_size =3D cluster_size + table_size =3D size * 8 + position =3D fd.tell() + fd.seek(offset) + table =3D [e[0] for e in struct.iter_unpack('>Q', fd.read(table_si= ze))] + fd.seek(position) + for entry in table: + self.entries.append(Qcow2BitmapTableEntry(entry)) + + def dump(self): + size =3D self.cluster_size + bitmap_table =3D enumerate(self.entries) + print(f'{"Bitmap table":<14} {"type":<15} {"offset":<24} {"size"}') + for i, entry in bitmap_table: + print(f'{i:<14} {entry.type:<15} {entry.offset:<24} {size}') =20 =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973849; cv=none; d=zohomail.com; s=zohoarc; b=j6pnqpwQJVyBLquTYt3h2HrIQDkb9VQwR/RVhFbA9oK8M6lgd4fh5xyK4NuO5mTYWhN7nm+wZVSsUHtXpl6ADtBszIyLtJuIKSWlgvcdLFbWx3TUTlBlxD0vTy8ZKKLW2YgUlvyn4EfIAqRfHMfOSqVaxiJVrb375F/FmpQp/Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973849; 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=P5RlWHZ0tP2HTSorrvhbnF5BjHGNEmiBxEiOuoYjDc4=; b=dI5FKIJTEeM9ldsnXg0aHQSKREl+y1DlYFI3bq1IJ1+z3dkFiQhbeBjh7tpAO+Yc2HKTlZGHWGOiXqPWVa380DDhDSET+SvEQ1kMy7AZa2N35R7el7HXbT2Be4jw6WUWv2/VG+IGHwjhnBklUgv2Ih+eZVArOvzJYukW/IDwn8o= 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 1594973849854735.6057269163874; Fri, 17 Jul 2020 01:17:29 -0700 (PDT) Received: from localhost ([::1]:45162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLYe-00050v-M6 for importer@patchew.org; Fri, 17 Jul 2020 04:17:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWT-0001sq-2B; Fri, 17 Jul 2020 04:15:13 -0400 Received: from relay.sw.ru ([185.231.240.75]:49970 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 1jwLWK-0007JF-CE; Fri, 17 Jul 2020 04:15:12 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-P7; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 08/11] qcow2.py: Introduce '-j' key to dump in JSON format Date: Fri, 17 Jul 2020 11:14:56 +0300 Message-Id: <1594973699-781898-9-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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=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" Add the command key to the qcow2.py arguments list to dump QCOW2 metadata in JSON format. Here is the suggested way to do that. The implementation of the dump in JSON format is in the patch that follows. Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2.py | 18 ++++++++++++++---- tests/qemu-iotests/qcow2_format.py | 5 +++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py index 0910e6a..77ca59c 100755 --- a/tests/qemu-iotests/qcow2.py +++ b/tests/qemu-iotests/qcow2.py @@ -26,16 +26,19 @@ from qcow2_format import ( ) =20 =20 +is_json =3D False + + def cmd_dump_header(fd): h =3D QcowHeader(fd) - h.dump() + h.dump(is_json) print() - h.dump_extensions() + h.dump_extensions(is_json) =20 =20 def cmd_dump_header_exts(fd): h =3D QcowHeader(fd) - h.dump_extensions() + h.dump_extensions(is_json) =20 =20 def cmd_set_header(fd, name, value): @@ -151,11 +154,14 @@ def main(filename, cmd, args): =20 =20 def usage(): - print("Usage: %s [, ...]" % sys.argv[0]) + print("Usage: %s [, ...] [, ...]" % sys.argv[0]) print("") print("Supported commands:") for name, handler, num_args, desc in cmds: print(" %-20s - %s" % (name, desc)) + print("") + print("Supported keys:") + print(" %-20s - %s" % ('-j', 'Dump in JSON format')) =20 =20 if __name__ =3D=3D '__main__': @@ -163,4 +169,8 @@ if __name__ =3D=3D '__main__': usage() sys.exit(1) =20 + is_json =3D '-j' in sys.argv + if is_json: + sys.argv.remove('-j') + main(sys.argv[1], sys.argv[2], sys.argv[3:]) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index ad1918c..2921a27 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -109,7 +109,7 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): self.__dict__ =3D dict((field[2], values[i]) for i, field in enumerate(self.fields)) =20 - def dump(self): + def dump(self, is_json=3DFalse): for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -147,6 +147,7 @@ class Qcow2BitmapExt(Qcow2Struct): =20 def dump(self): super().dump() + for entry in self.bitmap_directory: print() entry.dump() @@ -399,7 +400,7 @@ class QcowHeader(Qcow2Struct): buf =3D buf[0:header_bytes-1] fd.write(buf) =20 - def dump_extensions(self): + def dump_extensions(self, is_json=3DFalse): for ex in self.extensions: print('Header extension:') ex.dump() --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973915; cv=none; d=zohomail.com; s=zohoarc; b=AzvZnntq9laCyL4IPhSBF/TeKaXx+gZAJxcuEK52qmzM05bvIo5/N1xUnsrpWh3qImSiWTs9MLQY6971Nv+I/UQvOIJejHo0VPlZVTMpIJBiPDUW3D1b90G3x92sYZm3z/C6oLzsPVqt/XD74IMqa8LY8Wz1w/RU90m8YHcQJw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973915; 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=xxBJBUS0nOyOUigQ98FEcLzrwzXOvg1tHns1S5mVULY=; b=VE/4NFaWHdDIlTpyvzRF/Ur29/x6L6dU4Y4EJTprrWEG/7LUGL56kWboXGZkCFGKpKR2dcrBDmxe6Lbw7boiF8ZjTK7PeTvgTdA+0GuQ3cph9GbYo4K09h8KVyhrxHHDfkLMer2G5TpEA1x6FKmyVpuTgG2HbIbn3ZevKb5pAQU= 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 1594973915202431.03218724325484; Fri, 17 Jul 2020 01:18:35 -0700 (PDT) Received: from localhost ([::1]:50972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLZh-0007PP-VM for importer@patchew.org; Fri, 17 Jul 2020 04:18:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWO-0001qt-02; Fri, 17 Jul 2020 04:15:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:49998 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 1jwLWK-0007JR-DW; Fri, 17 Jul 2020 04:15:07 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-QU; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 09/11] qcow2_format.py: collect fields to dump in JSON format Date: Fri, 17 Jul 2020 11:14:57 +0300 Message-Id: <1594973699-781898-10-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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" As __dict__ is being extended with class members we do not want to print, add the to_dict() method to classes that returns a dictionary with desired fields and their values. Extend it in subclass when necessary to print the final dictionary in the JSON output which follows. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 38 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 38 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 2921a27..19d29b8 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -119,6 +119,9 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): =20 print('{:<25} {}'.format(f[2], value_str)) =20 + def to_dict(self): + return dict((f[2], self.__dict__[f[2]]) for f in self.fields) + =20 class Qcow2BitmapExt(Qcow2Struct): =20 @@ -152,6 +155,11 @@ class Qcow2BitmapExt(Qcow2Struct): print() entry.dump() =20 + def to_dict(self): + fields_dict =3D super().to_dict() + fields_dict.update(bitmap_directory=3Dself.bitmap_directory) + return fields_dict + =20 class Qcow2BitmapDirEntry(Qcow2Struct): =20 @@ -190,6 +198,13 @@ class Qcow2BitmapDirEntry(Qcow2Struct): super(Qcow2BitmapDirEntry, self).dump() self.bitmap_table.dump() =20 + def to_dict(self): + fields_dict =3D super().to_dict() + fields_dict.update(bitmap_table=3Dself.bitmap_table) + bmp_name =3D dict(name=3Dself.name) + bme_dict =3D {**bmp_name, **fields_dict} + return bme_dict + =20 class Qcow2BitmapTableEntry: =20 @@ -205,6 +220,9 @@ class Qcow2BitmapTableEntry: else: self.type =3D 'all-zeroes' =20 + def to_dict(self): + return dict(type=3Dself.type, offset=3Dself.offset) + =20 class Qcow2BitmapTable: =20 @@ -226,6 +244,9 @@ class Qcow2BitmapTable: for i, entry in bitmap_table: print(f'{i:<14} {entry.type:<15} {entry.offset:<24} {size}') =20 + def to_dict(self): + return dict(entries=3Dself.entries) + =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 @@ -241,6 +262,9 @@ class QcowHeaderExtension(Qcow2Struct): 0x44415441: 'Data file' } =20 + def to_dict(self): + return self.mapping.get(self.value, "") + fields =3D ( ('u32', Magic, 'magic'), ('u32', '{}', 'length') @@ -303,6 +327,17 @@ class QcowHeaderExtension(Qcow2Struct): else: self.obj.dump() =20 + def to_dict(self): + fields_dict =3D super().to_dict() + ext_name =3D dict(name=3Dself.Magic(self.magic)) + he_dict =3D {**ext_name, **fields_dict} + if self.obj is not None: + he_dict.update(data=3Dself.obj) + else: + he_dict.update(data_str=3Dself.data_str) + + return he_dict + @classmethod def create(cls, magic, data): return QcowHeaderExtension(magic, len(data), data) @@ -405,3 +440,6 @@ class QcowHeader(Qcow2Struct): print('Header extension:') ex.dump() print() + + def to_dict(self): + return super().to_dict() --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973807; cv=none; d=zohomail.com; s=zohoarc; b=l4Sl8KA/X2gyk7NaAsPdEnxIMyLl5v4Q/3tILLZ0p4dbLFMMQomyJiqxSMXwMtdY2DsGk5IlJRhPdkO4EMq6FUrgHJsucud9ynR3PwOQAr1ZlKzVKDUznF03AHrtqw8+crmcJnDB+Ke9iZ91mCDCb9/zJuDL/7HazmSpQ/nkVSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973807; 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=vx35zuuSgJFImydkcU/uqr+gfp5GzxdB2EkHXDOi+wk=; b=Lp6eV35jzLcpUxg0XL0lzKqkdGwGYYnyRLJWEQn8pj2YSoQsGqW4akqZdtXOW7NXgbQ9FMfu+Agnn8NdJy+ED7/qeV3phpxRuiNmYrRrYhZcGQR7TPDMoCgrRHQwy0dw8udQ/tMIn3Hfbwy/J41HlfKHUKkjuhBRIT4hME0vI+g= 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 1594973807036300.94612513123604; Fri, 17 Jul 2020 01:16:47 -0700 (PDT) Received: from localhost ([::1]:43288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLXx-0004F6-T3 for importer@patchew.org; Fri, 17 Jul 2020 04:16:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWQ-0001rs-Uv; Fri, 17 Jul 2020 04:15:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:49980 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 1jwLWK-0007JH-GM; Fri, 17 Jul 2020 04:15:10 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-SP; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 10/11] qcow2_format.py: introduce Qcow2HeaderExtensionsDoc class Date: Fri, 17 Jul 2020 11:14:58 +0300 Message-Id: <1594973699-781898-11-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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" Per original script design, QcowHeader class may dump the QCOW2 header info separately from the QCOW2 extensions info. To implement the to_dict() method for dumping extensions, let us introduce the class Qcow2HeaderExtensionsDoc. Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 19d29b8..d2a8659 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -248,6 +248,15 @@ class Qcow2BitmapTable: return dict(entries=3Dself.entries) =20 =20 +class Qcow2HeaderExtensionsDoc: + + def __init__(self, extensions): + self.extensions =3D extensions + + def to_dict(self): + return dict(Header_extensions=3Dself.extensions) + + QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 =20 --=20 1.8.3.1 From nobody Sun May 19 09:42:11 2024 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=1594973992; cv=none; d=zohomail.com; s=zohoarc; b=kmr6XbOYFh9/+bpaHMExgTQ4scJIK3OC+hhlCQVPC+6j8p3oaQYQSlOUwTZ9lcxv4MehuBxDuFPx5nyKUfX5Er89UwSPUY9EWb6UZ9mMQpT+rc+qtX8agdo2T25ryzRns1S9hu7BetzMc2z5IZh5wkIjoNwXm1r5KnAJh7rpZh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594973992; 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=dKVJHJXOqF1yrg/pY4OXszC/7zeWv3i4MXEt7xzfsok=; b=MrSy3TuvkeCJMZT9bkXFqjusReq+bcdkrfgoe09KIfpjNp+aK20d1RFuzINd2ib18olCB0fNPVkAZDSA1wdzgva7e3afIHMjBwdbNJNDcIGPBFlBVbIRAtTnIoD0jnS8vtsL1zV+t8j8PP5uCU+X8Sfyc85/tRp4X02vM80o3rw= 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 1594973992227931.027028742933; Fri, 17 Jul 2020 01:19:52 -0700 (PDT) Received: from localhost ([::1]:58450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jwLax-00027A-3G for importer@patchew.org; Fri, 17 Jul 2020 04:19:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jwLWR-0001sk-Lt; Fri, 17 Jul 2020 04:15:13 -0400 Received: from relay.sw.ru ([185.231.240.75]:49972 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 1jwLWK-0007JE-Ei; Fri, 17 Jul 2020 04:15:11 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jwLWC-0003cP-Tj; Fri, 17 Jul 2020 11:14:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v11 11/11] qcow2_format.py: support dumping metadata in JSON format Date: Fri, 17 Jul 2020 11:14:59 +0300 Message-Id: <1594973699-781898-12-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594973699-781898-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1594973699-781898-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/07/17 04:15:01 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": { "entries": [ { "type": "serialized", "offset": 655360 }, ... Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index d2a8659..d40eb49 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_dict'): + return obj.to_dict() + else: + return json.JSONEncoder.default(self, obj) =20 =20 class Qcow2Field: @@ -110,6 +119,11 @@ 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_dict(), indent=3D4, + cls=3DComplexEncoder)) + return + for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -445,6 +459,12 @@ class QcowHeader(Qcow2Struct): fd.write(buf) =20 def dump_extensions(self, is_json=3DFalse): + if is_json: + ext_doc =3D Qcow2HeaderExtensionsDoc(self.extensions) + print(json.dumps(ext_doc.to_dict(), indent=3D4, + cls=3DComplexEncoder)) + return + for ex in self.extensions: print('Header extension:') ex.dump() --=20 1.8.3.1