Blame SOURCES/kvm-blockdev-Split-off-basic-bitmap-operations-for-qemu-.patch

902636
From 2afa718d59ef86879a9e34b4601a1f2658afa9ba Mon Sep 17 00:00:00 2001
902636
From: Eric Blake <eblake@redhat.com>
902636
Date: Tue, 2 Jun 2020 02:34:14 +0100
902636
Subject: [PATCH 09/26] blockdev: Split off basic bitmap operations for
902636
 qemu-img
902636
902636
RH-Author: Eric Blake <eblake@redhat.com>
902636
Message-id: <20200602023420.2133649-7-eblake@redhat.com>
902636
Patchwork-id: 97073
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 06/12] blockdev: Split off basic bitmap operations for qemu-img
902636
Bugzilla: 1779893 1779904
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
902636
902636
Upcoming patches want to add some basic bitmap manipulation abilities
902636
to qemu-img.  But blockdev.o is too heavyweight to link into qemu-img
902636
(among other things, it would drag in block jobs and transaction
902636
support - qemu-img does offline manipulation, where atomicity is less
902636
important because there are no concurrent modifications to compete
902636
with), so it's time to split off the bare bones of what we will need
902636
into a new file block/monitor/bitmap-qmp-cmds.o.
902636
902636
This is sufficient to expose 6 QMP commands for use by qemu-img (add,
902636
remove, clear, enable, disable, merge), as well as move the three
902636
helper functions touched in the previous patch.  Regarding
902636
MAINTAINERS, the new file is automatically part of block core, but
902636
also makes sense as related to other dirty bitmap files.
902636
902636
Signed-off-by: Eric Blake <eblake@redhat.com>
902636
Reviewed-by: Max Reitz <mreitz@redhat.com>
902636
Message-Id: <20200513011648.166876-6-eblake@redhat.com>
902636
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
902636
(cherry picked from commit bb4e58c6137e80129b955789dd4b66c1504f20dc)
902636
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
902636
Conflicts:
902636
	Makefile.objs - comment context
902636
	block/monitor/Makefile.objs - context: a2dde2f2 not backported
902636
	blockdev.c - context
902636
Signed-off-by: Eric Blake <eblake@redhat.com>
902636
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 MAINTAINERS                     |   1 +
902636
 Makefile.objs                   |   3 +-
902636
 block/monitor/Makefile.objs     |   1 +
902636
 block/monitor/bitmap-qmp-cmds.c | 321 ++++++++++++++++++++++++++++++++++++++++
902636
 blockdev.c                      | 284 -----------------------------------
902636
 5 files changed, 324 insertions(+), 286 deletions(-)
902636
 create mode 100644 block/monitor/Makefile.objs
902636
 create mode 100644 block/monitor/bitmap-qmp-cmds.c
902636
902636
diff --git a/MAINTAINERS b/MAINTAINERS
902636
index 3a81ac9..49d5d44 100644
902636
--- a/MAINTAINERS
902636
+++ b/MAINTAINERS
902636
@@ -1875,6 +1875,7 @@ L: qemu-block@nongnu.org
902636
 S: Supported
902636
 F: include/qemu/hbitmap.h
902636
 F: include/block/dirty-bitmap.h
902636
+F: block/monitor/bitmap-qmp-cmds.c
902636
 F: block/dirty-bitmap.c
902636
 F: block/qcow2-bitmap.c
902636
 F: migration/block-dirty-bitmap.c
902636
diff --git a/Makefile.objs b/Makefile.objs
902636
index 1a8f288..7404ef0 100644
902636
--- a/Makefile.objs
902636
+++ b/Makefile.objs
902636
@@ -13,9 +13,8 @@ authz-obj-y = authz/
902636
 #######################################################################
902636
 # block-obj-y is code used by both qemu system emulation and qemu-img
902636
 
902636
-block-obj-y = nbd/
902636
+block-obj-y = block/ block/monitor/ nbd/ scsi/
902636
 block-obj-y += block.o blockjob.o job.o
902636
-block-obj-y += block/ scsi/
902636
 block-obj-y += qemu-io-cmds.o
902636
 block-obj-$(CONFIG_REPLICATION) += replication.o
902636
 
