From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, vsementsov@virtuozzo.com,
qemu-devel@nongnu.org, mreitz@redhat.com,
andrey.shinkevich@virtuozzo.com, den@openvz.org
Subject: [PATCH v3 3/6] iotests: dump bitmap extension data with qcow2.py
Date: Mon, 1 Jun 2020 16:48:10 +0300 [thread overview]
Message-ID: <1591019293-211155-4-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1591019293-211155-1-git-send-email-andrey.shinkevich@virtuozzo.com>
Add bitmap header extension data, if any, to the dump in qcow2.py.
Header extension: Bitmaps
magic 0x23852875
length 24
nb_bitmaps 2
reserved32 0
bitmap_directory_size 0x40
bitmap_directory_offset 0x100000
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
tests/qemu-iotests/qcow2.py | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index 18e4923..8286115 100755
--- a/tests/qemu-iotests/qcow2.py
+++ b/tests/qemu-iotests/qcow2.py
@@ -4,6 +4,39 @@ import sys
import struct
import string
+
+class Qcow2BitmapExt:
+
+ uint32_t = 'I'
+ uint64_t = 'Q'
+
+ fields = [
+ [uint32_t, '%d', 'nb_bitmaps'],
+ [uint32_t, '%d', 'reserved32'],
+ [uint64_t, '%#x', 'bitmap_directory_size'],
+ [uint64_t, '%#x', 'bitmap_directory_offset']
+ ]
+
+ fmt = '>' + ''.join(field[0] for field in fields)
+
+ def __init__(self, data):
+
+ extension = struct.unpack(Qcow2BitmapExt.fmt, data)
+ self.__dict__ = dict((field[2], extension[i])
+ for i, field in enumerate(Qcow2BitmapExt.fields))
+
+ def dump_bitmap_ext(self):
+ for f in Qcow2BitmapExt.fields:
+ value = self.__dict__[f[2]]
+ value_str = f[1] % value
+
+ print("%-25s" % f[2], value_str)
+ print("")
+
+ def dump_ext(self):
+ self.dump_bitmap_ext()
+
+
class QcowHeaderExtension:
QCOW2_EXT_MAGIC_BACKING_FORMAT = 0xE2792ACA
@@ -13,12 +46,16 @@ class QcowHeaderExtension:
QCOW2_EXT_MAGIC_DATA_FILE = 0x44415441
def __init__(self, magic, length, data):
+ self.obj = None
data_str = data[:length]
if all(c in string.printable.encode('ascii') for c in data_str):
data_str = "'%s'" % data_str.decode('ascii')
else:
data_str = "<binary>"
+ if magic == self.QCOW2_EXT_MAGIC_BITMAPS:
+ self.obj = Qcow2BitmapExt(data)
+
if length % 8 != 0:
padding = 8 - (length % 8)
data += b"\0" * padding
@@ -172,7 +209,10 @@ class QcowHeader:
print("%-25s %s" % ("Header extension:", ex.name))
print("%-25s %#x" % ("magic", ex.magic))
print("%-25s %d" % ("length", ex.length))
- print("%-25s %s" % ("data", ex.data_str))
+ if ex.obj is not None:
+ ex.obj.dump_ext()
+ else:
+ print("%-25s %s" % ("data", ex.data_str))
print("")
--
1.8.3.1
next prev parent reply other threads:[~2020-06-01 13:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-01 13:48 [PATCH v3 0/6] iotests: Dump QCOW2 dirty bitmaps metadata Andrey Shinkevich
2020-06-01 13:48 ` [PATCH v3 1/6] iotests: Add extension names to qcow2.py dump Andrey Shinkevich
2020-06-02 16:05 ` Eric Blake
2020-06-02 16:07 ` Eric Blake
2020-06-02 19:25 ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 2/6] iotests: move check for printable data to QcowHeaderExtension class Andrey Shinkevich
2020-06-02 16:14 ` Eric Blake
2020-06-02 19:32 ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` Andrey Shinkevich [this message]
2020-06-02 16:16 ` [PATCH v3 3/6] iotests: dump bitmap extension data with qcow2.py Eric Blake
2020-06-02 20:10 ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 4/6] iotests: Dump bitmap directory info " Andrey Shinkevich
2020-06-02 17:35 ` Eric Blake
2020-06-02 21:15 ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 5/6] iotests: Dump bitmap table entries serialized in QCOW2 image Andrey Shinkevich
2020-06-02 17:38 ` Eric Blake
2020-06-02 21:26 ` Vladimir Sementsov-Ogievskiy
2020-06-01 13:48 ` [PATCH v3 6/6] iotests: Dump QCOW2 image metadata in JSON format with qcow2.py Andrey Shinkevich
2020-06-02 17:40 ` Eric Blake
2020-06-02 21:36 ` Vladimir Sementsov-Ogievskiy
2020-06-01 21:46 ` [PATCH v3 0/6] iotests: Dump QCOW2 dirty bitmaps metadata Eric Blake
2020-06-04 7:54 ` Andrey Shinkevich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1591019293-211155-4-git-send-email-andrey.shinkevich@virtuozzo.com \
--to=andrey.shinkevich@virtuozzo.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).