From nobody Sat May 11 18:36:38 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=1596745596; cv=none; d=zohomail.com; s=zohoarc; b=fmVbCFN0p/GlE4/c4dOlimUjxYxfEAau+E6q4x6SUjYWwvLFSTjFpJeVVQpsU8gGBYtc4PirtaMWZjsPqMpS6ss/3uWRr+3mq3cpWDZY/ZVRVi2GJ4mmRkedoWVO7pWDVpGy8hsQMAC5hxl9xp9MO3Cw10ihQ8/CdDiJtgrk2j0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745596; 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=ay7slsAb5EqDoE5/ImHqbgnPL3qsJoPKlnmHiONRiVs=; b=AjERbGwog7sYF9n0lPkVTRhup1TbcOQNwwK9XmYTYYbZQtojudQgBezs9jgQxS9EmUp2mXTjZnob3YbllXwV44hMPM9v6F3LC41Ib03S1JLM5dir7/6XHy/J6X4P+XzLadF8wRbq7zHw/4bSQCiOUzpDZfObxpE/LNajkWMdavw= 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 1596745596581161.80859193958736; Thu, 6 Aug 2020 13:26:36 -0700 (PDT) Received: from localhost ([::1]:51744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mTD-0006c8-9w for importer@patchew.org; Thu, 06 Aug 2020 16:26:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgN-0002N6-8j; Thu, 06 Aug 2020 15:36:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:56464 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 1k3lgJ-0000Ko-PY; Thu, 06 Aug 2020 15:36:06 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-Li; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 01/11] iotests: add test for QCOW2 header dump Date: Thu, 6 Aug 2020 22:35:47 +0300 Message-Id: <1596742557-320265-2-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 simple script creates a QCOW2 image and fills it with some data. Two bitmaps are created as well. Then the script reads the image header with extensions from the disk by running the script qcow2.py and dumps the information to the output. Other entities, such as snapshots, may be added to the test later. Suggested-by: Eric Blake Signed-off-by: Andrey Shinkevich Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/303 | 60 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/303.out | 60 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/group | 1 + 3 files changed, 121 insertions(+) create mode 100755 tests/qemu-iotests/303 create mode 100644 tests/qemu-iotests/303.out diff --git a/tests/qemu-iotests/303 b/tests/qemu-iotests/303 new file mode 100755 index 0000000..e9accdc --- /dev/null +++ b/tests/qemu-iotests/303 @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# +# Test for dumping of qcow2 image metadata +# +# Copyright (c) 2020 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +import subprocess +from iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_= io + +iotests.script_initialize(supported_fmts=3D['qcow2']) + +disk =3D file_path('disk') +chunk =3D 1024 * 1024 + + +def create_bitmap(bitmap_number, disabled): + granularity =3D 1 << (14 + bitmap_number) + bitmap_name =3D 'bitmap-' + str(bitmap_number) + args =3D ['bitmap', '--add', '-g', f'{granularity}', '-f', iotests.img= fmt, + disk, bitmap_name] + if disabled: + args.append('--disable') + + iotests.qemu_img_pipe(*args) + + +def write_to_disk(offset, size): + write =3D f'write {offset} {size}' + log(qemu_io('-c', write, disk), filters=3D[filter_qemu_io]) + + +def add_bitmap(num, begin, end, disabled): + log(f'Add bitmap {num}') + create_bitmap(num, disabled) + for i in range(begin, end): + write_to_disk((i) * chunk, chunk) + log('') + + +qemu_img_create('-f', iotests.imgfmt, disk, '10M') + +add_bitmap(1, 0, 6, False) +add_bitmap(2, 6, 8, True) +dump =3D ['qcow2.py', disk, 'dump-header'] +subprocess.run(dump) diff --git a/tests/qemu-iotests/303.out b/tests/qemu-iotests/303.out new file mode 100644 index 0000000..8d7973c --- /dev/null +++ b/tests/qemu-iotests/303.out @@ -0,0 +1,60 @@ +Add bitmap 1 +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 2097152 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 4194304 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 5242880 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + + +Add bitmap 2 +wrote 1048576/1048576 bytes at offset 6291456 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +wrote 1048576/1048576 bytes at offset 7340032 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + + +magic 0x514649fb +version 3 +backing_file_offset 0x0 +backing_file_size 0x0 +cluster_bits 16 +size 10485760 +crypt_method 0 +l1_size 1 +l1_table_offset 0x30000 +refcount_table_offset 0x10000 +refcount_table_clusters 1 +nb_snapshots 0 +snapshot_offset 0x0 +incompatible_features [] +compatible_features [] +autoclear_features [0] +refcount_order 4 +header_length 112 + +Header extension: +magic 0x6803f857 (Feature table) +length 336 +data + +Header extension: +magic 0x23852875 (Bitmaps) +length 24 +nb_bitmaps 2 +reserved32 0 +bitmap_directory_size 0x40 +bitmap_directory_offset 0x9d0000 + diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 025ed52..7e12e1f 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -309,3 +309,4 @@ 299 auto quick 301 backing quick 302 quick +303 rw quick --=20 1.8.3.1 From nobody Sat May 11 18:36:38 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=1596745494; cv=none; d=zohomail.com; s=zohoarc; b=ndlzgp7kRjWE55PZtti0PmGSjEFQpBcz+RKGts7xqxhuIAsThNAgBfO/XZ/1mYNnRWVKxG+xLntx3KVthI+5wj6znGTcIRjYiB8+SdBOqFXIJyays9DzjWu6+yj9KBwOZVe3SA9yHgiClWImB7tQ3sxWS6gaD8K7z9CmwLc+TLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745494; 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=PZlFZfbyxrjd16v7weF1YYnam+ma8a4LRD+iI+1ldTb7UYUYsqkXc5ZYgkbRHWQD9tEONloaTONI7ISCzYjGFVcT4YgNhrg/L1ASAdCiPmt3SeK/sR5Xbb5LqXxcrC/qiE2nuHS/aQanpkEvRRIdaGWsuqBQ6NFt+/N+uiEzMac= 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 1596745494570647.6647721554887; Thu, 6 Aug 2020 13:24:54 -0700 (PDT) Received: from localhost ([::1]:45484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mRZ-00043R-AF for importer@patchew.org; Thu, 06 Aug 2020 16:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgM-0002MI-Vt; Thu, 06 Aug 2020 15:36:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:56466 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Kn-4Y; Thu, 06 Aug 2020 15:36:06 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-N2; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 02/11] qcow2_format.py: make printable data an extension class member Date: Thu, 6 Aug 2020 22:35:48 +0300 Message-Id: <1596742557-320265-3-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 Sat May 11 18:36:38 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=1596745682; cv=none; d=zohomail.com; s=zohoarc; b=KQQ9T2judXJcjJTiFihiuQzpdYJZnE1b/jeWl9QOVze38fhCQu26ATheFS2JmocSGpT/TPojozYynrgAGq9MfGtiL8z7IilUPKtOjQjFVuG2Qta58fko4b1AzMTlFfUUXmle3aBPNjpt7d795W0cpUmy+wOzhzlPsc+/6Qiy9JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745682; 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=po6iy39KpJCpsbML0K1ktaQnSiNcC7KW/I5eyNQir1Y=; b=hGBCXxz0mhlJewUTX7lTJkPn7I/Ir8SwhAz1UmnFDSdVe9Rglqvn3EIGEc3MzNHbewDYscRIZwR3zWWi+X1sSBkpolkTa0KT9lYMtBHVErBBufGgHX7SBx69ZpJpzKVnxvUH7NUlLsdRY1nW3Hp30kkojhfbKdEz62HoGZdqKuU= 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 1596745682669161.40133017593143; Thu, 6 Aug 2020 13:28:02 -0700 (PDT) Received: from localhost ([::1]:58566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mUb-0000wJ-FP for importer@patchew.org; Thu, 06 Aug 2020 16:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgN-0002Nu-Iz; Thu, 06 Aug 2020 15:36:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:56496 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 1k3lgJ-0000Ku-N7; Thu, 06 Aug 2020 15:36:07 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-OM; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 03/11] qcow2_format.py: change Qcow2BitmapExt initialization method Date: Thu, 6 Aug 2020 22:35:49 +0300 Message-Id: <1596742557-320265-4-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 Sat May 11 18:36:38 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=1596745847; cv=none; d=zohomail.com; s=zohoarc; b=HptY1TpH3iJkRsEBDEhNJ6I52ga5ARB2olIHl6JkD9IVztPNIn1d0X02U98VYgYZw6Y+IWvHHyyMy3WAtvFJ3l3BZh3fzgC4E9RiCwb7ikYc3lY5D09tnZlWcVbK4ppLHGwxRylKVOW5Kv2keN2z1V+0zDR1vJotnsnhTU6N7vs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745847; 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=ERtQZc+ztwUTubue4dRAr7ms1m4ek7yxYjqAf+CFV3g7JZIAoNJGbQ97F2fw+DYWYcPM5p4819VzyimZsy/iGBtU7h23Dy2hqCVAqkgyiKdLqtDoGDoJ2XniOENTnRxRu+SfKBbxCRqXN6bUQeEYavMkNGM1AoNMMfHntPeq6Zg= 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 1596745847577952.5137246070863; Thu, 6 Aug 2020 13:30:47 -0700 (PDT) Received: from localhost ([::1]:43550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mXG-0006Ms-BR for importer@patchew.org; Thu, 06 Aug 2020 16:30:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgf-00038t-D9; Thu, 06 Aug 2020 15:36:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:56456 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 1k3lgd-0000Kl-4N; Thu, 06 Aug 2020 15:36:25 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-Pg; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 04/11] qcow2_format.py: dump bitmap flags in human readable way. Date: Thu, 6 Aug 2020 22:35:50 +0300 Message-Id: <1596742557-320265-5-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Sat May 11 18:36:38 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=1596745675; cv=none; d=zohomail.com; s=zohoarc; b=CbSPZp98hT6E2HqTFM6u5D2t3Cc4SB49/tEZXhYA7RC05Skv31dLyPDrc8GCM2Zj9nEeWRm8K48Q3cEYgqLSB9UkGOirPqbWw8PabzT/NaVmaYf2M59Lpup3ZxPIgzKK7Q8k0z8OuNkmKPGej+S71/qQG6uZOK61HHl22RTJCnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745675; 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=sxsYoOYTB6eWOfFLixImx82zRZrifgs+32CfdEqSJlg=; b=FSq3SslK79+MjzeEog2U95oYBho1BVZz6GawG1sFhPpdBJ4YmPg4j1um9q6g1PmLm5JnXCpzax01efEfV3iaNsI52it55YmwAtx48Ol3jE4CjXcTdgT/9JJPBVWfi0eMU1D2GUwYbGAuXBHHP2zkvWqcm0tL1hEHyCPulJzMYt0= 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 1596745675772984.143790792265; Thu, 6 Aug 2020 13:27:55 -0700 (PDT) Received: from localhost ([::1]:58012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mUU-0000hU-GK for importer@patchew.org; Thu, 06 Aug 2020 16:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgO-0002Qa-Jx; Thu, 06 Aug 2020 15:36:08 -0400 Received: from relay.sw.ru ([185.231.240.75]:56454 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Kj-8L; Thu, 06 Aug 2020 15:36:08 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-RA; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 05/11] qcow2_format.py: Dump bitmap directory information Date: Thu, 6 Aug 2020 22:35:51 +0300 Message-Id: <1596742557-320265-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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/303.out | 18 +++++++++++++++ tests/qemu-iotests/qcow2_format.py | 47 ++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 65 insertions(+) diff --git a/tests/qemu-iotests/303.out b/tests/qemu-iotests/303.out index 8d7973c..038ba93 100644 --- a/tests/qemu-iotests/303.out +++ b/tests/qemu-iotests/303.out @@ -58,3 +58,21 @@ reserved32 0 bitmap_directory_size 0x40 bitmap_directory_offset 0x9d0000 =20 +Bitmap name bitmap-1 +bitmap_table_offset 0x9b0000 +bitmap_table_size 1 +flags 0x2 (['auto']) +type 1 +granularity_bits 15 +name_size 8 +extra_data_size 0 + +Bitmap name bitmap-2 +bitmap_table_offset 0x9c0000 +bitmap_table_size 1 +flags 0x0 ([]) +type 1 +granularity_bits 16 +name_size 8 +extra_data_size 0 + 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 Sat May 11 18:36:38 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=1596745933; cv=none; d=zohomail.com; s=zohoarc; b=A1xgkTsPsGwo77bG66qBB9hoTvao9MutVkJwzq6YSn8TeosmMtO8YWs6pgOJ19Q9lmUfNGWbQCrbJ3wHj42cYmWBORv3NyqaZmQXkH9MbXrK+KB+M8qoOJc033XWdJ1m4CICptneJsPJVk6XiE9gwtX6mlbVGP3HkhkuFZVXBqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745933; 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=ETHO+RBcx6zIh4G87idqFsAVYx3jkyNjuKYiEtXc5Vjdo4VTZUPiC7nTqBY1N/sikiZpvwH2mRc9u+C/IMkBJxfISk7udyCNpCn97pMB4cTcJlIYE8vOd7JW0IN86HUzO+Q9dlvx7/5AXNA9MGIAAgPelGFe1eo+p2eeqVwxhgc= 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 1596745933819272.0504969968805; Thu, 6 Aug 2020 13:32:13 -0700 (PDT) Received: from localhost ([::1]:49152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mYe-0000Nx-Hc for importer@patchew.org; Thu, 06 Aug 2020 16:32:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgf-00038m-6D; Thu, 06 Aug 2020 15:36:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:56462 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 1k3lgd-0000Kp-4E; Thu, 06 Aug 2020 15:36:24 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-Si; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 06/11] qcow2_format.py: pass cluster size to substructures Date: Thu, 6 Aug 2020 22:35:52 +0300 Message-Id: <1596742557-320265-7-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 Sat May 11 18:36:38 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=1596745583; cv=none; d=zohomail.com; s=zohoarc; b=EtrFQOM2S+LwcDZ27G8dLn6QaRWpRMxZpP1R/iU4/S3OsYkox3KLLmjHsveWsRQc281n7YAmetTmtwQQ/1tdx4RL043oA0oDwgjhr6BW6CGxHi3WzfZdPiCFuRd6TkH+ambLD4CnFsRMQD7c+7PfzJSZJ/OZnoaF+l4MDue17ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745583; 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=m8r+Rcjru85GH84vkZ/JN5Ivkv7JDGu4wiUA7fBWM0k=; b=Tt16VZRKPSSgbFPiGKiGpDaE52jCxR7+et7slESPOIsVu4fGvOJKsFRKDJTRBvrbUFViYLqeL4eg3HpGVkBv7K2y2qKQ9ZHovtTn1pOTQzP9fc8IPigc8OGp+yvuL0MYJxNVpI3kXJWi/2AXTeLTDI/vqytk4JBfdDeSt+cWhsE= 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 1596745583029472.46535330033396; Thu, 6 Aug 2020 13:26:23 -0700 (PDT) Received: from localhost ([::1]:50622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mSz-0006Az-OD for importer@patchew.org; Thu, 06 Aug 2020 16:26:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgO-0002PT-8D; Thu, 06 Aug 2020 15:36:08 -0400 Received: from relay.sw.ru ([185.231.240.75]:56481 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Kr-5A; Thu, 06 Aug 2020 15:36:07 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgB-0003k9-VR; Thu, 06 Aug 2020 22:35:55 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 07/11] qcow2_format.py: Dump bitmap table serialized entries Date: Thu, 6 Aug 2020 22:35:53 +0300 Message-Id: <1596742557-320265-8-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 size offset 0 serialized 65536 10092544 1 all-zeroes 0 0 2 all-zeroes 0 0 Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/303.out | 4 +++ tests/qemu-iotests/qcow2_format.py | 50 ++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 54 insertions(+) diff --git a/tests/qemu-iotests/303.out b/tests/qemu-iotests/303.out index 038ba93..70828e0 100644 --- a/tests/qemu-iotests/303.out +++ b/tests/qemu-iotests/303.out @@ -66,6 +66,8 @@ type 1 granularity_bits 15 name_size 8 extra_data_size 0 +Bitmap table type size offset +0 serialized 65536 10092544 =20 Bitmap name bitmap-2 bitmap_table_offset 0x9c0000 @@ -75,4 +77,6 @@ type 1 granularity_bits 16 name_size 8 extra_data_size 0 +Bitmap table type size offset +0 all-zeroes 0 0 =20 diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index ca0d350..574249b 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, + nb_entries=3Dself.bitmap_tabl= e_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,52 @@ class Qcow2BitmapDirEntry(Qcow2Struct): def dump(self): print(f'{"Bitmap name":<25} {self.name}') super(Qcow2BitmapDirEntry, self).dump() + self.bitmap_table.dump() + + +class Qcow2BitmapTableEntry(Qcow2Struct): + + fields =3D ( + ('u64', '{}', 'entry'), + ) + + BME_TABLE_ENTRY_RESERVED_MASK =3D 0xff000000000001fe + BME_TABLE_ENTRY_OFFSET_MASK =3D 0x00fffffffffffe00 + BME_TABLE_ENTRY_FLAG_ALL_ONES =3D 1 + + def __init__(self, fd): + super().__init__(fd=3Dfd) + self.reserved =3D self.entry & self.BME_TABLE_ENTRY_RESERVED_MASK + self.offset =3D self.entry & self.BME_TABLE_ENTRY_OFFSET_MASK + if self.offset: + if self.entry & self.BME_TABLE_ENTRY_FLAG_ALL_ONES: + self.type =3D 'invalid' + else: + self.type =3D 'serialized' + elif self.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, nb_entries, cluster_size): + self.cluster_size =3D cluster_size + position =3D fd.tell() + fd.seek(offset) + self.entries =3D [Qcow2BitmapTableEntry(fd) for _ in range(nb_entr= ies)] + fd.seek(position) + + def dump(self): + bitmap_table =3D enumerate(self.entries) + print(f'{"Bitmap table":<14} {"type":<15} {"size":<12} {"offset"}') + for i, entry in bitmap_table: + if entry.type =3D=3D 'serialized': + size =3D self.cluster_size + else: + size =3D 0 + print(f'{i:<14} {entry.type:<15} {size:<12} {entry.offset}') =20 =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 --=20 1.8.3.1 From nobody Sat May 11 18:36:38 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=1596745750; cv=none; d=zohomail.com; s=zohoarc; b=gHlrLagpM91w/UD75q2GwkUCzwmLGNzN4Vxu4RjTIPKqXKYba8AEpmJuj7Eq77PFXw/Y9SShqH5oxYdMDC9bI6mk5zmRD2kv9hAizBU9SuV6/YTTqfe1e6rsbIDK7S7pNvxiXRT6kXTrZTBRq+Zq4sVAfkZmU3HMthP3HvK0q9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745750; 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=m8doYvm6dTRuMNaGj5W1T39XngpOn2+pm2vLt6GYra0=; b=O5X0l4KDCW8fP1kxcldWG4x+T5N9Jqx3lmqxsqalY7YzoIRYYf6SrHWBtJw8Oi0yedrqbMRHlv6e3ML6e+r2j3CFeAn1x4exjU4LhBS72W6/tWcZV6XZBsmYPgDnjBzpzP4S4BFAO3XRaPy+tGkwpAIsx13gDvDCo7cOvrL6jPM= 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 1596745750173527.9295949171702; Thu, 6 Aug 2020 13:29:10 -0700 (PDT) Received: from localhost ([::1]:35898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mVg-0003CZ-KH for importer@patchew.org; Thu, 06 Aug 2020 16:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgP-0002Tw-IK; Thu, 06 Aug 2020 15:36:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:56478 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Ks-NV; Thu, 06 Aug 2020 15:36:09 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgC-0003k9-0Y; Thu, 06 Aug 2020 22:35:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 08/11] qcow2.py: Introduce '-j' key to dump in JSON format Date: Thu, 6 Aug 2020 22:35:54 +0300 Message-Id: <1596742557-320265-9-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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 | 4 ++-- 2 files changed, 16 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 574249b..de0adcb 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): @@ -408,7 +408,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 Sat May 11 18:36:38 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=1596745112; cv=none; d=zohomail.com; s=zohoarc; b=B9dnyOTL8FJSYtxYorTE6lM5McMQInYv3aydShD1Y77ukDIYThGzkqDdL+8XK9O9OdeB2c4csGyX/XULg3WZZsiWifEKn8P1nO5Xj0NK/aZpctOS35BN949KDTp1q1+o22y+niLZTChHCrozXEV/Tg0VSTE8DtNi13Y87IOgbLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745112; 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=mD3kBFRJ5Umy1ZxbQwreWHmJhCtUnKItTgbmYqGctOk=; b=Q3TzEmichGdc7U9KJSrppe8DePWQGVwACZfp9gSPay2M444UFah5HEJXwG6HScpTJH4KCnSshac0C4P9FHHepmGq3FtWD3rcMqLKaQyyFMh6y9gjwgAWs/8xSrojEcRz+1rI4wI8v5FXlkj/t5A6qTmdRU87deI1EU60C99Fr8w= 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 1596745112740511.72005455215833; Thu, 6 Aug 2020 13:18:32 -0700 (PDT) Received: from localhost ([::1]:46616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mLP-0001If-ES for importer@patchew.org; Thu, 06 Aug 2020 16:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgN-0002Mg-2P; Thu, 06 Aug 2020 15:36:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:56468 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 1k3lgJ-0000Kt-Ns; Thu, 06 Aug 2020 15:36:06 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgC-0003k9-1q; Thu, 06 Aug 2020 22:35:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 09/11] qcow2_format.py: collect fields to dump in JSON format Date: Thu, 6 Aug 2020 22:35:55 +0300 Message-Id: <1596742557-320265-10-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 36 ++++++++++++++++++++++++++++++++++= ++ 1 file changed, 36 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index de0adcb..5a298b2 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_json(self): + return dict((f[2], self.__dict__[f[2]]) for f in self.fields) + =20 class Qcow2BitmapExt(Qcow2Struct): =20 @@ -151,6 +154,11 @@ class Qcow2BitmapExt(Qcow2Struct): print() entry.dump() =20 + def to_json(self): + fields_dict =3D super().to_json() + fields_dict['bitmap_directory'] =3D self.bitmap_directory + return fields_dict + =20 class Qcow2BitmapDirEntry(Qcow2Struct): =20 @@ -189,6 +197,14 @@ class Qcow2BitmapDirEntry(Qcow2Struct): super(Qcow2BitmapDirEntry, self).dump() self.bitmap_table.dump() =20 + def to_json(self): + # Put the name ahead of the dict + return { + 'name': self.name, + **super().to_json(), + 'bitmap_table': self.bitmap_table + } + =20 class Qcow2BitmapTableEntry(Qcow2Struct): =20 @@ -214,6 +230,10 @@ class Qcow2BitmapTableEntry(Qcow2Struct): else: self.type =3D 'all-zeroes' =20 + def to_json(self): + return {'type': self.type, 'offset': self.offset, + 'reserved': self.reserved} + =20 class Qcow2BitmapTable: =20 @@ -234,6 +254,9 @@ class Qcow2BitmapTable: size =3D 0 print(f'{i:<14} {entry.type:<15} {size:<12} {entry.offset}') =20 + def to_json(self): + return self.entries + =20 QCOW2_EXT_MAGIC_BITMAPS =3D 0x23852875 =20 @@ -249,6 +272,9 @@ class QcowHeaderExtension(Qcow2Struct): 0x44415441: 'Data file' } =20 + def to_json(self): + return self.mapping.get(self.value, "") + fields =3D ( ('u32', Magic, 'magic'), ('u32', '{}', 'length') @@ -311,6 +337,16 @@ class QcowHeaderExtension(Qcow2Struct): else: self.obj.dump() =20 + def to_json(self): + # Put the name ahead of the dict + res =3D {'name': self.Magic(self.magic), **super().to_json()} + if self.obj is not None: + res['data'] =3D self.obj + else: + res['data_str'] =3D self.data_str + + return res + @classmethod def create(cls, magic, data): return QcowHeaderExtension(magic, len(data), data) --=20 1.8.3.1 From nobody Sat May 11 18:36:38 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=1596745635; cv=none; d=zohomail.com; s=zohoarc; b=fU09tEHEthf3UYzFJW2eNV33LgyJzRUofL3XWrguDER4D2OzER7FVYIIX0cC+xSremKYbox6CrcuImJIMqT+wpR6jUIVXwtOnZm/WPelSdtTPpN/saZ/eMQHWm7bOmpCYHYUUJNvd1mSIrxZ2hHQXe0RsZkSeZplw4RwfpPOg7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745635; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=yRZZdyIIX14B535mX7xfftZCzm1rEg78ItdpI2LXo8s=; b=a9Kw5UyXRTAYZYXR0i/iqjjkA4aJO3toLnVF8oHrb3u7KZoebg7UUDvqil7rn8JRrtClEsensWiX6iwP15qlTWP3CQiqV8LY7nrJdm+1IbeAZ9FNo7N7ojQD4sRJuAcgxe3cvrtr5Qy+2LCUshNpOwSLp2LtOjJchCDXezWYAXQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1596745635196125.20872623242178; Thu, 6 Aug 2020 13:27:15 -0700 (PDT) Received: from localhost ([::1]:54260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mTp-0007d2-Rl for importer@patchew.org; Thu, 06 Aug 2020 16:27:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgO-0002SI-VX; Thu, 06 Aug 2020 15:36:08 -0400 Received: from relay.sw.ru ([185.231.240.75]:56480 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Kq-95; Thu, 06 Aug 2020 15:36:08 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgC-0003k9-3C; Thu, 06 Aug 2020 22:35:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 10/11] qcow2_format.py: support dumping metadata in JSON format Date: Thu, 6 Aug 2020 22:35:56 +0300 Message-Id: <1596742557-320265-11-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implementation of dumping QCOW2 image metadata. The sample output: { "Header_extensions": [ { "name": "Feature table", "magic": 1745090647, "length": 192, "data_str": "" }, { "name": "Bitmaps", "magic": 595929205, "length": 24, "data": { "nb_bitmaps": 2, "reserved32": 0, "bitmap_directory_size": 64, "bitmap_directory_offset": 1048576, "bitmap_directory": [ { "name": "bitmap-1", "bitmap_table_offset": 589824, "bitmap_table_size": 1, "flags": 2, "type": 1, "granularity_bits": 15, "name_size": 8, "extra_data_size": 0, "bitmap_table": [ { "type": "serialized", "offset": 655360 }, ... Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/qcow2_format.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_= format.py index 5a298b2..8adc995 100644 --- a/tests/qemu-iotests/qcow2_format.py +++ b/tests/qemu-iotests/qcow2_format.py @@ -19,6 +19,15 @@ =20 import struct import string +import json + + +class ComplexEncoder(json.JSONEncoder): + def default(self, obj): + if hasattr(obj, 'to_json'): + return obj.to_json() + else: + return json.JSONEncoder.default(self, obj) =20 =20 class Qcow2Field: @@ -110,6 +119,10 @@ class Qcow2Struct(metaclass=3DQcow2StructMeta): for i, field in enumerate(self.fields)) =20 def dump(self, is_json=3DFalse): + if is_json: + print(json.dumps(self.to_json(), indent=3D4, cls=3DComplexEnco= der)) + return + for f in self.fields: value =3D self.__dict__[f[2]] if isinstance(f[1], str): @@ -445,6 +458,10 @@ class QcowHeader(Qcow2Struct): fd.write(buf) =20 def dump_extensions(self, is_json=3DFalse): + if is_json: + print(json.dumps(self.extensions, indent=3D4, cls=3DComplexEnc= oder)) + return + for ex in self.extensions: print('Header extension:') ex.dump() --=20 1.8.3.1 From nobody Sat May 11 18:36:38 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=1596745770; cv=none; d=zohomail.com; s=zohoarc; b=CD4LOjJxOlY5axH5fzoz1UdRyzcoiJgQdGWhdB7xSbLnxhsKhXBgKGhTj7W43HpFz73TJHRShhgzvC7FZw/IDzKSSzHhetb05S5ugHx1L0IfdTOyKodNxks13gkqS4XmO7+BViiZQO2FcHLdex52Q/5HCDeAUUcqH6dxg/yiaEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596745770; 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=Ob2Mk/+Wrw8zRKgvNi3MRFyAQ6SVyYxjFt/vBFJHpgs=; b=mvNHYTWY/nS7pU4BN/KLFYxa3cGKr2fp7Rtl7oC+BYBOvXcPvwSWxbTfgWz2wVJ8tODYukGk6Qzg4uRdIUW7YqRwL379S8h5N7ezuO2dRZBSAS1qAZ/mv4VwMUXsmmQL3zn52hrxBHFlkPPBcM+Ke+ibO1TCzRe7iFxvc2Fbq1s= 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 1596745770019393.54043923482686; Thu, 6 Aug 2020 13:29:30 -0700 (PDT) Received: from localhost ([::1]:37488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3mVy-0003p3-Jd for importer@patchew.org; Thu, 06 Aug 2020 16:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgQ-0002Xw-Os; Thu, 06 Aug 2020 15:36:10 -0400 Received: from relay.sw.ru ([185.231.240.75]:56458 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3lgK-0000Km-7H; Thu, 06 Aug 2020 15:36:10 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k3lgC-0003k9-4X; Thu, 06 Aug 2020 22:35:56 +0300 From: Andrey Shinkevich To: qemu-block@nongnu.org Subject: [PATCH v13 11/11] iotests: dump QCOW2 header in JSON in #303 Date: Thu, 6 Aug 2020 22:35:57 +0300 Message-Id: <1596742557-320265-12-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1596742557-320265-1-git-send-email-andrey.shinkevich@virtuozzo.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 15:35:59 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Extend the test case #303 by dumping QCOW2 image metadata in JSON format. Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/303 | 3 ++ tests/qemu-iotests/303.out | 76 ++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 79 insertions(+) diff --git a/tests/qemu-iotests/303 b/tests/qemu-iotests/303 index e9accdc..6c21774 100755 --- a/tests/qemu-iotests/303 +++ b/tests/qemu-iotests/303 @@ -58,3 +58,6 @@ add_bitmap(1, 0, 6, False) add_bitmap(2, 6, 8, True) dump =3D ['qcow2.py', disk, 'dump-header'] subprocess.run(dump) +# Dump the metadata in JSON format +dump.append('-j') +subprocess.run(dump) diff --git a/tests/qemu-iotests/303.out b/tests/qemu-iotests/303.out index 70828e0..7fa1ede 100644 --- a/tests/qemu-iotests/303.out +++ b/tests/qemu-iotests/303.out @@ -80,3 +80,79 @@ extra_data_size 0 Bitmap table type size offset 0 all-zeroes 0 0 =20 +{ + "magic": 1363560955, + "version": 3, + "backing_file_offset": 0, + "backing_file_size": 0, + "cluster_bits": 16, + "size": 10485760, + "crypt_method": 0, + "l1_size": 1, + "l1_table_offset": 196608, + "refcount_table_offset": 65536, + "refcount_table_clusters": 1, + "nb_snapshots": 0, + "snapshot_offset": 0, + "incompatible_features": 0, + "compatible_features": 0, + "autoclear_features": 1, + "refcount_order": 4, + "header_length": 112 +} + +[ + { + "name": "Feature table", + "magic": 1745090647, + "length": 336, + "data_str": "" + }, + { + "name": "Bitmaps", + "magic": 595929205, + "length": 24, + "data": { + "nb_bitmaps": 2, + "reserved32": 0, + "bitmap_directory_size": 64, + "bitmap_directory_offset": 10289152, + "bitmap_directory": [ + { + "name": "bitmap-1", + "bitmap_table_offset": 10158080, + "bitmap_table_size": 1, + "flags": 2, + "type": 1, + "granularity_bits": 15, + "name_size": 8, + "extra_data_size": 0, + "bitmap_table": [ + { + "type": "serialized", + "offset": 10092544, + "reserved": 0 + } + ] + }, + { + "name": "bitmap-2", + "bitmap_table_offset": 10223616, + "bitmap_table_size": 1, + "flags": 0, + "type": 1, + "granularity_bits": 16, + "name_size": 8, + "extra_data_size": 0, + "bitmap_table": [ + { + "type": "all-zeroes", + "offset": 0, + "reserved": 0 + } + ] + } + ] + } + } +] --=20 1.8.3.1