[PATCH 05/14] qemu: Generate alias for pr-helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



While we're not generating the command line just yet (look for
the next commit), we can generate the alias for pr-manager.
A domain can have up to one managed pr-manager (in which case
socket path is decided by libvirt and pr-helper is spawned by
libvirt too), but up to ndisks of unmanaged ones (one per disk
basically). In case of the former we can generate a simple alias
and be sure it'll not conflict. But in case of the latter to
avoid any conflicts let's generate alias that's based on
something unique - like disk target.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  3 +++
 2 files changed, 64 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7fa8c93b7..e8d2adf56 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -972,6 +972,8 @@ qemuDomainStorageSourcePrivateDispose(void *obj)
 
     qemuDomainSecretInfoFree(&priv->secinfo);
     qemuDomainSecretInfoFree(&priv->encinfo);
+
+    VIR_FREE(priv->prAlias);
 }
 
 
@@ -11037,6 +11039,62 @@ qemuDomainDiskPRObjectKillAll(qemuDomainObjPrivatePtr priv)
 }
 
 
+static int
+qemuDomainPrepareDiskPR(qemuDomainObjPrivatePtr priv,
+                        virDomainDiskDefPtr disk)
+{
+    qemuDomainStorageSourcePrivatePtr srcPriv;
+    virStoragePRDefPtr prd = disk->src->pr;
+    char *prPath = NULL;
+    bool managed;
+    int ret = -1;
+
+    if (!prd ||
+        prd->enabled != VIR_TRISTATE_BOOL_YES)
+        return 0;
+
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PR_MANAGER_HELPER)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("reservations not supported with this QEMU binary"));
+        goto cleanup;
+    }
+
+    if (!disk->src->privateData &&
+        !(disk->src->privateData = qemuDomainStorageSourcePrivateNew()))
+        return -1;
+
+    srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
+    managed = prd->managed == VIR_TRISTATE_BOOL_YES;
+
+    if (managed) {
+        /* Generate PR helper socket path & alias that are same
+         * for each disk in the domain. */
+
+        if (VIR_STRDUP(srcPriv->prAlias, "pr-helper0") < 0)
+            return -1;
+
+        if (virAsprintf(&prPath, "%s/pr-helper0.sock", priv->libDir) < 0)
+            return -1;
+
+    } else {
+        if (virAsprintf(&srcPriv->prAlias, "pr-helper-%s", disk->dst) < 0)
+            return -1;
+
+        if (VIR_STRDUP(prPath, prd->path) < 0)
+            return -1;
+    }
+
+    if (qemuDomainDiskPRObjectRegister(priv, srcPriv->prAlias,
+                                       managed, &prPath) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(prPath);
+    return ret;
+}
+
+
 int
 qemuDomainPrepareDiskSource(virConnectPtr conn,
                             virDomainDiskDefPtr disk,
@@ -11049,6 +11107,9 @@ qemuDomainPrepareDiskSource(virConnectPtr conn,
     if (qemuDomainSecretDiskPrepare(conn, priv, disk) < 0)
         return -1;
 
+    if (qemuDomainPrepareDiskPR(priv, disk) < 0)
+        return -1;
+
     if (disk->src->type == VIR_STORAGE_TYPE_NETWORK &&
         disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_GLUSTER_DEBUG_LEVEL)) {
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f741f3039..5fdb5b931 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -375,6 +375,9 @@ struct _qemuDomainStorageSourcePrivate {
 
     /* data required for decryption of encrypted storage source */
     qemuDomainSecretInfoPtr encinfo;
+
+    /* alias for pr-manager-helper */
+    char *prAlias;
 };
 
 virObjectPtr qemuDomainStorageSourcePrivateNew(void);
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux