From: Vladimir Sementsov-Ogievskiy <vsementsov@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 v5 13/13] qcow2_format.py: dump bitmaps header extension
Date: Sat, 6 Jun 2020 11:18:06 +0300 [thread overview]
Message-ID: <20200606081806.23897-14-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20200606081806.23897-1-vsementsov@virtuozzo.com>
Add class for bitmap extension and dump its fields. Further work is to
dump bitmap directory.
Test new functionality inside 291 iotest.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
tests/qemu-iotests/291 | 4 +++
tests/qemu-iotests/291.out | 33 +++++++++++++++++++++++
tests/qemu-iotests/qcow2_format.py | 42 +++++++++++++++++++++++-------
3 files changed, 70 insertions(+), 9 deletions(-)
diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291
index 3ca83b9cd1..e0cffc7cb1 100755
--- a/tests/qemu-iotests/291
+++ b/tests/qemu-iotests/291
@@ -62,6 +62,8 @@ $QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
$QEMU_IMG bitmap --disable -f $IMGFMT "$TEST_IMG" b1
$QEMU_IMG bitmap --enable -f $IMGFMT "$TEST_IMG" b2
$QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
+echo "Check resulting qcow2 header extensions:"
+$PYTHON qcow2.py "$TEST_IMG" dump-header-exts
echo
echo "=== Bitmap preservation not possible to non-qcow2 ==="
@@ -88,6 +90,8 @@ $QEMU_IMG bitmap --merge tmp -f $IMGFMT "$TEST_IMG" b0
$QEMU_IMG bitmap --remove --image-opts \
driver=$IMGFMT,file.driver=file,file.filename="$TEST_IMG" tmp
$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific
+echo "Check resulting qcow2 header extensions:"
+$PYTHON qcow2.py "$TEST_IMG" dump-header-exts
echo
echo "=== Check bitmap contents ==="
diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out
index 8c62017567..1d4f9cd96d 100644
--- a/tests/qemu-iotests/291.out
+++ b/tests/qemu-iotests/291.out
@@ -14,6 +14,25 @@ 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)
+Check resulting qcow2 header extensions:
+Header extension:
+magic 3799591626 (Backing format)
+length 5
+data 'qcow2'
+
+Header extension:
+magic 1745090647 (Feature table)
+length 336
+data <binary>
+
+Header extension:
+magic 595929205 (Bitmaps)
+length 24
+nb_bitmaps 2
+reserved32 0
+bitmap_directory_size 0x40
+bitmap_directory_offset 0x510000
+
=== Bitmap preservation not possible to non-qcow2 ===
@@ -65,6 +84,20 @@ Format specific information:
granularity: 65536
refcount bits: 16
corrupt: false
+Check resulting qcow2 header extensions:
+Header extension:
+magic 1745090647 (Feature table)
+length 336
+data <binary>
+
+Header extension:
+magic 595929205 (Bitmaps)
+length 24
+nb_bitmaps 3
+reserved32 0
+bitmap_directory_size 0x60
+bitmap_directory_offset 0x520000
+
=== Check bitmap contents ===
diff --git a/tests/qemu-iotests/qcow2_format.py b/tests/qemu-iotests/qcow2_format.py
index 40b5bf467b..0f65fd161d 100644
--- a/tests/qemu-iotests/qcow2_format.py
+++ b/tests/qemu-iotests/qcow2_format.py
@@ -103,6 +103,19 @@ class Qcow2Struct(metaclass=Qcow2StructMeta):
print('{:<25} {}'.format(f[2], value_str))
+class Qcow2BitmapExt(Qcow2Struct):
+
+ fields = (
+ ('u32', '{}', 'nb_bitmaps'),
+ ('u32', '{}', 'reserved32'),
+ ('u64', '{:#x}', 'bitmap_directory_size'),
+ ('u64', '{:#x}', 'bitmap_directory_offset')
+ )
+
+
+QCOW2_EXT_MAGIC_BITMAPS = 0x23852875
+
+
class QcowHeaderExtension(Qcow2Struct):
class Magic(Enum):
@@ -110,7 +123,7 @@ class QcowHeaderExtension(Qcow2Struct):
0xe2792aca: 'Backing format',
0x6803f857: 'Feature table',
0x0537be77: 'Crypto header',
- 0x23852875: 'Bitmaps',
+ QCOW2_EXT_MAGIC_BITMAPS: 'Bitmaps',
0x44415441: 'Data file'
}
@@ -130,8 +143,11 @@ class QcowHeaderExtension(Qcow2Struct):
This should be somehow refactored and functionality should be moved to
superclass (to allow creation of any qcow2 struct), but then, fields
of variable length (data here) should be supported in base class
- somehow. So, it's a TODO. We'll see how to properly refactor this when
- we have more qcow2 structures.
+ somehow. Note also, that we probably want to parse different
+ extensions. Should they be subclasses of this class, or how to do it
+ better? Should it be something like QAPI union with discriminator field
+ (magic here). So, it's a TODO. We'll see how to properly refactor this
+ when we have more qcow2 structures.
"""
if fd is None:
assert all(v is not None for v in (magic, length, data))
@@ -148,15 +164,23 @@ class QcowHeaderExtension(Qcow2Struct):
self.data = fd.read(padded)
assert self.data is not None
- def dump(self):
- data = self.data[:self.length]
- if all(c in string.printable.encode('ascii') for c in data):
- data = f"'{ data.decode('ascii') }'"
+ if self.magic == QCOW2_EXT_MAGIC_BITMAPS:
+ self.obj = Qcow2BitmapExt(data=self.data)
else:
- data = '<binary>'
+ self.obj = None
+ def dump(self):
super().dump()
- print(f'{"data":<25} {data}')
+
+ if self.obj is None:
+ data = self.data[:self.length]
+ if all(c in string.printable.encode('ascii') for c in data):
+ data = f"'{ data.decode('ascii') }'"
+ else:
+ data = '<binary>'
+ print(f'{"data":<25} {data}')
+ else:
+ self.obj.dump()
@classmethod
def create(cls, magic, data):
--
2.21.0
next prev parent reply other threads:[~2020-06-06 8:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 8:17 [PATCH v5 00/13] iotests: Dump QCOW2 dirty bitmaps metadata Vladimir Sementsov-Ogievskiy
2020-06-06 8:17 ` [PATCH v5 01/13] qcow2.py: python style fixes Vladimir Sementsov-Ogievskiy
2020-06-08 20:52 ` Eric Blake
2020-06-06 8:17 ` [PATCH v5 02/13] qcow2.py: add licensing blurb Vladimir Sementsov-Ogievskiy
2020-06-08 21:01 ` Eric Blake
2020-06-06 8:17 ` [PATCH v5 03/13] qcow2.py: move qcow2 format classes to separate module Vladimir Sementsov-Ogievskiy
2020-06-08 21:05 ` Eric Blake
2020-06-06 8:17 ` [PATCH v5 04/13] qcow2_format.py: drop new line printing at end of dump() Vladimir Sementsov-Ogievskiy
2020-06-06 8:17 ` [PATCH v5 05/13] qcow2_format.py: use tuples instead of lists for fields Vladimir Sementsov-Ogievskiy
2020-06-06 8:17 ` [PATCH v5 06/13] qcow2_format.py: use modern string formatting Vladimir Sementsov-Ogievskiy
2020-06-06 8:18 ` [PATCH v5 07/13] qcow2_format.py: use strings to specify c-type of struct fields Vladimir Sementsov-Ogievskiy
2020-06-06 8:18 ` [PATCH v5 08/13] qcow2_format.py: separate generic functionality of structure classes Vladimir Sementsov-Ogievskiy
2020-06-08 21:28 ` Eric Blake
2020-06-06 8:18 ` [PATCH v5 09/13] qcow2_format.py: add field-formatting class Vladimir Sementsov-Ogievskiy
2020-06-06 8:18 ` [PATCH v5 10/13] qcow2_format.py: QcowHeaderExtension: add dump method Vladimir Sementsov-Ogievskiy
2020-06-06 8:18 ` [PATCH v5 11/13] qcow2_format: refactor QcowHeaderExtension as a subclass of Qcow2Struct Vladimir Sementsov-Ogievskiy
2020-06-06 8:18 ` [PATCH v5 12/13] qcow2: QcowHeaderExtension print names for extension magics Vladimir Sementsov-Ogievskiy
2020-06-08 5:48 ` Andrey Shinkevich
2020-06-08 9:52 ` Andrey Shinkevich
2020-06-09 19:08 ` Eric Blake
2020-06-06 8:18 ` Vladimir Sementsov-Ogievskiy [this message]
2020-06-08 22:00 ` [PATCH v5 13/13] qcow2_format.py: dump bitmaps header extension Eric Blake
2020-06-09 7:11 ` Vladimir Sementsov-Ogievskiy
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=20200606081806.23897-14-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=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 \
/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).