render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From 71278b86a232d83e0e848b61514b9886e7e2697f Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <71278b86a232d83e0e848b61514b9886e7e2697f@dist-git>
0a7476
From: Laine Stump <laine@laine.org>
0a7476
Date: Thu, 11 Apr 2019 15:14:37 -0400
0a7476
Subject: [PATCH] qemu_hotplug: move qemuDomainChangeGraphicsPasswords()
0a7476
0a7476
It was sitting down in the middle of all the qemuDomainDetach*()
0a7476
functions. Move it up with the rest of the qemuDomain*Graphics*()
0a7476
functions.
0a7476
0a7476
Signed-off-by: Laine Stump <laine@laine.org>
0a7476
ACKed-by: Peter Krempa <pkrempa@redhat.com>
0a7476
(cherry picked from commit 036a4521f3c539c58bb5706b4710db0f1a16eec6)
0a7476
0a7476
Partially-Resolves: https://bugzilla.redhat.com/1658198
0a7476
Signed-off-by: Laine Stump <laine@redhat.com>
0a7476
Signed-off-by: Laine Stump <laine@laine.org>
0a7476
Message-Id: <20190411191453.24055-26-laine@redhat.com>
0a7476
Acked-by: Michal Privoznik <mprivozn@redhat.com>
0a7476
---
0a7476
 src/qemu/qemu_hotplug.c | 151 ++++++++++++++++++++--------------------
0a7476
 1 file changed, 77 insertions(+), 74 deletions(-)
0a7476
0a7476
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
0a7476
index 8a3946a6e2..d80b9b005b 100644
0a7476
--- a/src/qemu/qemu_hotplug.c
0a7476
+++ b/src/qemu/qemu_hotplug.c
0a7476
@@ -3574,6 +3574,83 @@ qemuDomainFindGraphicsIndex(virDomainDefPtr def,
0a7476
     return -1;
0a7476
 }
0a7476
 
0a7476
+
0a7476
+int
0a7476
+qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
0a7476
+                                  virDomainObjPtr vm,
0a7476
+                                  int type,
0a7476
+                                  virDomainGraphicsAuthDefPtr auth,
0a7476
+                                  const char *defaultPasswd,
0a7476
+                                  int asyncJob)
0a7476
+{
0a7476
+    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
+    time_t now = time(NULL);
0a7476
+    const char *expire;
0a7476
+    char *validTo = NULL;
0a7476
+    const char *connected = NULL;
0a7476
+    const char *password;
0a7476
+    int ret = -1;
0a7476
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
0a7476
+
0a7476
+    if (!auth->passwd && !defaultPasswd) {
0a7476
+        ret = 0;
0a7476
+        goto cleanup;
0a7476
+    }
0a7476
+    password = auth->passwd ? auth->passwd : defaultPasswd;
0a7476
+
0a7476
+    if (auth->connected)
0a7476
+        connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
0a7476
+
0a7476
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
0a7476
+        goto cleanup;
0a7476
+    ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
0a7476
+
0a7476
+    if (ret == -2) {
0a7476
+        if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
0a7476
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
0a7476
+                           _("Graphics password only supported for VNC"));
0a7476
+            ret = -1;
0a7476
+        } else {
0a7476
+            ret = qemuMonitorSetVNCPassword(priv->mon, password);
0a7476
+        }
0a7476
+    }
0a7476
+    if (ret != 0)
0a7476
+        goto end_job;
0a7476
+
0a7476
+    if (password[0] == '\0' ||
0a7476
+        (auth->expires && auth->validTo <= now)) {
0a7476
+        expire = "now";
0a7476
+    } else if (auth->expires) {
0a7476
+        if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0)
0a7476
+            goto end_job;
0a7476
+        expire = validTo;
0a7476
+    } else {
0a7476
+        expire = "never";
0a7476
+    }
0a7476
+
0a7476
+    ret = qemuMonitorExpirePassword(priv->mon, type, expire);
0a7476
+
0a7476
+    if (ret == -2) {
0a7476
+        /* XXX we could fake this with a timer */
0a7476
+        if (auth->expires) {
0a7476
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
0a7476
+                           _("Expiry of passwords is not supported"));
0a7476
+            ret = -1;
0a7476
+        } else {
0a7476
+            ret = 0;
0a7476
+        }
0a7476
+    }
0a7476
+
0a7476
+ end_job:
0a7476
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+        ret = -1;
0a7476
+ cleanup:
0a7476
+    VIR_FREE(validTo);
0a7476
+    virObjectUnref(cfg);
0a7476
+    return ret;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 int
0a7476
 qemuDomainChangeGraphics(virQEMUDriverPtr driver,
0a7476
                          virDomainObjPtr vm,
0a7476
@@ -5272,80 +5349,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
0a7476
     return ret;
0a7476
 }
0a7476
 
0a7476
-int
0a7476
-qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
0a7476
-                                  virDomainObjPtr vm,
0a7476
-                                  int type,
0a7476
-                                  virDomainGraphicsAuthDefPtr auth,
0a7476
-                                  const char *defaultPasswd,
0a7476
-                                  int asyncJob)
0a7476
-{
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    time_t now = time(NULL);
0a7476
-    const char *expire;
0a7476
-    char *validTo = NULL;
0a7476
-    const char *connected = NULL;
0a7476
-    const char *password;
0a7476
-    int ret = -1;
0a7476
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
0a7476
-
0a7476
-    if (!auth->passwd && !defaultPasswd) {
0a7476
-        ret = 0;
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    password = auth->passwd ? auth->passwd : defaultPasswd;
0a7476
-
0a7476
-    if (auth->connected)
0a7476
-        connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
0a7476
-
0a7476
-    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
0a7476
-        goto cleanup;
0a7476
-    ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
0a7476
-
0a7476
-    if (ret == -2) {
0a7476
-        if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
0a7476
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
0a7476
-                           _("Graphics password only supported for VNC"));
0a7476
-            ret = -1;
0a7476
-        } else {
0a7476
-            ret = qemuMonitorSetVNCPassword(priv->mon, password);
0a7476
-        }
0a7476
-    }
0a7476
-    if (ret != 0)
0a7476
-        goto end_job;
0a7476
-
0a7476
-    if (password[0] == '\0' ||
0a7476
-        (auth->expires && auth->validTo <= now)) {
0a7476
-        expire = "now";
0a7476
-    } else if (auth->expires) {
0a7476
-        if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0)
0a7476
-            goto end_job;
0a7476
-        expire = validTo;
0a7476
-    } else {
0a7476
-        expire = "never";
0a7476
-    }
0a7476
-
0a7476
-    ret = qemuMonitorExpirePassword(priv->mon, type, expire);
0a7476
-
0a7476
-    if (ret == -2) {
0a7476
-        /* XXX we could fake this with a timer */
0a7476
-        if (auth->expires) {
0a7476
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
0a7476
-                           _("Expiry of passwords is not supported"));
0a7476
-            ret = -1;
0a7476
-        } else {
0a7476
-            ret = 0;
0a7476
-        }
0a7476
-    }
0a7476
-
0a7476
- end_job:
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        ret = -1;
0a7476
- cleanup:
0a7476
-    VIR_FREE(validTo);
0a7476
-    virObjectUnref(cfg);
0a7476
-    return ret;
0a7476
-}
0a7476
 
0a7476
 int qemuDomainAttachLease(virQEMUDriverPtr driver,
0a7476
                           virDomainObjPtr vm,
0a7476
-- 
0a7476
2.21.0
0a7476