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

26ba25
From f694daf74067ada6720659a7133224f727f98ed3 Mon Sep 17 00:00:00 2001
26ba25
From: John Snow <jsnow@redhat.com>
26ba25
Date: Wed, 18 Jul 2018 22:54:39 +0200
26ba25
Subject: [PATCH 221/268] qmp: transaction support for
26ba25
 x-block-dirty-bitmap-enable/disable
26ba25
26ba25
RH-Author: John Snow <jsnow@redhat.com>
26ba25
Message-id: <20180718225511.14878-4-jsnow@redhat.com>
26ba25
Patchwork-id: 81410
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 03/35] qmp: transaction support for x-block-dirty-bitmap-enable/disable
26ba25
Bugzilla: 1207657
26ba25
RH-Acked-by: Eric Blake <eblake@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Fam Zheng <famz@redhat.com>
26ba25
26ba25
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
26ba25
26ba25
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Reviewed-by: Jeff Cody <jcody@redhat.com>
26ba25
Message-id: 20180606182449.1607-4-jsnow@redhat.com
26ba25
[Added x- prefix. --js]
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
(cherry picked from commit c6490447402f574bbe45f45c318e0bdd19121baf)
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 blockdev.c            | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-
26ba25
 qapi/transaction.json |  4 +++
26ba25
 2 files changed, 84 insertions(+), 1 deletion(-)
26ba25
26ba25
diff --git a/blockdev.c b/blockdev.c
26ba25
index 9e435f4..b74b7d4 100644
26ba25
--- a/blockdev.c
26ba25
+++ b/blockdev.c
26ba25
@@ -2053,6 +2053,7 @@ typedef struct BlockDirtyBitmapState {
26ba25
     BlockDriverState *bs;
26ba25
     HBitmap *backup;
26ba25
     bool prepared;
26ba25
+    bool was_enabled;
26ba25
 } BlockDirtyBitmapState;
26ba25
 
26ba25
 static void block_dirty_bitmap_add_prepare(BlkActionState *common,
26ba25
@@ -2152,6 +2153,74 @@ static void block_dirty_bitmap_clear_commit(BlkActionState *common)
26ba25
     hbitmap_free(state->backup);
26ba25
 }
26ba25
 
26ba25
+static void block_dirty_bitmap_enable_prepare(BlkActionState *common,
26ba25
+                                              Error **errp)
26ba25
+{
26ba25
+    BlockDirtyBitmap *action;
26ba25
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
26ba25
+                                             common, common);
26ba25
+
26ba25
+    if (action_check_completion_mode(common, errp) < 0) {
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
+    action = common->action->u.x_block_dirty_bitmap_enable.data;
26ba25
+    state->bitmap = block_dirty_bitmap_lookup(action->node,
26ba25
+                                              action->name,
26ba25
+                                              NULL,
26ba25
+                                              errp);
26ba25
+    if (!state->bitmap) {
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
+    state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
26ba25
+    bdrv_enable_dirty_bitmap(state->bitmap);
26ba25
+}
26ba25
+
26ba25
+static void block_dirty_bitmap_enable_abort(BlkActionState *common)
26ba25
+{
26ba25
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
26ba25
+                                             common, common);
26ba25
+
26ba25
+    if (!state->was_enabled) {
26ba25
+        bdrv_disable_dirty_bitmap(state->bitmap);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
+static void block_dirty_bitmap_disable_prepare(BlkActionState *common,
26ba25
+                                               Error **errp)
26ba25
+{
26ba25
+    BlockDirtyBitmap *action;
26ba25
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
26ba25
+                                             common, common);
26ba25
+
26ba25
+    if (action_check_completion_mode(common, errp) < 0) {
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
+    action = common->action->u.x_block_dirty_bitmap_disable.data;
26ba25
+    state->bitmap = block_dirty_bitmap_lookup(action->node,
26ba25
+                                              action->name,
26ba25
+                                              NULL,
26ba25
+                                              errp);
26ba25
+    if (!state->bitmap) {
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
+    state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
26ba25
+    bdrv_disable_dirty_bitmap(state->bitmap);
26ba25
+}
26ba25
+
26ba25
+static void block_dirty_bitmap_disable_abort(BlkActionState *common)
26ba25
+{
26ba25
+    BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState,
26ba25
+                                             common, common);
26ba25
+
26ba25
+    if (state->was_enabled) {
26ba25
+        bdrv_enable_dirty_bitmap(state->bitmap);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
 static void abort_prepare(BlkActionState *common, Error **errp)
26ba25
 {
26ba25
     error_setg(errp, "Transaction aborted using Abort action");
26ba25
@@ -2212,7 +2281,17 @@ static const BlkActionOps actions[] = {
26ba25
         .prepare = block_dirty_bitmap_clear_prepare,
26ba25
         .commit = block_dirty_bitmap_clear_commit,
26ba25
         .abort = block_dirty_bitmap_clear_abort,
26ba25
-    }
26ba25
+    },
26ba25
+    [TRANSACTION_ACTION_KIND_X_BLOCK_DIRTY_BITMAP_ENABLE] = {
26ba25
+        .instance_size = sizeof(BlockDirtyBitmapState),
26ba25
+        .prepare = block_dirty_bitmap_enable_prepare,
26ba25
+        .abort = block_dirty_bitmap_enable_abort,
26ba25
+    },
26ba25
+    [TRANSACTION_ACTION_KIND_X_BLOCK_DIRTY_BITMAP_DISABLE] = {
26ba25
+        .instance_size = sizeof(BlockDirtyBitmapState),
26ba25
+        .prepare = block_dirty_bitmap_disable_prepare,
26ba25
+        .abort = block_dirty_bitmap_disable_abort,
26ba25
+     }
26ba25
 };
26ba25
 
26ba25
 /**
26ba25
diff --git a/qapi/transaction.json b/qapi/transaction.json
26ba25
index bd31279..d7e4274 100644
26ba25
--- a/qapi/transaction.json
26ba25
+++ b/qapi/transaction.json
26ba25
@@ -46,6 +46,8 @@
26ba25
 # - @abort: since 1.6
26ba25
 # - @block-dirty-bitmap-add: since 2.5
26ba25
 # - @block-dirty-bitmap-clear: since 2.5
26ba25
+# - @x-block-dirty-bitmap-enable: since 3.0
26ba25
+# - @x-block-dirty-bitmap-disable: since 3.0
26ba25
 # - @blockdev-backup: since 2.3
26ba25
 # - @blockdev-snapshot: since 2.5
26ba25
 # - @blockdev-snapshot-internal-sync: since 1.7
26ba25
@@ -59,6 +61,8 @@
26ba25
        'abort': 'Abort',
26ba25
        'block-dirty-bitmap-add': 'BlockDirtyBitmapAdd',
26ba25
        'block-dirty-bitmap-clear': 'BlockDirtyBitmap',
26ba25
+       'x-block-dirty-bitmap-enable': 'BlockDirtyBitmap',
26ba25
+       'x-block-dirty-bitmap-disable': 'BlockDirtyBitmap',
26ba25
        'blockdev-backup': 'BlockdevBackup',
26ba25
        'blockdev-snapshot': 'BlockdevSnapshot',
26ba25
        'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal',
26ba25
-- 
26ba25
1.8.3.1
26ba25