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

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