From nobody Sun May 19 05:51:03 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=1591920388; cv=none; d=zohomail.com; s=zohoarc; b=EcpB67bCyUNcNdwHDYKmOjS80gnce4eDLFDjaP0CJR0Myoel8Nx/Zfy9pnKKpNEHbkJotH4RyEbH7IFH5BNFNLp57KYbeiUQ+IdvZ+Li9sQQCMse2pguUhjboTIta9NnVjD7jbr/WuNIw2Oz3bTxKYZV+crziiU7x+h56igJrQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920388; 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=OGRHgSTboD1W16jvabI+KWyiSNjnyMyM8RpEcbTZ56k=; b=STuofAeQ8rZ55NQpKApWwnXpnFGiWxGTCC/SDcQPgIKOrB1esFIi4A/pH01uwwdDjbxrXnVdK11R7DOk4nJ3t2mD6dDCD/kcrCLxxCZLN9oB5zGA02RokVOQEZPe9mQuE+j42wA0/zcRUi2CUu1w7lpIJuZxToreNgYjICt2pyw= 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 1591920388665325.3608090487289; Thu, 11 Jun 2020 17:06:28 -0700 (PDT) Received: from localhost ([::1]:36882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXDH-00023E-8o for importer@patchew.org; Thu, 11 Jun 2020 20:06:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC2-0008Lj-8u; Thu, 11 Jun 2020 20:05:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:52852 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 1jjXBy-0006IE-Jd; Thu, 11 Jun 2020 20:05:09 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-H4; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 1/9] iotests: Fix for magic hexadecimal output in 291 Date: Fri, 12 Jun 2020 03:04:54 +0300 Message-Id: <1591920302-1002219-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" This issue was introduced in the earlier patch: "qcow2_format: refactor QcowHeaderExtension as a subclass of Qcow2Struct". Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/291.out | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out index 1d4f9cd..ccfcdc5 100644 --- a/tests/qemu-iotests/291.out +++ b/tests/qemu-iotests/291.out @@ -16,17 +16,17 @@ wrote 1048576/1048576 bytes at offset 2097152 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) Check resulting qcow2 header extensions: Header extension: -magic 3799591626 (Backing format) +magic 0xe2792aca (Backing format) length 5 data 'qcow2' =20 Header extension: -magic 1745090647 (Feature table) +magic 0x6803f857 (Feature table) length 336 data =20 Header extension: -magic 595929205 (Bitmaps) +magic 0x23852875 (Bitmaps) length 24 nb_bitmaps 2 reserved32 0 @@ -86,12 +86,12 @@ Format specific information: corrupt: false Check resulting qcow2 header extensions: Header extension: -magic 1745090647 (Feature table) +magic 0x6803f857 (Feature table) length 336 data =20 Header extension: -magic 595929205 (Bitmaps) +magic 0x23852875 (Bitmaps) length 24 nb_bitmaps 3 reserved32 0 --=20 1.8.3.1 From nobody Sun May 19 05:51:03 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=1591920524; cv=none; d=zohomail.com; s=zohoarc; b=CobulYqcg3hHqkuhtNjc+ZVq2/H7neCbYpgUonAcfZDN4bokuDKQxUGhlKVlZO1LY6XputFr4lp/fMqjO4U7CKhO8CJq/CqqNvp0vsErxrWD/iACLNLh8l0OadJEZbm/Q8amrddZ4BpDvLtOf1DM8qwShlxU13KqRerpQRcMWRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920524; 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=5j52zIyJ7h91qu9hmAm+RftLtQQI+uwoY4LI941x/l0=; b=kOjh1z8hAh/J8u5QhQcCgitOYBJwkmCBV2l0SiUqwX5nR4D1BwStYzFn7XeLj+RHq7zL/Idr1fmuqOuZ9VlqE/4AT3b2dVfJ0W/2qHN7ay0VvOLyyYb22IfyAhyMmhdYsI5FvAi+4o4NmUcSiTrhExjvsfFE5umCrDWRuxssLLE= 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 1591920524382387.77572214752377; Thu, 11 Jun 2020 17:08:44 -0700 (PDT) Received: from localhost ([::1]:46776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXFT-0006ZB-4h for importer@patchew.org; Thu, 11 Jun 2020 20:08:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC3-0008Mw-Hy; Thu, 11 Jun 2020 20:05:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:52848 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 1jjXBy-0006I9-Oh; Thu, 11 Jun 2020 20:05:11 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-IP; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 2/9] qcow2: Fix capitalization of header extension constant. Date: Fri, 12 Jun 2020 03:04:55 +0300 Message-Id: <1591920302-1002219-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" 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 --- 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 0cd2e67..80dfe5f 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 05:51:03 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=1591920422; cv=none; d=zohomail.com; s=zohoarc; b=Yv/rSlAfoMlWRTluJU2djGRDDFY+aQF7XTvLTj2RyKSn1s4PIlcr0t52iogUOAJASvV/Ltd0Y/gWNwv8onKXRmWiSyChDHaydzmWy6BhTcJUjeoDGVVnBk7kU5SkWlLGQAnL1BaUZZ9/IjT4V9P9c9Qf0N2OuVsoMargSCd22oU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920422; 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=j98/2L8Eg2YeBaa7IbMCoTSo3hCWgqXe9buMwSKjwT0=; b=I0wGA1tJSGmFT7bEwdpQhISaBnrbKHa25ZoL+nsxrwktqX2o8eo1HH7QFv7/yyYEBThf+C01qjZQ9RBcv1IEnEgvxSzmNmdDB4C8GcSKS7QXD4esfSrvL/1AYkzrxb+TNH1EqYgTFBrjlMVMYBOQ7gRimUmBhr8FrFJVQUh90Oc= 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 1591920422071390.5912507036013; Thu, 11 Jun 2020 17:07:02 -0700 (PDT) Received: from localhost ([::1]:38184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXDo-0002Z3-KR for importer@patchew.org; Thu, 11 Jun 2020 20:07:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC3-0008MK-4e; Thu, 11 Jun 2020 20:05:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:52854 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 1jjXBy-0006IF-JM; Thu, 11 Jun 2020 20:05:10 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-JZ; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 3/9] qcow2_format.py: make printable data an extension class member Date: Fri, 12 Jun 2020 03:04:56 +0300 Message-Id: <1591920302-1002219-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" 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 0f65fd1..d4f0000 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -164,6 +164,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: @@ -173,12 +180,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 05:51:03 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=1591920388; cv=none; d=zohomail.com; s=zohoarc; b=NYD4l3adk5XXfE4DavcbQimTrRU1F4Ddk2/wXdTPB/R6xnSyMDY71meWjtRcLgJXeFSDZdfewmpGUhh7R11U4mfPJXNoOaN+V2Or1zw00gbNlzrdE6w96ihdsrFpoZCwONUDojuQanjLivE0xfkq7JOf8oxFh1SWWvOC0dkenlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920388; 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=u8ra7fZyUjF93RSFO5TSyHOhl2PwzllkJwsG6gCQURA=; b=Cbtlo21y0hl81l78IazyzDbAz/l9C8gp8A3sKkfBGB7suHVrWL7bhjCbkUBFBWBkV9g5OMA8t799Xy3oONCR8vK+vcOemRtTlvhfqWcRODWaS3SPAse3PgHd3CHdB46+v10EydPONc4Ymw/tWbSbqqrIBuyJ0+Bsc0A8Gcuvngw= 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 15919203885671006.0763388819091; Thu, 11 Jun 2020 17:06:28 -0700 (PDT) Received: from localhost ([::1]:36764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXDH-00020F-6e for importer@patchew.org; Thu, 11 Jun 2020 20:06:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC1-0008LT-Q3; Thu, 11 Jun 2020 20:05:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:52836 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 1jjXBy-0006I7-IA; Thu, 11 Jun 2020 20:05:08 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-Kv; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 4/9] qcow2_format.py: Dump bitmap directory information Date: Fri, 12 Jun 2020 03:04:57 +0300 Message-Id: <1591920302-1002219-5-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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. It extends the output in the test case #291. 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/291.out | 52 ++++++++++++++++++++++++++ tests/qemu-iotests/qcow2_format.py | 75 ++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 127 insertions(+) diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out index ccfcdc5..d847419 100644 --- a/tests/qemu-iotests/291.out +++ b/tests/qemu-iotests/291.out @@ -33,6 +33,27 @@ reserved32 0 bitmap_directory_size 0x40 bitmap_directory_offset 0x510000 =20 +Bitmap name b1 +table size 8 (bytes) +bitmap_table_offset 0x4e0000 +bitmap_table_size 1 +flags 0 +type 1 +granularity_bits 19 +name_size 2 +extra_data_size 0 + +Bitmap name b2 +flag auto +table size 8 (bytes) +bitmap_table_offset 0x500000 +bitmap_table_size 1 +flags 2 +type 1 +granularity_bits 16 +name_size 2 +extra_data_size 0 + =20 =3D=3D=3D Bitmap preservation not possible to non-qcow2 =3D=3D=3D =20 @@ -98,6 +119,37 @@ reserved32 0 bitmap_directory_size 0x60 bitmap_directory_offset 0x520000 =20 +Bitmap name b1 +table size 8 (bytes) +bitmap_table_offset 0x470000 +bitmap_table_size 1 +flags 0 +type 1 +granularity_bits 19 +name_size 2 +extra_data_size 0 + +Bitmap name b2 +flag auto +table size 8 (bytes) +bitmap_table_offset 0x490000 +bitmap_table_size 1 +flags 2 +type 1 +granularity_bits 16 +name_size 2 +extra_data_size 0 + +Bitmap name b0 +table size 8 (bytes) +bitmap_table_offset 0x510000 +bitmap_table_size 1 +flags 0 +type 1 +granularity_bits 16 +name_size 2 +extra_data_size 0 + =20 =3D=3D=3D Check bitmap contents =3D=3D=3D =20 diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index d4f0000..90eff92 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 From nobody Sun May 19 05:51:03 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=1591920600; cv=none; d=zohomail.com; s=zohoarc; b=NVTz6wckwH7M+UtHvwEDF+VX2fSAnKARAF6mfeyOROWzkNvhNViMVttx087Aux1FjjfHX9oyCYhliqxXqDtArLEWGedtNgXa8uarzcc3F//1FoKBOL+K2T19eC4zBpj+VqDZrv63IEJjbh0boy+/dZ34+qwOlrziWSvM9jwQu5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920600; 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=3D3chZKlVxISDDyWIt/ggaA2rOUwHLPYl5LsNqYv44c=; b=b/gZmKlO6iM1fKDNbcvW34RCtfD9SnaVgMTLrkvgEEq7CTiFzsEspyW/qu94FG8MALimfYoQyT6yOOEiGS+ClN8xdy50W1Zni5y/XGgegGVPCNwGOgmrAZKqopVdO/7+WWUER5WLbOZXyGQXLVWzFNx6nZZlGwYhz8brzNoU9gE= 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 1591920600934965.3091307362292; Thu, 11 Jun 2020 17:10:00 -0700 (PDT) Received: from localhost ([::1]:52106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXGh-0000u1-MV for importer@patchew.org; Thu, 11 Jun 2020 20:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC3-0008NP-Pg; Thu, 11 Jun 2020 20:05:11 -0400 Received: from relay.sw.ru ([185.231.240.75]:52838 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 1jjXBy-0006IB-Oy; Thu, 11 Jun 2020 20:05:11 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-Lz; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 5/9] qcow2_format.py: pass cluster size to substructures Date: Fri, 12 Jun 2020 03:04:58 +0300 Message-Id: <1591920302-1002219-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" 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 --- tests/qemu-iotests/qcow2_format.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 90eff92..eb99119 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -116,6 +116,10 @@ class Qcow2BitmapExt(Qcow2Struct): ('u64', '{:#x}', 'bitmap_directory_offset') ) =20 + def __init__(self, data, cluster_size): + super().__init__(data=3Ddata) + self.cluster_size =3D cluster_size + def read_bitmap_directory(self, fd): self.bitmaps =3D [] fd.seek(self.bitmap_directory_offset) @@ -123,7 +127,8 @@ class Qcow2BitmapExt(Qcow2Struct): =20 for n in range(self.nb_bitmaps): buf =3D fd.read(buf_size) - dir_entry =3D Qcow2BitmapDirEntry(data=3Dbuf) + dir_entry =3D Qcow2BitmapDirEntry(data=3Dbuf, + cluster_size=3Dself.cluster_si= ze) 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') @@ -159,8 +164,9 @@ class Qcow2BitmapDirEntry(Qcow2Struct): ('u32', '{}', 'extra_data_size') ) =20 - def __init__(self, data): + def __init__(self, data, cluster_size): super().__init__(data=3Ddata) + self.cluster_size =3D cluster_size =20 self.bitmap_table_bytes =3D self.bitmap_table_size \ * struct.calcsize('Q') @@ -205,11 +211,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 @@ -243,7 +251,8 @@ class QcowHeaderExtension(Qcow2Struct): self.data_str =3D data_str =20 if self.magic =3D=3D QCOW2_EXT_MAGIC_BITMAPS: - self.obj =3D Qcow2BitmapExt(data=3Dself.data) + self.obj =3D Qcow2BitmapExt(data=3Dself.data, + cluster_size=3Dcluster_size) else: self.obj =3D None =20 @@ -318,7 +327,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 05:51:03 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=1591920687; cv=none; d=zohomail.com; s=zohoarc; b=llOAWqr/k4uy5kGYm4T4/O5iZZHs4S3p+ZqBOBseXyp612VAszh5oIlb7JxD/zEfNyklLoSAkh6sPkeF7fThK3Zyy3G4hL3V1IyPMs+YtYfy4viFdcB5bRZIdJtl82bK1yXmlcyMmxjKQE8vyMMk3c9y00+LcDoH6ljrdSOpDfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920687; 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=Cj5KrORH2mow1Y3/twHQ+73XR+QKcVVdahTy9hEhJBs=; b=Kfo0A/YW4EHMJxPKC+fCYSWTKK6uAgt2UXgurmgS/hVCwI1haBMMroiPNiSqmo+lzsJLJKo381nnQ7upfHg59Ooh81RBSv074uVufZZeakhQIhpKvAkvjZQ6sEtQPucwONZR076RC+ruVUAA9D0yj1CJIlzSuNVpTcskpOxN5hs= 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 159192068785618.183802475832636; Thu, 11 Jun 2020 17:11:27 -0700 (PDT) Received: from localhost ([::1]:54448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXI6-0002iE-Lt for importer@patchew.org; Thu, 11 Jun 2020 20:11:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC4-0008PM-JK; Thu, 11 Jun 2020 20:05:12 -0400 Received: from relay.sw.ru ([185.231.240.75]:52850 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 1jjXBy-0006IC-Ou; Thu, 11 Jun 2020 20:05:12 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-N6; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 6/9] qcow2_format.py: Dump bitmap table serialized entries Date: Fri, 12 Jun 2020 03:04:59 +0300 Message-Id: <1591920302-1002219-7-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" Add bitmap table information to the QCOW2 metadata dump. It extends the output of the test case #291 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 Reviewed-by: Eric Blake --- tests/qemu-iotests/291.out | 50 ++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/qcow2_format.py | 40 ++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out index d847419..595327c 100644 --- a/tests/qemu-iotests/291.out +++ b/tests/qemu-iotests/291.out @@ -42,6 +42,16 @@ type 1 granularity_bits 19 name_size 2 extra_data_size 0 +Bitmap table type offset size +0 serialized 5046272 65536 +1 all-zeroes 0 65536 +2 all-zeroes 0 65536 +3 all-zeroes 0 65536 +4 all-zeroes 0 65536 +5 all-zeroes 0 65536 +6 all-zeroes 0 65536 +7 all-zeroes 0 65536 + =20 Bitmap name b2 flag auto @@ -53,6 +63,16 @@ type 1 granularity_bits 16 name_size 2 extra_data_size 0 +Bitmap table type offset size +0 serialized 5177344 65536 +1 all-zeroes 0 65536 +2 all-zeroes 0 65536 +3 all-zeroes 0 65536 +4 all-zeroes 0 65536 +5 all-zeroes 0 65536 +6 all-zeroes 0 65536 +7 all-zeroes 0 65536 + =20 =20 =3D=3D=3D Bitmap preservation not possible to non-qcow2 =3D=3D=3D @@ -128,6 +148,16 @@ type 1 granularity_bits 19 name_size 2 extra_data_size 0 +Bitmap table type offset size +0 serialized 4587520 65536 +1 all-zeroes 0 65536 +2 all-zeroes 0 65536 +3 all-zeroes 0 65536 +4 all-zeroes 0 65536 +5 all-zeroes 0 65536 +6 all-zeroes 0 65536 +7 all-zeroes 0 65536 + =20 Bitmap name b2 flag auto @@ -139,6 +169,16 @@ type 1 granularity_bits 16 name_size 2 extra_data_size 0 +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 + =20 Bitmap name b0 table size 8 (bytes) @@ -149,6 +189,16 @@ type 1 granularity_bits 16 name_size 2 extra_data_size 0 +Bitmap table type offset size +0 serialized 5242880 65536 +1 all-zeroes 0 65536 +2 all-zeroes 0 65536 +3 all-zeroes 0 65536 +4 all-zeroes 0 65536 +5 all-zeroes 0 65536 +6 all-zeroes 0 65536 +7 all-zeroes 0 65536 + =20 =20 =3D=3D=3D Check bitmap contents =3D=3D=3D diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index eb99119..c1c2773 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -137,6 +137,9 @@ class Qcow2BitmapExt(Qcow2Struct): shift =3D ((entry_raw_size + 7) & ~7) - entry_raw_size fd.seek(shift, FROM_CURRENT) =20 + for bm in self.bitmaps: + bm.read_bitmap_table(fd) + def load(self, fd): self.read_bitmap_directory(fd) =20 @@ -181,6 +184,12 @@ class Qcow2BitmapDirEntry(Qcow2Struct): return struct.calcsize(self.fmt) + self.name_size + \ self.extra_data_size =20 + def read_bitmap_table(self, fd): + fd.seek(self.bitmap_table_offset) + table_size =3D self.bitmap_table_bytes * struct.calcsize('Q') + table =3D [e[0] for e in struct.iter_unpack('>Q', fd.read(table_si= ze))] + self.bitmap_table =3D Qcow2BitmapTable(table) + def dump_bitmap_dir_entry(self): print() print(f'{"Bitmap name":<25} {self.name}') @@ -188,6 +197,37 @@ class Qcow2BitmapDirEntry(Qcow2Struct): print(f'{"flag":<25} {fl}') print(f'{"table size":<25} {self.bitmap_table_bytes} {"(bytes)"}') super().dump() + self.bitmap_table.print_bitmap_table(self.cluster_size) + + +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, raw_table): + self.entries =3D [] + for entry in raw_table: + self.entries.append(Qcow2BitmapTableEntry(entry)) + + def print_bitmap_table(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} {cluster_s= ize}') + print("") =20 =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 --=20 1.8.3.1 From nobody Sun May 19 05:51:03 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=1591920387; cv=none; d=zohomail.com; s=zohoarc; b=Iy59oJXo0bFJG0WZU3M0zEKezq8oyZauOxx5/ToF3+Oq9APHl4Gl7yyQY59GZXHKQF01NayZwTZOBbTqvXdV9aoKFEFV/0d+k5548P8Zg9lS98AYpgbpftGzQSp+XeB/Gn3gs+DQEuJwkVoSeDzJJEcAU45Qv1vLS0KIK8tHfME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920387; 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=z+f0yShr2f80MH94g9pqe/+6QmY0N+ep+k0xzD583ik=; b=mO6vC4mIrTvFQ7d+joP4cN4XzxMMM+/xAg1WUYRp191/oeysIP+9ZGltpwhzZIdsz/P63Gxv44zyLog0e7VybzabiS2ghxnXHg64PtVBf1EsZv6akrmPitUIlDz0BsHjRksKJBUU+a5yNs4Uc+QkL3uH8MLTOVrZIHlqati1lP4= 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 1591920387512164.56495189918792; Thu, 11 Jun 2020 17:06:27 -0700 (PDT) Received: from localhost ([::1]:36702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXDG-0001yp-0i for importer@patchew.org; Thu, 11 Jun 2020 20:06:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC2-0008Lr-ER; Thu, 11 Jun 2020 20:05:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:52837 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 1jjXBy-0006IA-K0; Thu, 11 Jun 2020 20:05:10 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-OG; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 7/9] qcow2.py: Introduce '-j' key to dump in JSON format Date: Fri, 12 Jun 2020 03:05:00 +0300 Message-Id: <1591920302-1002219-8-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" 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 --- tests/qemu-iotests/qcow2.py | 20 +++++++++++++++----- tests/qemu-iotests/qcow2_format.py | 18 +++++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py index 8c187e9..b08d8fc 100755 --- a/tests/qemu-iotests/qcow2.py +++ b/tests/qemu-iotests/qcow2.py @@ -24,16 +24,19 @@ from qcow2_format import ( ) =20 =20 +dump_json =3D False + + def cmd_dump_header(fd): h =3D QcowHeader(fd) - h.dump() + h.dump(dump_json) print() - h.dump_extensions() + h.dump_extensions(dump_json) =20 =20 def cmd_dump_header_exts(fd): h =3D QcowHeader(fd) - h.dump_extensions() + h.dump_extensions(dump_json) =20 =20 def cmd_set_header(fd, name, value): @@ -132,6 +135,11 @@ cmds =3D [ =20 =20 def main(filename, cmd, args): + global dump_json + dump_json =3D '-j' in sys.argv + if dump_json: + sys.argv.remove('-j') + args.remove('-j') fd =3D open(filename, "r+b") try: for name, handler, num_args, desc in cmds: @@ -149,12 +157,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 if __name__ =3D=3D '__main__': if len(sys.argv) < 3: diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index c1c2773..a19f3b3 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -92,7 +92,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, dump_json=3DNone): for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -143,10 +143,10 @@ class Qcow2BitmapExt(Qcow2Struct): def load(self, fd): self.read_bitmap_directory(fd) =20 - def dump(self): - super().dump() + def dump(self, dump_json=3DNone): + super().dump(dump_json) for bm in self.bitmaps: - bm.dump_bitmap_dir_entry() + bm.dump_bitmap_dir_entry(dump_json) =20 =20 BME_FLAG_IN_USE =3D 1 << 0 @@ -190,7 +190,7 @@ class Qcow2BitmapDirEntry(Qcow2Struct): table =3D [e[0] for e in struct.iter_unpack('>Q', fd.read(table_si= ze))] self.bitmap_table =3D Qcow2BitmapTable(table) =20 - def dump_bitmap_dir_entry(self): + def dump_bitmap_dir_entry(self, dump_json=3DNone): print() print(f'{"Bitmap name":<25} {self.name}') for fl in self.bitmap_flags: @@ -296,13 +296,13 @@ class QcowHeaderExtension(Qcow2Struct): else: self.obj =3D None =20 - def dump(self): + def dump(self, dump_json=3DNone): super().dump() =20 if self.obj is None: print(f'{"data":<25} {self.data_str}') else: - self.obj.dump() + self.obj.dump(dump_json) =20 @classmethod def create(cls, magic, data): @@ -405,8 +405,8 @@ class QcowHeader(Qcow2Struct): buf =3D buf[0:header_bytes-1] fd.write(buf) =20 - def dump_extensions(self): + def dump_extensions(self, dump_json=3DNone): for ex in self.extensions: print('Header extension:') - ex.dump() + ex.dump(dump_json) print() --=20 1.8.3.1 From nobody Sun May 19 05:51:03 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=1591920511; cv=none; d=zohomail.com; s=zohoarc; b=YCPkIzLDhDxsFQvo485JhpsCW56eZDhLlt7v70J3V+ngOs9eXSvXwUFqdCfkVtmYw48hiOPA2hMDABTwkoR/kh42OxAkb60boDkaPRcYtCl0yfykt4h5UT1sF/mLyR2DXLLlCI9oTefpu4h/IAbI36AlZ/SjR1LUQlaqfCgukxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920511; 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=JTdTQK4FoQp66X62qDXR0sOizfXvUlyfmx4u0cHioZw=; b=RhZfJNZOlSKo0XofuSQBsXOa/zeI2Ghr7dQ0pcmJBggI0Xdu38zQTA1RtuegPs5PDNtrkJxFTV6fnIaE9VhegPhDrqRDXQu+k62qmDDXji6hXjC1UIM8DyPGAymNuUEN2mBQiph8gytLBMb3K6GOKzYASKxeSesXkS5f642kqOU= 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 1591920511084465.5795882822914; Thu, 11 Jun 2020 17:08:31 -0700 (PDT) Received: from localhost ([::1]:45382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXFF-0005sn-KA for importer@patchew.org; Thu, 11 Jun 2020 20:08:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC2-0008Le-3p; Thu, 11 Jun 2020 20:05:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:52846 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 1jjXBy-0006I8-IL; Thu, 11 Jun 2020 20:05:09 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-PM; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 8/9] qcow2_format.py: collect fields to dump in JSON format Date: Fri, 12 Jun 2020 03:05:01 +0300 Message-Id: <1591920302-1002219-9-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" As __dict__ is being extended with class members we do not want to print in JSON format dump, make a light copy of the initial __dict__ and extend the copy by adding lists we have to print in the JSON output. Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index a19f3b3..bdd5f68 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -92,6 +92,8 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): self.__dict__ =3D dict((field[2], values[i]) for i, field in enumerate(self.fields)) =20 + self.fields_dict =3D self.__dict__.copy() + def dump(self, dump_json=3DNone): for f in self.fields: value =3D self.__dict__[f[2]] @@ -102,7 +104,6 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): =20 print('{:<25} {}'.format(f[2], value_str)) =20 - # seek relative to the current position in the file FROM_CURRENT =3D 1 =20 @@ -142,6 +143,7 @@ class Qcow2BitmapExt(Qcow2Struct): =20 def load(self, fd): self.read_bitmap_directory(fd) + self.fields_dict.update(entries=3Dself.bitmaps) =20 def dump(self, dump_json=3DNone): super().dump(dump_json) @@ -189,6 +191,7 @@ class Qcow2BitmapDirEntry(Qcow2Struct): table_size =3D self.bitmap_table_bytes * struct.calcsize('Q') table =3D [e[0] for e in struct.iter_unpack('>Q', fd.read(table_si= ze))] self.bitmap_table =3D Qcow2BitmapTable(table) + self.fields_dict.update(bitmap_table=3Dself.bitmap_table) =20 def dump_bitmap_dir_entry(self, dump_json=3DNone): print() --=20 1.8.3.1 From nobody Sun May 19 05:51:03 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=1591920551; cv=none; d=zohomail.com; s=zohoarc; b=iHLuLo05TXh/1NWw0KSyfuE+xcT7nF004nfCaK2VgEZ6t4w+eJRXurtQ9c1GCFqIyzONYnm8DfPJqHJ4q3SV6w+N0D1bxLo2pDSS+fL7fk7eASGE6COS5IbUBxAkk4IO8o0vfGmIgQMSylpcTmyrmn+qRW9b3IpqEuZlqqSbOc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591920551; 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=l9IyQf0A/CdqzweWvxUJNZTpfRfdC9+ve3RuaAisIjY=; b=X+7geRHELwHCJq3QkuRqWo4RRsdatYSOB5KtLriLgefIpAZi+fOCEnk3htZbm5eJsFrCyZEnnGkyEdvYIGOc3lr4IQ6ZMUk2k7HCGuaqQayCIgDMq495bH+T+KHlICZGvIlMbayZUYHBIuF7Uqa8OrndiJnHgFese47Dv0/NND8= 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 1591920551031540.7070022194657; Thu, 11 Jun 2020 17:09:11 -0700 (PDT) Received: from localhost ([::1]:48044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjXFt-00078L-RO for importer@patchew.org; Thu, 11 Jun 2020 20:09:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjXC5-0008Qj-73; Thu, 11 Jun 2020 20:05:13 -0400 Received: from relay.sw.ru ([185.231.240.75]:52874 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 1jjXBy-0006IG-Ln; Thu, 11 Jun 2020 20:05:12 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1jjXBr-0002Yd-QV; Fri, 12 Jun 2020 03:04:59 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v7 9/9] qcow2_format.py: support dumping metadata in JSON format Date: Fri, 12 Jun 2020 03:05:02 +0300 Message-Id: <1591920302-1002219-10-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1591920302-1002219-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1591920302-1002219-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 20:05:03 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=_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" 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, "entries": [ { "name": "bitmap-1", "bitmap_table_offset": 589824, "bitmap_table_size": 1, "flags": [ "auto" ], "type": 1, "granularity_bits": 16, "name_size": 8, "extra_data_size": 0, "bitmap_table": { "table_entries": [ { "type": "serialized", "offset": 655360 }, ... Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich --- tests/qemu-iotests/qcow2_format.py | 60 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 60 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index bdd5f68..35daec9 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -18,6 +18,15 @@ =20 import struct import string +import json + + +class ComplexEncoder(json.JSONEncoder): + def default(self, obj): + if hasattr(obj, 'get_fields_dict'): + return obj.get_fields_dict() + else: + return json.JSONEncoder.default(self, obj) =20 =20 class Qcow2Field: @@ -95,6 +104,11 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): self.fields_dict =3D self.__dict__.copy() =20 def dump(self, dump_json=3DNone): + if dump_json: + print(json.dumps(self.get_fields_dict(), indent=3D4, + cls=3DComplexEncoder)) + return + for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -150,6 +164,9 @@ class Qcow2BitmapExt(Qcow2Struct): for bm in self.bitmaps: bm.dump_bitmap_dir_entry(dump_json) =20 + def get_fields_dict(self): + return self.fields_dict + =20 BME_FLAG_IN_USE =3D 1 << 0 BME_FLAG_AUTO =3D 1 << 1 @@ -202,6 +219,12 @@ class Qcow2BitmapDirEntry(Qcow2Struct): super().dump() self.bitmap_table.print_bitmap_table(self.cluster_size) =20 + def get_fields_dict(self): + bmp_name =3D dict(name=3Dself.name) + bme_dict =3D {**bmp_name, **self.fields_dict} + bme_dict['flags'] =3D self.bitmap_flags + return bme_dict + =20 class Qcow2BitmapTableEntry: =20 @@ -217,6 +240,9 @@ class Qcow2BitmapTableEntry: else: self.type =3D 'all-zeroes' =20 + def get_fields_dict(self): + return dict(type=3Dself.type, offset=3Dself.offset) + =20 class Qcow2BitmapTable: =20 @@ -232,6 +258,18 @@ class Qcow2BitmapTable: print(f'{i:<14} {entry.type:<15} {entry.offset:<24} {cluster_s= ize}') print("") =20 + def get_fields_dict(self): + return dict(table_entries=3Dself.entries) + + +class Qcow2HeaderExtensionsDoc: + + def __init__(self, extensions): + self.extensions =3D extensions + + def get_fields_dict(self): + return dict(Header_extensions=3Dself.extensions) + =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 @@ -247,6 +285,9 @@ class QcowHeaderExtension(Qcow2Struct): 0x44415441: 'Data file' } =20 + def get_fields_dict(self): + return self.mapping.get(self.value, "") + fields =3D ( ('u32', Magic, 'magic'), ('u32', '{}', 'length') @@ -307,6 +348,16 @@ class QcowHeaderExtension(Qcow2Struct): else: self.obj.dump(dump_json) =20 + def get_fields_dict(self): + ext_name =3D dict(name=3Dself.Magic(self.magic)) + he_dict =3D {**ext_name, **self.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) @@ -409,7 +460,16 @@ class QcowHeader(Qcow2Struct): fd.write(buf) =20 def dump_extensions(self, dump_json=3DNone): + if dump_json: + ext_doc =3D Qcow2HeaderExtensionsDoc(self.extensions) + print(json.dumps(ext_doc.get_fields_dict(), indent=3D4, + cls=3DComplexEncoder)) + return + for ex in self.extensions: print('Header extension:') ex.dump(dump_json) print() + + def get_fields_dict(self): + return self.fields_dict --=20 1.8.3.1