Blame SOURCES/kvm-qcow2-Add-list-of-bitmaps-to-ImageInfoSpecificQCow2.patch

383d26
From bc648c67692348f9fa8cb091f5949c608dbc7565 Mon Sep 17 00:00:00 2001
383d26
From: John Snow <jsnow@redhat.com>
383d26
Date: Wed, 20 Mar 2019 21:48:37 +0100
383d26
Subject: [PATCH 044/163] qcow2: Add list of bitmaps to ImageInfoSpecificQCow2
383d26
383d26
RH-Author: John Snow <jsnow@redhat.com>
383d26
Message-id: <20190320214838.22027-10-jsnow@redhat.com>
383d26
Patchwork-id: 85000
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 09/10] qcow2: Add list of bitmaps to ImageInfoSpecificQCow2
383d26
Bugzilla: 1691048
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
383d26
383d26
In the 'Format specific information' section of the 'qemu-img info'
383d26
command output, the supplemental information about existing QCOW2
383d26
bitmaps will be shown, such as a bitmap name, flags and granularity:
383d26
383d26
image: /vz/vmprivate/VM1/harddisk.hdd
383d26
file format: qcow2
383d26
virtual size: 64G (68719476736 bytes)
383d26
disk size: 3.0M
383d26
cluster_size: 1048576
383d26
Format specific information:
383d26
    compat: 1.1
383d26
    lazy refcounts: true
383d26
    bitmaps:
383d26
        [0]:
383d26
            flags:
383d26
                [0]: in-use
383d26
                [1]: auto
383d26
            name: back-up1
383d26
            granularity: 65536
383d26
        [1]:
383d26
            flags:
383d26
                [0]: in-use
383d26
                [1]: auto
383d26
            name: back-up2
383d26
            granularity: 65536
383d26
    refcount bits: 16
383d26
    corrupt: false
383d26
383d26
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
383d26
Reviewed-by: Eric Blake <eblake@redhat.com>
383d26
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
383d26
Message-Id: <1549638368-530182-3-git-send-email-andrey.shinkevich@virtuozzo.com>
383d26
Signed-off-by: Eric Blake <eblake@redhat.com>
383d26
(cherry picked from commit b8968c875f4030dd6924d6971bb3d92dfa3d2f65)
383d26
Signed-off-by: John Snow <jsnow@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/qcow2-bitmap.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
383d26
 block/qcow2.c        | 11 +++++++-
383d26
 block/qcow2.h        |  2 ++
383d26
 qapi/block-core.json | 41 +++++++++++++++++++++++++++-
383d26
 4 files changed, 128 insertions(+), 2 deletions(-)
383d26
383d26
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
383d26
index a36773c..4899719 100644
383d26
--- a/block/qcow2-bitmap.c
383d26
+++ b/block/qcow2-bitmap.c
383d26
@@ -1008,6 +1008,82 @@ fail:
383d26
     return false;
383d26
 }
383d26
 