902636
diff --git a/block/monitor/Makefile.objs b/block/monitor/Makefile.objs
902636
new file mode 100644
902636
index 0000000..f0c7642
902636
--- /dev/null
902636
+++ b/block/monitor/Makefile.objs
902636
@@ -0,0 +1 @@
902636
+block-obj-y += bitmap-qmp-cmds.o
902636
diff --git a/block/monitor/bitmap-qmp-cmds.c b/block/monitor/bitmap-qmp-cmds.c
902636
new file mode 100644
902636
index 0000000..9f11dee
902636
--- /dev/null
902636
+++ b/block/monitor/bitmap-qmp-cmds.c
902636
@@ -0,0 +1,321 @@
902636
+/*
902636
+ * QEMU block dirty bitmap QMP commands
902636
+ *
902636
+ * Copyright (c) 2003-2008 Fabrice Bellard
902636
+ *
902636
+ * This work is licensed under the terms of the GNU GPL, version 2 or
902636
+ * later.  See the COPYING file in the top-level directory.
902636
+ *
902636
+ * This file incorporates work covered by the following copyright and
902636
+ * permission notice:
902636
+ *
902636
+ * Copyright (c) 2003-2008 Fabrice Bellard
902636
+ *
902636
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
902636
+ * of this software and associated documentation files (the "Software"), to deal
902636
+ * in the Software without restriction, including without limitation the rights
902636
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
902636
+ * copies of the Software, and to permit persons to whom the Software is
902636
+ * furnished to do so, subject to the following conditions:
902636
+ *
902636
+ * The above copyright notice and this permission notice shall be included in
902636
+ * all copies or substantial portions of the Software.
902636
+ *
902636
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
902636
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
902636
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
902636
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
902636
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
902636
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
902636
+ * THE SOFTWARE.
902636
+ */
902636
+
902636
+#include "qemu/osdep.h"
902636
+
902636
+#include "block/block_int.h"
902636
+#include "qapi/qapi-commands-block.h"
902636
+#include "qapi/error.h"
902636
+
902636
+/**
902636
+ * block_dirty_bitmap_lookup:
902636
+ * Return a dirty bitmap (if present), after validating
902636
+ * the node reference and bitmap names.
902636
+ *
902636
+ * @node: The name of the BDS node to search for bitmaps
902636
+ * @name: The name of the bitmap to search for
902636
+ * @pbs: Output pointer for BDS lookup, if desired. Can be NULL.
902636
+ * @errp: Output pointer for error information. Can be NULL.
902636
+ *
902636
+ * @return: A bitmap object on success, or NULL on failure.
902636
+ */
902636
+BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node,
902636
+                                           const char *name,
902636
+                                           BlockDriverState **pbs,
902636
+                                           Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *bitmap;
902636
+
902636
+    if (!node) {
902636
+        error_setg(errp, "Node cannot be NULL");
902636
+        return NULL;
902636
+    }
902636
+    if (!name) {
902636
+        error_setg(errp, "Bitmap name cannot be NULL");
902636
+        return NULL;
902636
+    }
902636
+    bs = bdrv_lookup_bs(node, node, NULL);
902636
+    if (!bs) {
902636
+        error_setg(errp, "Node '%s' not found", node);
902636
+        return NULL;
902636
+    }
902636
+
902636
+    bitmap = bdrv_find_dirty_bitmap(bs, name);
902636
+    if (!bitmap) {
902636
+        error_setg(errp, "Dirty bitmap '%s' not found", name);
902636
+        return NULL;
902636
+    }
902636
+
902636
+    if (pbs) {
902636
+        *pbs = bs;
902636
+    }
902636
+
902636
+    return bitmap;
902636
+}
902636
+
902636
+void qmp_block_dirty_bitmap_add(const char *node, const char *name,
902636
+                                bool has_granularity, uint32_t granularity,
902636
+                                bool has_persistent, bool persistent,
902636
+                                bool has_disabled, bool disabled,
902636
+                                Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *bitmap;
902636
+    AioContext *aio_context;
902636
+
902636
+    if (!name || name[0] == '\0') {
902636
+        error_setg(errp, "Bitmap name cannot be empty");
902636
+        return;
902636
+    }
902636
+
902636
+    bs = bdrv_lookup_bs(node, node, errp);
902636
+    if (!bs) {
902636
+        return;
902636
+    }
902636
+
902636
+    aio_context = bdrv_get_aio_context(bs);
902636
+    aio_context_acquire(aio_context);
902636
+
902636
+    if (has_granularity) {
902636
+        if (granularity < 512 || !is_power_of_2(granularity)) {
902636
+            error_setg(errp, "Granularity must be power of 2 "
902636
+                             "and at least 512");
902636
+            goto out;
902636
+        }
902636
+    } else {
902636
+        /* Default to cluster size, if available: */
902636
+        granularity = bdrv_get_default_bitmap_granularity(bs);
902636
+    }
902636
+
902636
+    if (!has_persistent) {
902636
+        persistent = false;
902636
+    }
902636
+
902636
+    if (!has_disabled) {
902636
+        disabled = false;
902636
+    }
902636
+
902636
+    if (persistent &&
902636
+        !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))
902636
+    {
902636
+        goto out;
902636
+    }
902636
+
902636
+    bitmap = bdrv_create_dirty_bitmap(bs, granularity, name, errp);
902636
+    if (bitmap == NULL) {
902636
+        goto out;
902636
+    }
902636
+
902636
+    if (disabled) {
902636
+        bdrv_disable_dirty_bitmap(bitmap);
902636
+    }
902636
+
902636
+    bdrv_dirty_bitmap_set_persistence(bitmap, persistent);
902636
+
902636
+out:
902636
+    aio_context_release(aio_context);
902636
+}
902636
+
902636
+BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
902636
+                                           bool release,
902636
+                                           BlockDriverState **bitmap_bs,
902636
+                                           Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *bitmap;
902636
+    AioContext *aio_context;
902636
+
902636
+    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
+    if (!bitmap || !bs) {
902636
+        return NULL;
902636
+    }
902636
+
902636
+    aio_context = bdrv_get_aio_context(bs);
902636
+    aio_context_acquire(aio_context);
902636
+
902636
+    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO,
902636
+                                errp)) {
902636
+        aio_context_release(aio_context);
902636
+        return NULL;
902636
+    }
902636
+
902636
+    if (bdrv_dirty_bitmap_get_persistence(bitmap) &&
902636
+        bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0)
902636
+    {
902636
+        aio_context_release(aio_context);
902636
+        return NULL;
902636
+    }
902636
+
902636
+    if (release) {
902636
+        bdrv_release_dirty_bitmap(bitmap);
902636
+    }
902636
+
902636
+    if (bitmap_bs) {
902636
+        *bitmap_bs = bs;
902636
+    }
902636
+
902636
+    aio_context_release(aio_context);
902636
+    return release ? NULL : bitmap;
902636
+}
902636
+
902636
+void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
902636
+                                   Error **errp)
902636
+{
902636
+    block_dirty_bitmap_remove(node, name, true, NULL, errp);
902636
+}
902636
+
902636
+/**
902636
+ * Completely clear a bitmap, for the purposes of synchronizing a bitmap
902636
+ * immediately after a full backup operation.
902636
+ */
902636
+void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
902636
+                                  Error **errp)
902636
+{
902636
+    BdrvDirtyBitmap *bitmap;
902636
+    BlockDriverState *bs;
902636
+
902636
+    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
+    if (!bitmap || !bs) {
902636
+        return;
902636
+    }
902636
+
902636
+    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) {
902636
+        return;
902636
+    }
902636
+
902636
+    bdrv_clear_dirty_bitmap(bitmap, NULL);
902636
+}
902636
+
902636
+void qmp_block_dirty_bitmap_enable(const char *node, const char *name,
902636
+                                   Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *bitmap;
902636
+
902636
+    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
+    if (!bitmap) {
902636
+        return;
902636
+    }
902636
+
902636
+    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
902636
+        return;
902636
+    }
902636
+
902636
+    bdrv_enable_dirty_bitmap(bitmap);
902636
+}
902636
+
902636
+void qmp_block_dirty_bitmap_disable(const char *node, const char *name,
902636
+                                    Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *bitmap;
902636
+
902636
+    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
+    if (!bitmap) {
902636
+        return;
902636
+    }
902636
+
902636
+    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
902636
+        return;
902636
+    }
902636
+
902636
+    bdrv_disable_dirty_bitmap(bitmap);
902636
+}
902636
+
902636
+BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target,
902636
+                                          BlockDirtyBitmapMergeSourceList *bms,
902636
+                                          HBitmap **backup, Error **errp)
902636
+{
902636
+    BlockDriverState *bs;
902636
+    BdrvDirtyBitmap *dst, *src, *anon;
902636
+    BlockDirtyBitmapMergeSourceList *lst;
902636
+    Error *local_err = NULL;
902636
+
902636
+    dst = block_dirty_bitmap_lookup(node, target, &bs, errp);
902636
+    if (!dst) {
902636
+        return NULL;
902636
+    }
902636
+
902636
+    anon = bdrv_create_dirty_bitmap(bs, bdrv_dirty_bitmap_granularity(dst),
902636
+                                    NULL, errp);
902636
+    if (!anon) {
902636
+        return NULL;
902636
+    }
902636
+
902636
+    for (lst = bms; lst; lst = lst->next) {
902636
+        switch (lst->value->type) {
902636
+            const char *name, *node;
902636
+        case QTYPE_QSTRING:
902636
+            name = lst->value->u.local;
902636
+            src = bdrv_find_dirty_bitmap(bs, name);
902636
+            if (!src) {
902636
+                error_setg(errp, "Dirty bitmap '%s' not found", name);
902636
+                dst = NULL;
902636
+                goto out;
902636
+            }
902636
+            break;
902636
+        case QTYPE_QDICT:
902636
+            node = lst->value->u.external.node;
902636
+            name = lst->value->u.external.name;
902636
+            src = block_dirty_bitmap_lookup(node, name, NULL, errp);
902636
+            if (!src) {
902636
+                dst = NULL;
902636
+                goto out;
902636
+            }
902636
+            break;
902636
+        default:
902636
+            abort();
902636
+        }
902636
+
902636
+        bdrv_merge_dirty_bitmap(anon, src, NULL, &local_err);
902636
+        if (local_err) {
902636
+            error_propagate(errp, local_err);
902636
+            dst = NULL;
902636
+            goto out;
902636
+        }
902636
+    }
902636
+
902636
+    /* Merge into dst; dst is unchanged on failure. */
902636
+    bdrv_merge_dirty_bitmap(dst, anon, backup, errp);
902636
+
902636
+ out:
902636
+    bdrv_release_dirty_bitmap(anon);
902636
+    return dst;
902636
+}
902636
+
902636
+void qmp_block_dirty_bitmap_merge(const char *node, const char *target,
902636
+                                  BlockDirtyBitmapMergeSourceList *bitmaps,
902636
+                                  Error **errp)
902636
+{
902636
+    block_dirty_bitmap_merge(node, target, bitmaps, NULL, errp);
902636
+}
902636
diff --git a/blockdev.c b/blockdev.c
902636
index 3958058..5128c9b 100644
902636
--- a/blockdev.c
902636
+++ b/blockdev.c
902636
@@ -1250,53 +1250,6 @@ out_aio_context:
902636
     return NULL;
