|
|
a41c76 |
From 0890cd78e9391625a591a7a9327601ee79ba6636 Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <0890cd78e9391625a591a7a9327601ee79ba6636@dist-git>
|
|
|
a41c76 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Date: Tue, 4 Feb 2020 15:08:25 +0100
|
|
|
a41c76 |
Subject: [PATCH] qemu: block: Introduce function to calculate bitmap handling
|
|
|
a41c76 |
for block-copy
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
Add a function calculating which bitmaps to copy to the mirror during
|
|
|
a41c76 |
a block-copy operation.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 26f07f68707e16bef3d48e1c0b138791ab5df346)
|
|
|
a41c76 |
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1207659
|
|
|
a41c76 |
Message-Id: <6d4bd72b975f9f690cb34784ed22bb5fad6bbf2c.1580824112.git.pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/qemu/qemu_block.c | 138 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
a41c76 |
src/qemu/qemu_block.h | 7 +++
|
|
|
a41c76 |
2 files changed, 145 insertions(+)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
|
|
|
a41c76 |
index b19290e677..63116ef5f2 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_block.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_block.c
|
|
|
a41c76 |
@@ -2728,3 +2728,141 @@ qemuBlockBitmapChainIsValid(virStorageSourcePtr src,
|
|
|
a41c76 |
|
|
|
a41c76 |
return chain_started;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+struct qemuBlockBitmapsHandleBlockcopyConcatData {
|
|
|
a41c76 |
+ virHashTablePtr bitmaps_merge;
|
|
|
a41c76 |
+ virJSONValuePtr actions;
|
|
|
a41c76 |
+ const char *mirrornodeformat;
|
|
|
a41c76 |
+ bool has_bitmaps;
|
|
|
a41c76 |
+};
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+qemuBlockBitmapsHandleBlockcopyConcatActions(void *payload,
|
|
|
a41c76 |
+ const void *name,
|
|
|
a41c76 |
+ void *opaque)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ struct qemuBlockBitmapsHandleBlockcopyConcatData *data = opaque;
|
|
|
a41c76 |
+ virJSONValuePtr createactions = payload;
|
|
|
a41c76 |
+ const char *bitmapname = name;
|
|
|
a41c76 |
+ g_autoptr(virJSONValue) mergebitmaps = virHashSteal(data->bitmaps_merge, bitmapname);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ data->has_bitmaps = true;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virJSONValueArrayConcat(data->actions, createactions);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuMonitorTransactionBitmapMerge(data->actions,
|
|
|
a41c76 |
+ data->mirrornodeformat,
|
|
|
a41c76 |
+ bitmapname,
|
|
|
a41c76 |
+ &mergebitmaps) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/**
|
|
|
a41c76 |
+ * qemuBlockBitmapsHandleBlockcopy:
|
|
|
a41c76 |
+ * @src: disk source
|
|
|
a41c76 |
+ * @mirror: mirror source
|
|
|
a41c76 |
+ * @blockNamedNodeData: hash table containing data about bitmaps
|
|
|
a41c76 |
+ * @shallow: whether shallow copy is requested
|
|
|
a41c76 |
+ * @actions: filled with arguments for a 'transaction' command
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * Calculates which bitmaps to copy and merge during a virDomainBlockCopy job.
|
|
|
a41c76 |
+ * This is designed to be called when the job is already synchronised as it
|
|
|
a41c76 |
+ * may result in active bitmaps being created.
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * Returns 0 on success and -1 on error. If @actions is NULL when 0 is returned
|
|
|
a41c76 |
+ * there are no actions to perform for the given job.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockBitmapsHandleBlockcopy(virStorageSourcePtr src,
|
|
|
a41c76 |
+ virStorageSourcePtr mirror,
|
|
|
a41c76 |
+ virHashTablePtr blockNamedNodeData,
|
|
|
a41c76 |
+ bool shallow,
|
|
|
a41c76 |
+ virJSONValuePtr *actions)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autoptr(virHashTable) bitmaps = virHashNew(virJSONValueHashFree);
|
|
|
a41c76 |
+ g_autoptr(virHashTable) bitmaps_merge = virHashNew(virJSONValueHashFree);
|
|
|
a41c76 |
+ g_autoptr(virHashTable) bitmaps_skip = virHashNew(NULL);
|
|
|
a41c76 |
+ g_autoptr(virJSONValue) tmpactions = virJSONValueNewArray();
|
|
|
a41c76 |
+ qemuBlockNamedNodeDataPtr entry;
|
|
|
a41c76 |
+ virStorageSourcePtr n;
|
|
|
a41c76 |
+ size_t i;
|
|
|
a41c76 |
+ struct qemuBlockBitmapsHandleBlockcopyConcatData data = { .bitmaps_merge = bitmaps_merge,
|
|
|
a41c76 |
+ .actions = tmpactions,
|
|
|
a41c76 |
+ .mirrornodeformat = mirror->nodeformat,
|
|
|
a41c76 |
+ .has_bitmaps = false, };
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (n = src; n; n = n->backingStore) {
|
|
|
a41c76 |
+ if (!(entry = virHashLookup(blockNamedNodeData, n->nodeformat)))
|
|
|
a41c76 |
+ continue;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < entry->nbitmaps; i++) {
|
|
|
a41c76 |
+ qemuBlockNamedNodeDataBitmapPtr bitmap = entry->bitmaps[i];
|
|
|
a41c76 |
+ virJSONValuePtr bitmap_merge;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virHashHasEntry(bitmaps_skip, bitmap->name))
|
|
|
a41c76 |
+ continue;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(bitmap_merge = virHashLookup(bitmaps_merge, bitmap->name))) {
|
|
|
a41c76 |
+ g_autoptr(virJSONValue) tmp = NULL;
|
|
|
a41c76 |
+ bool disabled = !bitmap->recording;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* disable any non top-layer bitmaps */
|
|
|
a41c76 |
+ if (n != src)
|
|
|
a41c76 |
+ disabled = true;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!bitmap->persistent ||
|
|
|
a41c76 |
+ !(qemuBlockBitmapChainIsValid(n, bitmap->name,
|
|
|
a41c76 |
+ blockNamedNodeData))) {
|
|
|
a41c76 |
+ ignore_value(virHashAddEntry(bitmaps_skip, bitmap->name, NULL));
|
|
|
a41c76 |
+ continue;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* prepare the data for adding the bitmap to the mirror */
|
|
|
a41c76 |
+ tmp = virJSONValueNewArray();
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuMonitorTransactionBitmapAdd(tmp,
|
|
|
a41c76 |
+ mirror->nodeformat,
|
|
|
a41c76 |
+ bitmap->name,
|
|
|
a41c76 |
+ true,
|
|
|
a41c76 |
+ disabled,
|
|
|
a41c76 |
+ bitmap->granularity) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virHashAddEntry(bitmaps, bitmap->name, tmp) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ tmp = NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* prepare array for merging all the bitmaps from the original chain */
|
|
|
a41c76 |
+ tmp = virJSONValueNewArray();
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virHashAddEntry(bitmaps_merge, bitmap->name, tmp) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ bitmap_merge = g_steal_pointer(&tmp);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(bitmap_merge,
|
|
|
a41c76 |
+ n->nodeformat,
|
|
|
a41c76 |
+ bitmap->name) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (shallow)
|
|
|
a41c76 |
+ break;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virHashForEach(bitmaps, qemuBlockBitmapsHandleBlockcopyConcatActions,
|
|
|
a41c76 |
+ &data) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (data.has_bitmaps)
|
|
|
a41c76 |
+ *actions = g_steal_pointer(&tmpactions);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
|
|
|
a41c76 |
index cf51b9bf4e..a816190bb7 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_block.h
|
|
|
a41c76 |
+++ b/src/qemu/qemu_block.h
|
|
|
a41c76 |
@@ -217,3 +217,10 @@ bool
|
|
|
a41c76 |
qemuBlockBitmapChainIsValid(virStorageSourcePtr src,
|
|
|
a41c76 |
const char *bitmapname,
|
|
|
a41c76 |
virHashTablePtr blockNamedNodeData);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockBitmapsHandleBlockcopy(virStorageSourcePtr src,
|
|
|
a41c76 |
+ virStorageSourcePtr mirror,
|
|
|
a41c76 |
+ virHashTablePtr blockNamedNodeData,
|
|
|
a41c76 |
+ bool shallow,
|
|
|
a41c76 |
+ virJSONValuePtr *actions);
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.0
|
|
|
a41c76 |
|