Blob Blame History Raw
From 71278b86a232d83e0e848b61514b9886e7e2697f Mon Sep 17 00:00:00 2001
Message-Id: <71278b86a232d83e0e848b61514b9886e7e2697f@dist-git>
From: Laine Stump <laine@laine.org>
Date: Thu, 11 Apr 2019 15:14:37 -0400
Subject: [PATCH] qemu_hotplug: move qemuDomainChangeGraphicsPasswords()

It was sitting down in the middle of all the qemuDomainDetach*()
functions. Move it up with the rest of the qemuDomain*Graphics*()
functions.

Signed-off-by: Laine Stump <laine@laine.org>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit 036a4521f3c539c58bb5706b4710db0f1a16eec6)

Partially-Resolves: https://bugzilla.redhat.com/1658198
Signed-off-by: Laine Stump <laine@redhat.com>
Signed-off-by: Laine Stump <laine@laine.org>
Message-Id: <20190411191453.24055-26-laine@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_hotplug.c | 151 ++++++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 74 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8a3946a6e2..d80b9b005b 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3574,6 +3574,83 @@ qemuDomainFindGraphicsIndex(virDomainDefPtr def,
     return -1;
 }
 
+
+int
+qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
+                                  virDomainObjPtr vm,
+                                  int type,
+                                  virDomainGraphicsAuthDefPtr auth,
+                                  const char *defaultPasswd,
+                                  int asyncJob)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    time_t now = time(NULL);
+    const char *expire;
+    char *validTo = NULL;
+    const char *connected = NULL;
+    const char *password;
+    int ret = -1;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+    if (!auth->passwd && !defaultPasswd) {
+        ret = 0;
+        goto cleanup;
+    }
+    password = auth->passwd ? auth->passwd : defaultPasswd;
+
+    if (auth->connected)
+        connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
+
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+        goto cleanup;
+    ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
+
+    if (ret == -2) {
+        if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Graphics password only supported for VNC"));
+            ret = -1;
+        } else {
+            ret = qemuMonitorSetVNCPassword(priv->mon, password);
+        }
+    }
+    if (ret != 0)
+        goto end_job;
+
+    if (password[0] == '\0' ||
+        (auth->expires && auth->validTo <= now)) {
+        expire = "now";
+    } else if (auth->expires) {
+        if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0)
+            goto end_job;
+        expire = validTo;
+    } else {
+        expire = "never";
+    }
+
+    ret = qemuMonitorExpirePassword(priv->mon, type, expire);
+
+    if (ret == -2) {
+        /* XXX we could fake this with a timer */
+        if (auth->expires) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Expiry of passwords is not supported"));
+            ret = -1;
+        } else {
+            ret = 0;
+        }
+    }
+
+ end_job:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        ret = -1;
+ cleanup:
+    VIR_FREE(validTo);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+
 int
 qemuDomainChangeGraphics(virQEMUDriverPtr driver,
                          virDomainObjPtr vm,
@@ -5272,80 +5349,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
     return ret;
 }
 
-int
-qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
-                                  virDomainObjPtr vm,
-                                  int type,
-                                  virDomainGraphicsAuthDefPtr auth,
-                                  const char *defaultPasswd,
-                                  int asyncJob)
-{
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-    time_t now = time(NULL);
-    const char *expire;
-    char *validTo = NULL;
-    const char *connected = NULL;
-    const char *password;
-    int ret = -1;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-
-    if (!auth->passwd && !defaultPasswd) {
-        ret = 0;
-        goto cleanup;
-    }
-    password = auth->passwd ? auth->passwd : defaultPasswd;
-
-    if (auth->connected)
-        connected = virDomainGraphicsAuthConnectedTypeToString(auth->connected);
-
-    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-        goto cleanup;
-    ret = qemuMonitorSetPassword(priv->mon, type, password, connected);
-
-    if (ret == -2) {
-        if (type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Graphics password only supported for VNC"));
-            ret = -1;
-        } else {
-            ret = qemuMonitorSetVNCPassword(priv->mon, password);
-        }
-    }
-    if (ret != 0)
-        goto end_job;
-
-    if (password[0] == '\0' ||
-        (auth->expires && auth->validTo <= now)) {
-        expire = "now";
-    } else if (auth->expires) {
-        if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0)
-            goto end_job;
-        expire = validTo;
-    } else {
-        expire = "never";
-    }
-
-    ret = qemuMonitorExpirePassword(priv->mon, type, expire);
-
-    if (ret == -2) {
-        /* XXX we could fake this with a timer */
-        if (auth->expires) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("Expiry of passwords is not supported"));
-            ret = -1;
-        } else {
-            ret = 0;
-        }
-    }
-
- end_job:
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
-        ret = -1;
- cleanup:
-    VIR_FREE(validTo);
-    virObjectUnref(cfg);
-    return ret;
-}
 
 int qemuDomainAttachLease(virQEMUDriverPtr driver,
                           virDomainObjPtr vm,
-- 
2.21.0