qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v8 04/10] qcow2_format.py: dump bitmap flags in human readabl


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH v8 04/10] qcow2_format.py: dump bitmap flags in human readable way.
Date: Sat, 11 Jul 2020 19:43:42 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

03.07.2020 16:13, Andrey Shinkevich wrote:
Introduce the class BitmapFlags that parses a bitmap flags mask.

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
  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 1435e34..d8c058d 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)
+class BitmapFlags(Qcow2Field):
+
+    flags = {
+        0x1: 'in-use',
+        0x2: 'auto'
+    }
+
+    def __str__(self):
+        bits = []
+        for bit in range(64):
+            flag = self.value & (1 << bit)
+            if flag:
+                bits.append(self.flags.get(flag, '{:#x}'.format(flag)))

please use f-strings where possible, for consistency.

Also, more obvious notation for unknown bits would be f'bit-{bit}' I think, so 
you see number of bit, not big hex number.

+        return f'{self.value:#x} ({bits})'
+
+
  class Enum(Qcow2Field):
def __str__(self):



--
Best regards,
Vladimir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]