Blame SOURCES/kvm-qmp-transaction-support-for-x-block-dirty-bitmap-ena.patch

357786
From a2c0037a5871c5982b742f255f6580f30482f1fc Mon Sep 17 00:00:00 2001
357786
From: John Snow <jsnow@redhat.com>
357786
Date: Wed, 18 Jul 2018 22:54:39 +0200
357786
Subject: [PATCH 54/89] qmp: transaction support for
357786
 x-block-dirty-bitmap-enable/disable
357786
357786
RH-Author: John Snow <jsnow@redhat.com>
357786
Message-id: <20180718225511.14878-4-jsnow@redhat.com>
357786
Patchwork-id: 81410
357786
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 03/35] qmp: transaction support for x-block-dirty-bitmap-enable/disable
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-4-jsnow@redhat.com
357786
[Added x- prefix. --js]
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
(cherry picked from commit c6490447402f574bbe45f45c318e0bdd19121baf)
357786
Signed-off-by: John Snow <jsnow@redhat.com>
357786
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 blockdev.c            | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-
357786
 qapi/transaction.json |  4 +++
357786
 2 files changed, 84 insertions(+), 1 deletion(-)
357786
357786
diff --git a/blockdev.c b/blockdev.c
357786
index ca2ffff..a88d792 100644
357786
--- a/blockdev.c
357786
+++ b/blockdev.c
357786
@@ -2094,6 +2094,7 @@ typedef struct BlockDirtyBitmapState {
357786
     BlockDriverState *bs;
357786
     HBitmap *backup;
357786
     bool prepared;
357786
+    bool was_enabled;
357786
 } BlockDirtyBitmapState;
357786
 
357786
 static void block_dirty_bitmap_add_prepare(BlkActionState *common,
357786
@@ -2193,6 +2194,74 @@ static void block_dirty_bitmap_clear_commit(BlkActionState *common)
357786
     hbitmap_free(state->backup);
357786
 }
357786
 
357786
+static void block_dirty_bitmap_enable_prepare(BlkActionState *common,
357786
+                                              Error **errp)
357786
+{
357786
+    BlockDirtyBitmap *action;
357786
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
357786
+                                             common, common);
357786
+
357786
+    if (action_check_completion_mode(common, errp) < 0) {
357786
+        return;
357786
+    }
357786
+
357786
+    action = common->action->u.x_block_dirty_bitmap_enable.data;
357786
+    state->bitmap = block_dirty_bitmap_lookup(action->node,
357786
+                                              action->name,
357786
+                                              NULL,
357786
+                                              errp);
357786
+    if (!state->bitmap) {
357786
+        return;
357786
+    }
357786
+
357786
+    state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
357786
+    bdrv_enable_dirty_bitmap(state->bitmap);
357786
+}
357786
+
357786
+static void block_dirty_bitmap_enable_abort(BlkActionState *common)
357786
+{
357786
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
357786
+                                             common, common);
357786
+
357786
+    if (!state->was_enabled) {
357786
+        bdrv_disable_dirty_bitmap(state->bitmap);
357786
+    }
357786
+}
357786
+
357786
+static void block_dirty_bitmap_disable_prepare(BlkActionState *common,
357786
+                                               Error **errp)
357786
+{
357786
+    BlockDirtyBitmap *action;
357786
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
357786
+                                             common, common);
357786
+
357786
+    if (action_check_completion_mode(common, errp) < 0) {
357786
+        return;
357786
+    }
357786
+
357786
+    action = common->action->u.x_block_dirty_bitmap_disable.data;
357786
+    state->bitmap = block_dirty_bitmap_lookup(action->node,
357786
+                                              action->name,
357786
+                                              NULL,
357786
+                                              errp);
357786
+    if (!state->bitmap) {
357786
+        return;
357786
+    }
357786
+
357786
+    state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
357786
+    bdrv_disable_dirty_bitmap(state->bitmap);
357786
+}
357786
+
357786
+static void block_dirty_bitmap_disable_abort(BlkActionState *common)
357786
+{
357786
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
357786
+                                             common, common);
357786
+
357786
+    if (state->was_enabled) {
357786
+        bdrv_enable_dirty_bitmap(state->bitmap);
357786
+    }
357786
+}
357786
+
357786
 static void abort_prepare(BlkActionState *common, Error **errp)
357786
 {
357786
     error_setg(errp, "Transaction aborted using Abort action");
357786
@@ -2253,7 +2322,17 @@ static const BlkActionOps actions[] = {
357786
         .prepare = block_dirty_bitmap_clear_prepare,
357786
         .commit = block_dirty_bitmap_clear_commit,
357786
         .abort = block_dirty_bitmap_clear_abort,
357786
-    }
357786
+    },
357786
+    [TRANSACTION_ACTION_KIND_X_BLOCK_DIRTY_BITMAP_ENABLE] = {
357786
+        .instance_size = sizeof(BlockDirtyBitmapState),
357786
+        .prepare = block_dirty_bitmap_enable_prepare,
357786
+        .abort = block_dirty_bitmap_enable_abort,
357786
+    },
357786
+    [TRANSACTION_ACTION_KIND_X_BLOCK_DIRTY_BITMAP_DISABLE] = {
357786
+        .instance_size = sizeof(BlockDirtyBitmapState),
357786
+        .prepare = block_dirty_bitmap_disable_prepare,
357786
+        .abort = block_dirty_bitmap_disable_abort,
357786
+     }
357786
 };
357786
 
357786
 /**
357786
diff --git a/qapi/transaction.json b/qapi/transaction.json
357786
index bd31279..d7e4274 100644
357786
--- a/qapi/transaction.json
357786
+++ b/qapi/transaction.json
357786
@@ -46,6 +46,8 @@
357786
 # - @abort: since 1.6
357786
 # - @block-dirty-bitmap-add: since 2.5
357786
 # - @block-dirty-bitmap-clear: since 2.5
357786
+# - @x-block-dirty-bitmap-enable: since 3.0
357786
+# - @x-block-dirty-bitmap-disable: since 3.0
357786
 # - @blockdev-backup: since 2.3
357786
 # - @blockdev-snapshot: since 2.5
357786
 # - @blockdev-snapshot-internal-sync: since 1.7
357786
@@ -59,6 +61,8 @@
357786
        'abort': 'Abort',
357786
        'block-dirty-bitmap-add': 'BlockDirtyBitmapAdd',
357786
        'block-dirty-bitmap-clear': 'BlockDirtyBitmap',
357786
+       'x-block-dirty-bitmap-enable': 'BlockDirtyBitmap',
357786
+       'x-block-dirty-bitmap-disable': 'BlockDirtyBitmap',
357786
        'blockdev-backup': 'BlockdevBackup',
357786
        'blockdev-snapshot': 'BlockdevSnapshot',
357786
        'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal',
357786
-- 
357786
1.8.3.1
357786