383d26
+
383d26
+static Qcow2BitmapInfoFlagsList *get_bitmap_info_flags(uint32_t flags)
383d26
+{
383d26
+    Qcow2BitmapInfoFlagsList *list = NULL;
383d26
+    Qcow2BitmapInfoFlagsList **plist = &list;
383d26
+    int i;
383d26
+
383d26
+    static const struct {
383d26
+        int bme;  /* Bitmap directory entry flags */
383d26
+        int info; /* The flags to report to the user */
383d26
+    } map[] = {
383d26
+        { BME_FLAG_IN_USE, QCOW2_BITMAP_INFO_FLAGS_IN_USE },
383d26
+        { BME_FLAG_AUTO,   QCOW2_BITMAP_INFO_FLAGS_AUTO },
383d26
+    };
383d26
+
383d26
+    int map_size = ARRAY_SIZE(map);
383d26
+
383d26
+    for (i = 0; i < map_size; ++i) {
383d26
+        if (flags & map[i].bme) {
383d26
+            Qcow2BitmapInfoFlagsList *entry =
383d26
+                g_new0(Qcow2BitmapInfoFlagsList, 1);
383d26
+            entry->value = map[i].info;
383d26
+            *plist = entry;
383d26
+            plist = &entry->next;
383d26
+            flags &= ~map[i].bme;
383d26
+        }
383d26
+    }
383d26
+    /* Check if the BME_* mapping above is complete */
383d26
+    assert(!flags);
383d26
+
383d26
+    return list;
383d26
+}
383d26
+
383d26
+/*
383d26
+ * qcow2_get_bitmap_info_list()
383d26
+ * Returns a list of QCOW2 bitmap details.
383d26
+ * In case of no bitmaps, the function returns NULL and
383d26
+ * the @errp parameter is not set.
383d26
+ * When bitmap information can not be obtained, the function returns
383d26
+ * NULL and the @errp parameter is set.
383d26
+ */
383d26
+Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDriverState *bs,
383d26
+                                                Error **errp)
383d26
+{
383d26
+    BDRVQcow2State *s = bs->opaque;
383d26
+    Qcow2BitmapList *bm_list;
383d26
+    Qcow2Bitmap *bm;
383d26
+    Qcow2BitmapInfoList *list = NULL;
383d26
+    Qcow2BitmapInfoList **plist = &list;
383d26
+
383d26
+    if (s->nb_bitmaps == 0) {
383d26
+        return NULL;
383d26
+    }
383d26
+
383d26
+    bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
383d26
+                               s->bitmap_directory_size, errp);
383d26
+    if (bm_list == NULL) {
383d26
+        return NULL;
383d26
+    }
383d26
+
383d26
+    QSIMPLEQ_FOREACH(bm, bm_list, entry) {
383d26
+        Qcow2BitmapInfo *info = g_new0(Qcow2BitmapInfo, 1);
383d26
+        Qcow2BitmapInfoList *obj = g_new0(Qcow2BitmapInfoList, 1);
383d26
+        info->granularity = 1U << bm->granularity_bits;
383d26
+        info->name = g_strdup(bm->name);
383d26
+        info->flags = get_bitmap_info_flags(bm->flags & ~BME_RESERVED_FLAGS);
383d26
+        obj->value = info;
383d26
+        *plist = obj;
383d26
+        plist = &obj->next;
383d26
+    }
383d26
+
383d26
+    bitmap_list_free(bm_list);
383d26
+
383d26
+    return list;
383d26
+}
383d26
+
383d26
 int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
383d26
                                  Error **errp)
