Blame SOURCES/kvm-qapi-add-x-block-dirty-bitmap-merge.patch

357786
From 56f208617b142524b79ddd060db62c045561c418 Mon Sep 17 00:00:00 2001
357786
From: John Snow <jsnow@redhat.com>
357786
Date: Wed, 18 Jul 2018 22:54:40 +0200
357786
Subject: [PATCH 55/89] qapi: add x-block-dirty-bitmap-merge
357786
357786
RH-Author: John Snow <jsnow@redhat.com>
357786
Message-id: <20180718225511.14878-5-jsnow@redhat.com>
357786
Patchwork-id: 81397
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 04/35] qapi: add x-block-dirty-bitmap-merge
357786
Bugzilla: 1207657
357786
RH-Acked-by: Eric Blake <eblake@redhat.com>
357786
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
357786
357786
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Reviewed-by: Jeff Cody <jcody@redhat.com>
357786
Message-id: 20180606182449.1607-5-jsnow@redhat.com
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
(cherry picked from commit b598e531f1123d2fb72615f1161c66093be751ea)
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/dirty-bitmap.c         | 18 ++++++++++++++++++
357786
 blockdev.c                   | 30 ++++++++++++++++++++++++++++++
357786
 include/block/dirty-bitmap.h |  3 ++-
357786
 qapi/block-core.json         | 38 ++++++++++++++++++++++++++++++++++++++
357786
 4 files changed, 88 insertions(+), 1 deletion(-)
357786
357786
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
357786
index 5623425..4159d39 100644
357786
--- a/block/dirty-bitmap.c
357786
+++ b/block/dirty-bitmap.c
357786
@@ -757,3 +757,21 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset)
357786
 {
357786
     return hbitmap_next_zero(bitmap->bitmap, offset);
357786
 }
357786
+
357786
+void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
357786
+                             Error **errp)
357786
+{
357786
+    /* only bitmaps from one bds are supported */
357786
+    assert(dest->mutex == src->mutex);
357786
+
357786
+    qemu_mutex_lock(dest->mutex);
357786
+
357786
+    assert(bdrv_dirty_bitmap_enabled(dest));
357786
+    assert(!bdrv_dirty_bitmap_readonly(dest));
357786
+
357786
+    if (!hbitmap_merge(dest->bitmap, src->bitmap)) {
357786
+        error_setg(errp, "Bitmaps are incompatible and can't be merged");
357786
+    }
357786
+
357786
+    qemu_mutex_unlock(dest->mutex);
357786
+}
357786
diff --git a/blockdev.c b/blockdev.c
357786
index a88d792..3728082 100644
357786
--- a/blockdev.c
357786
+++ b/blockdev.c
357786
@@ -3086,6 +3086,36 @@ void qmp_x_block_dirty_bitmap_disable(const char *node, const char *name,
357786
     bdrv_disable_dirty_bitmap(bitmap);
357786
 }
357786
 
357786
+void qmp_x_block_dirty_bitmap_merge(const char *node, const char *dst_name,
357786
+                                    const char *src_name, Error **errp)
357786
+{
357786
+    BlockDriverState *bs;
357786
+    BdrvDirtyBitmap *dst, *src;
357786
+
357786
+    dst = block_dirty_bitmap_lookup(node, dst_name, &bs, errp);
357786
+    if (!dst) {
357786
+        return;
357786
+    }
357786
+
357786
+    if (bdrv_dirty_bitmap_frozen(dst)) {
357786
+        error_setg(errp, "Bitmap '%s' is frozen and cannot be modified",
357786
+                   dst_name);
357786
+        return;
357786
+    } else if (bdrv_dirty_bitmap_readonly(dst)) {
357786
+        error_setg(errp, "Bitmap '%s' is readonly and cannot be modified",
357786
+                   dst_name);
357786
+        return;
357786
+    }
357786
+
357786
+    src = bdrv_find_dirty_bitmap(bs, src_name);
357786
+    if (!src) {
357786
+        error_setg(errp, "Dirty bitmap '%s' not found", src_name);
357786
+        return;
357786
+    }
357786
+
357786
+    bdrv_merge_dirty_bitmap(dst, src, errp);
357786
+}
357786
+
357786
 BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *node,
357786
                                                               const char *name,
357786
                                                               Error **errp)
357786
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
357786
index 1ff8949..1e14743 100644
357786
--- a/include/block/dirty-bitmap.h
357786
+++ b/include/block/dirty-bitmap.h
357786
@@ -70,7 +70,8 @@ void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
357786
 void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
357786
                                        bool persistent);
357786
 void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked);
357786
-
357786
+void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
357786
+                             Error **errp);
357786
 
357786
 /* Functions that require manual locking.  */
357786
 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
357786
diff --git a/qapi/block-core.json b/qapi/block-core.json
357786
index 5c8cfa3..4e1fda3 100644
357786
--- a/qapi/block-core.json
357786
+++ b/qapi/block-core.json
357786
@@ -1741,6 +1741,20 @@
357786
             '*persistent': 'bool', '*autoload': 'bool' } }
357786
 
357786
 ##
357786
+# @BlockDirtyBitmapMerge:
357786
+#
357786
+# @node: name of device/node which the bitmap is tracking
357786
+#
357786
+# @dst_name: name of the destination dirty bitmap
357786
+#
357786
+# @src_name: name of the source dirty bitmap
357786
+#
357786
+# Since: 3.0
357786
+##
357786
+{ 'struct': 'BlockDirtyBitmapMerge',
357786
+  'data': { 'node': 'str', 'dst_name': 'str', 'src_name': 'str' } }
357786
+
357786
+##
357786
 # @block-dirty-bitmap-add:
357786
 #
357786
 # Create a dirty bitmap with a name on the node, and start tracking the writes.
357786
@@ -1851,6 +1865,30 @@
357786
       'data': 'BlockDirtyBitmap' }
357786
 
357786
 ##
357786
+# @x-block-dirty-bitmap-merge:
357786
+#
357786
+# Merge @src_name dirty bitmap to @dst_name dirty bitmap. @src_name dirty
357786
+# bitmap is unchanged. On error, @dst_name is unchanged.
357786
+#
357786
+# Returns: nothing on success
357786
+#          If @node is not a valid block device, DeviceNotFound
357786
+#          If @dst_name or @src_name is not found, GenericError
357786
+#          If bitmaps has different sizes or granularities, GenericError
357786
+#
357786
+# Since: 3.0
357786
+#
357786
+# Example:
357786
+#
357786
+# -> { "execute": "x-block-dirty-bitmap-merge",
357786
+#      "arguments": { "node": "drive0", "dst_name": "bitmap0",
357786
+#                     "src_name": "bitmap1" } }
357786
+# <- { "return": {} }
357786
+#
357786
+##
357786
+      { 'command': 'x-block-dirty-bitmap-merge',
357786
+        'data': 'BlockDirtyBitmapMerge' }
357786
+
357786
+##
357786
 # @BlockDirtyBitmapSha256:
357786
 #
357786
 # SHA256 hash of dirty bitmap data
357786
-- 
357786
1.8.3.1
357786