On 11/27/18 6:41 AM, Andrey Shinkevich wrote:
The 'Format specific information' of qemu-img info command will show
the name, flags and granularity for every QCOW2 bitmap.

Signed-off-by: Andrey Shinkevich <andrey.shinkev...@virtuozzo.com>
---
Dear colleagues,

With this patch, qemu-img info will display a name, flags and granularity
information for every bitmap in the directory section of a QCOW2 image.
That information appears in the 'Format specific information' section as
it's shown in the following example:

image: /vz/vmprivate/VM1/harddisk.hdd
file format: qcow2
virtual size: 64G (68719476736 bytes)
disk size: 3.0M
cluster_size: 1048576
Format specific information:
     compat: 1.1
     lazy refcounts: true
     refcount bits: 16
     dirty bitmaps:
         [0]:
             flags:
                 [0]: in-use
                 [1]: auto
             name: {257b5ea5-38c5-410e-a457-71c76f763c60}
             granularity: 65536
         [1]:
             flags:
                 [0]: in-use
                 [1]: auto
             name: back-up
             granularity: 65536
     corrupt: false

This example is worth including in the commit message proper (by putting it above the Signed-off-by and --- lines).

In addition to Vladimir's review (he's correct about using 4.0),

+++ b/block/qcow2-bitmap.c
@@ -1008,6 +1008,56 @@ fail:
      return false;
  }
+static Qcow2BitmapInfoFlagsList *get_bitmap_info_flags(uint32_t flags)
+{
+    Qcow2BitmapInfoFlagsList *list = NULL;
+    Qcow2BitmapInfoFlagsList **plist = &list;
+
+    if (flags & BME_FLAG_IN_USE) {
+        Qcow2BitmapInfoFlagsList *entry = g_new0(Qcow2BitmapInfoFlagsList, 1);
+        entry->value = QCOW2_BITMAP_INFO_FLAGS_IN_USE;
+        *plist = entry;
+        plist = &entry->next;
+    }
+    if (flags & BME_FLAG_AUTO) {
+        Qcow2BitmapInfoFlagsList *entry = g_new0(Qcow2BitmapInfoFlagsList, 1);
+        entry->value = QCOW2_BITMAP_INFO_FLAGS_AUTO;
+        *plist = entry;
+    }
+    return list;
+}

This implementation means that qemu won't report bits that are set but which qemu doesn't recognize. Is that a problem? I wouldn't over-engineer it unless we have a use case, but maybe one way would be to have an optional integer field alongside the array of known flags, where the integer is present only if there are unrecognized flags present. But by the time we encounter an image with more than the two flags we currently recognize, we may have also patched this code to recognize a new flag.

@@ -4279,6 +4287,8 @@ static ImageInfoSpecific 
*qcow2_get_specific_info(BlockDriverState *bs)
                                    QCOW2_INCOMPAT_CORRUPT,
              .has_corrupt        = true,
              .refcount_bits      = s->refcount_bits,
+            .has_bitmaps        = bitmaps ? true : false,

This looks awkward; I'd write it ' = !!bitmaps'.


+++ b/qapi/block-core.json
@@ -77,7 +77,8 @@
        '*lazy-refcounts': 'bool',
        '*corrupt': 'bool',
        'refcount-bits': 'int',
-      '*encrypt': 'ImageInfoSpecificQCow2Encryption'
+      '*encrypt': 'ImageInfoSpecificQCow2Encryption',
+      '*bitmaps': ['Qcow2BitmapInfo']

Missing documentation on the new member, including a '(since 4.0)' tag.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Reply via email to