902636
 }
902636
 
902636
-/**
902636
- * block_dirty_bitmap_lookup:
902636
- * Return a dirty bitmap (if present), after validating
902636
- * the node reference and bitmap names.
902636
- *
902636
- * @node: The name of the BDS node to search for bitmaps
902636
- * @name: The name of the bitmap to search for
902636
- * @pbs: Output pointer for BDS lookup, if desired. Can be NULL.
902636
- * @errp: Output pointer for error information. Can be NULL.
902636
- *
902636
- * @return: A bitmap object on success, or NULL on failure.
902636
- */
902636
-BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node,
902636
-                                           const char *name,
902636
-                                           BlockDriverState **pbs,
902636
-                                           Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *bitmap;
902636
-
902636
-    if (!node) {
902636
-        error_setg(errp, "Node cannot be NULL");
902636
-        return NULL;
902636
-    }
902636
-    if (!name) {
902636
-        error_setg(errp, "Bitmap name cannot be NULL");
902636
-        return NULL;
902636
-    }
902636
-    bs = bdrv_lookup_bs(node, node, NULL);
902636
-    if (!bs) {
902636
-        error_setg(errp, "Node '%s' not found", node);
902636
-        return NULL;
902636
-    }
902636
-
902636
-    bitmap = bdrv_find_dirty_bitmap(bs, name);
902636
-    if (!bitmap) {
902636
-        error_setg(errp, "Dirty bitmap '%s' not found", name);
902636
-        return NULL;
902636
-    }
902636
-
902636
-    if (pbs) {
902636
-        *pbs = bs;
902636
-    }
902636
-
902636
-    return bitmap;
902636
-}
902636
-
902636
 /* New and old BlockDriverState structs for atomic group operations */
