|
|
a41c76 |
From 416b12099e379ec4c19e55a0414a448d140f3dc1 Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <416b12099e379ec4c19e55a0414a448d140f3dc1@dist-git>
|
|
|
a41c76 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Date: Mon, 16 Mar 2020 22:12:16 +0100
|
|
|
a41c76 |
Subject: [PATCH] qemu: block: implement helpers for blockdev-reopen
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
Introduce a set of helpers to call blockdev-reopen in certain scenarios
|
|
|
a41c76 |
|
|
|
a41c76 |
Libvirt will use the QMP command to turn certain members of the backing
|
|
|
a41c76 |
chain read-write for bitmap manipulation and we'll also want to use it
|
|
|
a41c76 |
to replace/install the backing chain of a qcow2 format node.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 96063ce280a398493d7a78a35f674ed25078d849)
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1799013
|
|
|
a41c76 |
Message-Id: <f7b3a9cc523a22b9f1678483b6b8bf302ae7e1cc.1584391727.git.pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/qemu/qemu_block.c | 101 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
a41c76 |
src/qemu/qemu_block.h | 9 ++++
|
|
|
a41c76 |
2 files changed, 110 insertions(+)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
|
|
|
a41c76 |
index 141059ae81..b4da323610 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_block.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_block.c
|
|
|
a41c76 |
@@ -2986,3 +2986,104 @@ qemuBlockBitmapsHandleBlockcopy(virStorageSourcePtr src,
|
|
|
a41c76 |
|
|
|
a41c76 |
return 0;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/**
|
|
|
a41c76 |
+ * qemuBlockReopenFormat:
|
|
|
a41c76 |
+ * @vm: domain object
|
|
|
a41c76 |
+ * @src: storage source to reopen
|
|
|
a41c76 |
+ * @asyncJob: qemu async job type
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * Invokes the 'blockdev-reopen' command on the format layer of @src. This means
|
|
|
a41c76 |
+ * that @src must be already properly configured for the desired outcome. The
|
|
|
a41c76 |
+ * nodenames of @src are used to identify the specific image in qemu.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+qemuBlockReopenFormat(virDomainObjPtr vm,
|
|
|
a41c76 |
+ virStorageSourcePtr src,
|
|
|
a41c76 |
+ qemuDomainAsyncJob asyncJob)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ qemuDomainObjPrivatePtr priv = vm->privateData;
|
|
|
a41c76 |
+ virQEMUDriverPtr driver = priv->driver;
|
|
|
a41c76 |
+ g_autoptr(virJSONValue) reopenprops = NULL;
|
|
|
a41c76 |
+ int rc;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* If we are lacking the object here, qemu might have opened an image with
|
|
|
a41c76 |
+ * a node name unknown to us */
|
|
|
a41c76 |
+ if (!src->backingStore) {
|
|
|
a41c76 |
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
a41c76 |
+ _("can't reopen image with unknown presence of backing store"));
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(reopenprops = qemuBlockStorageSourceGetBlockdevProps(src, src->backingStore)))
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ rc = qemuMonitorBlockdevReopen(priv->mon, &reopenprops);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/**
|
|
|
a41c76 |
+ * qemuBlockReopenReadWrite:
|
|
|
a41c76 |
+ * @vm: domain object
|
|
|
a41c76 |
+ * @src: storage source to reopen
|
|
|
a41c76 |
+ * @asyncJob: qemu async job type
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * Wrapper that reopens @src read-write. We currently depend on qemu
|
|
|
a41c76 |
+ * reopening the storage with 'auto-read-only' enabled for us.
|
|
|
a41c76 |
+ * After successful reopen @src's 'readonly' flag is modified. Does nothing
|
|
|
a41c76 |
+ * if @src is already read-write.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockReopenReadWrite(virDomainObjPtr vm,
|
|
|
a41c76 |
+ virStorageSourcePtr src,
|
|
|
a41c76 |
+ qemuDomainAsyncJob asyncJob)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ if (!src->readonly)
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ src->readonly = false;
|
|
|
a41c76 |
+ if (qemuBlockReopenFormat(vm, src, asyncJob) < 0) {
|
|
|
a41c76 |
+ src->readonly = true;
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/**
|
|
|
a41c76 |
+ * qemuBlockReopenReadOnly:
|
|
|
a41c76 |
+ * @vm: domain object
|
|
|
a41c76 |
+ * @src: storage source to reopen
|
|
|
a41c76 |
+ * @asyncJob: qemu async job type
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * Wrapper that reopens @src read-only. We currently depend on qemu
|
|
|
a41c76 |
+ * reopening the storage with 'auto-read-only' enabled for us.
|
|
|
a41c76 |
+ * After successful reopen @src's 'readonly' flag is modified. Does nothing
|
|
|
a41c76 |
+ * if @src is already read-only.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockReopenReadOnly(virDomainObjPtr vm,
|
|
|
a41c76 |
+ virStorageSourcePtr src,
|
|
|
a41c76 |
+ qemuDomainAsyncJob asyncJob)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ if (src->readonly)
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ src->readonly = true;
|
|
|
a41c76 |
+ if (qemuBlockReopenFormat(vm, src, asyncJob) < 0) {
|
|
|
a41c76 |
+ src->readonly = false;
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return 0;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
|
|
|
a41c76 |
index 197f5dae97..e012052352 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_block.h
|
|
|
a41c76 |
+++ b/src/qemu/qemu_block.h
|
|
|
a41c76 |
@@ -231,3 +231,12 @@ qemuBlockBitmapsHandleBlockcopy(virStorageSourcePtr src,
|
|
|
a41c76 |
virHashTablePtr blockNamedNodeData,
|
|
|
a41c76 |
bool shallow,
|
|
|
a41c76 |
virJSONValuePtr *actions);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockReopenReadWrite(virDomainObjPtr vm,
|
|
|
a41c76 |
+ virStorageSourcePtr src,
|
|
|
a41c76 |
+ qemuDomainAsyncJob asyncJob);
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuBlockReopenReadOnly(virDomainObjPtr vm,
|
|
|
a41c76 |
+ virStorageSourcePtr src,
|
|
|
a41c76 |
+ qemuDomainAsyncJob asyncJob);
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.1
|
|
|
a41c76 |
|