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