902636
 
902636
 typedef struct BlkActionState BlkActionState;
902636
@@ -2974,243 +2927,6 @@ out:
902636
     aio_context_release(aio_context);
902636
 }
902636
 
902636
-void qmp_block_dirty_bitmap_add(const char *node, const char *name,
902636
-                                bool has_granularity, uint32_t granularity,
902636
-                                bool has_persistent, bool persistent,
902636
-                                bool has_disabled, bool disabled,
902636
-                                Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *bitmap;
902636
-    AioContext *aio_context;
902636
-
902636
-    if (!name || name[0] == '\0') {
902636
-        error_setg(errp, "Bitmap name cannot be empty");
902636
-        return;
902636
-    }
902636
-
902636
-    bs = bdrv_lookup_bs(node, node, errp);
902636
-    if (!bs) {
902636
-        return;
902636
-    }
902636
-
902636
-    aio_context = bdrv_get_aio_context(bs);
902636
-    aio_context_acquire(aio_context);
902636
-
902636
-    if (has_granularity) {
902636
-        if (granularity < 512 || !is_power_of_2(granularity)) {
902636
-            error_setg(errp, "Granularity must be power of 2 "
902636
-                             "and at least 512");
902636
-            goto out;
902636
-        }
902636
-    } else {
902636
-        /* Default to cluster size, if available: */
902636
-        granularity = bdrv_get_default_bitmap_granularity(bs);
902636
-    }
902636
-
902636
-    if (!has_persistent) {
902636
-        persistent = false;
902636
-    }
902636
-
902636
-    if (!has_disabled) {
902636
-        disabled = false;
902636
-    }
902636
-
902636
-    if (persistent &&
902636
-        !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))
902636
-    {
902636
-        goto out;
902636
-    }
902636
-
902636
-    bitmap = bdrv_create_dirty_bitmap(bs, granularity, name, errp);
902636
-    if (bitmap == NULL) {
902636
-        goto out;
902636
-    }
902636
-
902636
-    if (disabled) {
902636
-        bdrv_disable_dirty_bitmap(bitmap);
902636
-    }
902636
-
902636
-    bdrv_dirty_bitmap_set_persistence(bitmap, persistent);
902636
-
902636
-out:
902636
-    aio_context_release(aio_context);
902636
-}
902636
-
902636
-BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
902636
-                                           bool release,
902636
-                                           BlockDriverState **bitmap_bs,
902636
-                                           Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *bitmap;
902636
-    AioContext *aio_context;
902636
-
902636
-    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
-    if (!bitmap || !bs) {
902636
-        return NULL;
902636
-    }
902636
-
902636
-    aio_context = bdrv_get_aio_context(bs);
902636
-    aio_context_acquire(aio_context);
902636
-
902636
-    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO,
902636
-                                errp)) {
902636
-        aio_context_release(aio_context);
902636
-        return NULL;
902636
-    }
902636
-
902636
-    if (bdrv_dirty_bitmap_get_persistence(bitmap) &&
902636
-        bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0)
902636
-    {
902636
-        aio_context_release(aio_context);
902636
-        return NULL;
902636
-    }
902636
-
902636
-    if (release) {
902636
-        bdrv_release_dirty_bitmap(bitmap);
902636
-    }
902636
-
902636
-    if (bitmap_bs) {
902636
-        *bitmap_bs = bs;
902636
-    }
902636
-
902636
-    aio_context_release(aio_context);
902636
-    return release ? NULL : bitmap;
902636
-}
902636
-
902636
-void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
902636
-                                   Error **errp)
902636
-{
902636
-    block_dirty_bitmap_remove(node, name, true, NULL, errp);
902636
-}
902636
-
902636
-/**
902636
- * Completely clear a bitmap, for the purposes of synchronizing a bitmap
902636
- * immediately after a full backup operation.
902636
- */
902636
-void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
902636
-                                  Error **errp)
902636
-{
902636
-    BdrvDirtyBitmap *bitmap;
902636
-    BlockDriverState *bs;
902636
-
902636
-    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
-    if (!bitmap || !bs) {
902636
-        return;
902636
-    }
902636
-
902636
-    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, errp)) {
902636
-        return;
902636
-    }
902636
-
902636
-    bdrv_clear_dirty_bitmap(bitmap, NULL);
902636
-}
902636
-
902636
-void qmp_block_dirty_bitmap_enable(const char *node, const char *name,
902636
-                                   Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *bitmap;
902636
-
902636
-    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
-    if (!bitmap) {
902636
-        return;
902636
-    }
902636
-
902636
-    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
902636
-        return;
902636
-    }
902636
-
902636
-    bdrv_enable_dirty_bitmap(bitmap);
902636
-}
902636
-
902636
-void qmp_block_dirty_bitmap_disable(const char *node, const char *name,
902636
-                                    Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *bitmap;
902636
-
902636
-    bitmap = block_dirty_bitmap_lookup(node, name, &bs, errp);
902636
-    if (!bitmap) {
902636
-        return;
902636
-    }
902636
-
902636
-    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_ALLOW_RO, errp)) {
902636
-        return;
902636
-    }
902636
-
902636
-    bdrv_disable_dirty_bitmap(bitmap);
902636
-}
902636
-
902636
-BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target,
902636
-                                          BlockDirtyBitmapMergeSourceList *bms,
902636
-                                          HBitmap **backup, Error **errp)
902636
-{
902636
-    BlockDriverState *bs;
902636
-    BdrvDirtyBitmap *dst, *src, *anon;
902636
-    BlockDirtyBitmapMergeSourceList *lst;
902636
-    Error *local_err = NULL;
902636
-
902636
-    dst = block_dirty_bitmap_lookup(node, target, &bs, errp);
902636
-    if (!dst) {
902636
-        return NULL;
902636
-    }
902636
-
902636
-    anon = bdrv_create_dirty_bitmap(bs, bdrv_dirty_bitmap_granularity(dst),
902636
-                                    NULL, errp);
902636
-    if (!anon) {
902636
-        return NULL;
902636
-    }
902636
-
902636
-    for (lst = bms; lst; lst = lst->next) {
902636
-        switch (lst->value->type) {
902636
-            const char *name, *node;
902636
-        case QTYPE_QSTRING:
902636
-            name = lst->value->u.local;
902636
-            src = bdrv_find_dirty_bitmap(bs, name);
902636
-            if (!src) {
902636
-                error_setg(errp, "Dirty bitmap '%s' not found", name);
902636
-                dst = NULL;
902636
-                goto out;
902636
-            }
902636
-            break;
902636
-        case QTYPE_QDICT:
902636
-            node = lst->value->u.external.node;
902636
-            name = lst->value->u.external.name;
902636
-            src = block_dirty_bitmap_lookup(node, name, NULL, errp);
902636
-            if (!src) {
902636
-                dst = NULL;
902636
-                goto out;
902636
-            }
902636
-            break;
902636
-        default:
902636
-            abort();
902636
-        }
902636
-
902636
-        bdrv_merge_dirty_bitmap(anon, src, NULL, &local_err);
902636
-        if (local_err) {
902636
-            error_propagate(errp, local_err);
902636
-            dst = NULL;
902636
-            goto out;
902636
-        }
902636
-    }
902636
-
902636
-    /* Merge into dst; dst is unchanged on failure. */
902636
-    bdrv_merge_dirty_bitmap(dst, anon, backup, errp);
902636
-
902636
- out:
902636
-    bdrv_release_dirty_bitmap(anon);
902636
-    return dst;
902636
-}
902636
-
902636
-void qmp_block_dirty_bitmap_merge(const char *node, const char *target,
902636
-                                  BlockDirtyBitmapMergeSourceList *bitmaps,
902636
-                                  Error **errp)
902636
-{
902636
-    block_dirty_bitmap_merge(node, target, bitmaps, NULL, errp);
902636
-}
902636
-
902636
 BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *node,
902636
                                                               const char *name,
902636
                                                               Error **errp)
902636
-- 
902636
1.8.3.1
902636