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

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