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