383d26
 {
383d26
diff --git a/block/qcow2.c b/block/qcow2.c
383d26
index de9872f..21f7556 100644
383d26
--- a/block/qcow2.c
383d26
+++ b/block/qcow2.c
383d26
@@ -4185,7 +4185,7 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
383d26
     spec_info = g_new(ImageInfoSpecific, 1);
383d26
     *spec_info = (ImageInfoSpecific){
383d26
         .type  = IMAGE_INFO_SPECIFIC_KIND_QCOW2,
383d26
-        .u.qcow2.data = g_new(ImageInfoSpecificQCow2, 1),
383d26
+        .u.qcow2.data = g_new0(ImageInfoSpecificQCow2, 1),
383d26
     };
383d26
     if (s->qcow_version == 2) {
383d26
         *spec_info->u.qcow2.data = (ImageInfoSpecificQCow2){
383d26
@@ -4193,6 +4193,13 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
383d26
             .refcount_bits      = s->refcount_bits,
383d26
         };
383d26
     } else if (s->qcow_version == 3) {
383d26
+        Qcow2BitmapInfoList *bitmaps;
383d26
+        bitmaps = qcow2_get_bitmap_info_list(bs, &local_err);
383d26
+        if (local_err) {
383d26
+            error_propagate(errp, local_err);
383d26
+            qapi_free_ImageInfoSpecific(spec_info);
383d26
+            return NULL;
383d26
+        }
383d26
         *spec_info->u.qcow2.data = (ImageInfoSpecificQCow2){
383d26
             .compat             = g_strdup("1.1"),
383d26
             .lazy_refcounts     = s->compatible_features &
383d26
@@ -4202,6 +4209,8 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
383d26
                                   QCOW2_INCOMPAT_CORRUPT,
383d26
             .has_corrupt        = true,
383d26
             .refcount_bits      = s->refcount_bits,
383d26
+            .has_bitmaps        = !!bitmaps,
383d26
+            .bitmaps            = bitmaps,
383d26
         };
383d26
     } else {
383d26
         /* if this assertion fails, this probably means a new version was
383d26
diff --git a/block/qcow2.h b/block/qcow2.h
383d26
index 29b041c..2633e33 100644
383d26
--- a/block/qcow2.h
383d26
+++ b/block/qcow2.h
383d26
@@ -676,6 +676,8 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
383d26
                                   void **refcount_table,
383d26
                                   int64_t *refcount_table_size);
383d26
 bool qcow2_load_dirty_bitmaps(BlockDriverState *bs, Error **errp);
383d26
+Qcow2BitmapInfoList *qcow2_get_bitmap_info_list(BlockDriverState *bs,
383d26
+                                                Error **errp);
383d26
 int qcow2_reopen_bitmaps_rw_hint(BlockDriverState *bs, bool *header_updated,
383d26
                                  Error **errp);
383d26
 int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp);
383d26
diff --git a/qapi/block-core.json b/qapi/block-core.json
383d26
index 176c04e..5d6bb14 100644
383d26
--- a/qapi/block-core.json
383d26
+++ b/qapi/block-core.json
383d26
@@ -70,6 +70,8 @@
383d26
 # @encrypt: details about encryption parameters; only set if image
383d26
 #           is encrypted (since 2.10)
383d26
 #
383d26
+# @bitmaps: A list of qcow2 bitmap details (since 4.0)
383d26
+#
383d26
 # Since: 1.7
383d26
 ##
383d26
 { 'struct': 'ImageInfoSpecificQCow2',
383d26
@@ -78,7 +80,8 @@
383d26
       '*lazy-refcounts': 'bool',
383d26
       '*corrupt': 'bool',
383d26
       'refcount-bits': 'int',
383d26
-      '*encrypt': 'ImageInfoSpecificQCow2Encryption'
383d26
+      '*encrypt': 'ImageInfoSpecificQCow2Encryption',
383d26
+      '*bitmaps': ['Qcow2BitmapInfo']
383d26
   } }
383d26
 
383d26
 ##
383d26
@@ -455,6 +458,42 @@
383d26
            'status': 'DirtyBitmapStatus'} }
383d26
 
383d26
 ##
383d26
+# @Qcow2BitmapInfoFlags:
383d26
+#
383d26
+# An enumeration of flags that a bitmap can report to the user.
383d26
+#
383d26
+# @in-use: This flag is set by any process actively modifying the qcow2 file,
383d26
+#          and cleared when the updated bitmap is flushed to the qcow2 image.
383d26
+#          The presence of this flag in an offline image means that the bitmap
383d26
+#          was not saved correctly after its last usage, and may contain
383d26
+#          inconsistent data.
383d26
+#
383d26
+# @auto: The bitmap must reflect all changes of the virtual disk by any
383d26
+#        application that would write to this qcow2 file.
383d26
+#
383d26
+# Since: 4.0
383d26
+##
383d26
+{ 'enum': 'Qcow2BitmapInfoFlags',
383d26
+  'data': ['in-use', 'auto'] }
383d26
+
383d26
+##
383d26
+# @Qcow2BitmapInfo:
383d26
+#
383d26
+# Qcow2 bitmap information.
383d26
+#
383d26
+# @name: the name of the bitmap
383d26
+#
383d26
+# @granularity: granularity of the bitmap in bytes
383d26
+#
383d26
+# @flags: flags of the bitmap
383d26
+#
383d26
+# Since: 4.0
383d26
+##
383d26
+{ 'struct': 'Qcow2BitmapInfo',
383d26
+  'data': {'name': 'str', 'granularity': 'uint32',
383d26
+           'flags': ['Qcow2BitmapInfoFlags'] } }
383d26
+
383d26
+##
383d26
 # @BlockLatencyHistogramInfo:
383d26
 #
383d26
 # Block latency histogram.
383d26
-- 
383d26
1.8.3.1
383d26