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

[libvirt] [PATCH v2 07/14] qemu: Move qemuDomainPrepareChardevSourceTLS call



Move the call to inside the qemuDomainAddChardevTLSObjects in order to
further converge the code.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/qemu/qemu_hotplug.c | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b59f3ab..d7a1f1f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1646,7 +1646,6 @@ qemuDomainGetChardevTLSObjects(virQEMUDriverConfigPtr cfg,
 static int
 qemuDomainAddChardevTLSObjects(virConnectPtr conn,
                                virQEMUDriverPtr driver,
-                               virQEMUDriverConfigPtr cfg,
                                virDomainObjPtr vm,
                                virDomainChrSourceDefPtr dev,
                                char *devAlias,
@@ -1655,13 +1654,19 @@ qemuDomainAddChardevTLSObjects(virConnectPtr conn,
                                char **secAlias)
 {
     int ret = -1;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virJSONValuePtr tlsProps = NULL;
     virJSONValuePtr secProps = NULL;
 
+    /* NB: This may alter haveTLS based on cfg */
+    qemuDomainPrepareChardevSourceTLS(dev, cfg);
+
     if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP ||
-        dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES)
-        return 0;
+        dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES) {
+        ret = 0;
+        goto cleanup;
+    }
 
     if (qemuDomainSecretChardevPrepare(conn, cfg, priv, devAlias, dev) < 0)
         goto cleanup;
@@ -1680,6 +1685,7 @@ qemuDomainAddChardevTLSObjects(virConnectPtr conn,
  cleanup:
     virJSONValueFree(tlsProps);
     virJSONValueFree(secProps);
+    virObjectUnref(cfg);
 
     return ret;
 }
@@ -1692,7 +1698,6 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
 {
     int ret = -1;
     int rc;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDefPtr def = vm->def;
     char *charAlias = NULL;
@@ -1703,8 +1708,6 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
     bool need_release = false;
     virErrorPtr orig_err;
 
-    qemuDomainPrepareChardevSourceTLS(redirdev->source, cfg);
-
     if (qemuAssignDeviceRedirdevAlias(def, redirdev, -1) < 0)
         goto cleanup;
 
@@ -1722,7 +1725,7 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
     if (VIR_REALLOC_N(def->redirdevs, def->nredirdevs+1) < 0)
         goto cleanup;
 
-    if (qemuDomainAddChardevTLSObjects(conn, driver, cfg, vm, redirdev->source,
+    if (qemuDomainAddChardevTLSObjects(conn, driver, vm, redirdev->source,
                                        redirdev->info.alias, charAlias,
                                        &tlsAlias, &secAlias) < 0)
         goto audit;
@@ -1752,7 +1755,6 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
     VIR_FREE(secAlias);
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
-    virObjectUnref(cfg);
     return ret;
 
  exit_monitor:
@@ -1935,7 +1937,6 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
                               virDomainChrDefPtr chr)
 {
     int ret = -1, rc;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virErrorPtr orig_err;
     virDomainDefPtr vmdef = vm->def;
@@ -1953,8 +1954,6 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
         qemuDomainPrepareChannel(chr, priv->channelTargetDir) < 0)
         goto cleanup;
 
-    qemuDomainPrepareChardevSourceTLS(dev, cfg);
-
     if (qemuAssignDeviceChrAlias(vmdef, chr, -1) < 0)
         goto cleanup;
 
@@ -1980,7 +1979,7 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
     if (qemuDomainChrPreInsert(vmdef, chr) < 0)
         goto cleanup;
 
-    if (qemuDomainAddChardevTLSObjects(conn, driver, cfg, vm, dev,
+    if (qemuDomainAddChardevTLSObjects(conn, driver, vm, dev,
                                        chr->info.alias, charAlias,
                                        &tlsAlias, &secAlias) < 0)
         goto audit;
@@ -2016,7 +2015,6 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
     VIR_FREE(secAlias);
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
-    virObjectUnref(cfg);
     return ret;
 
  exit_monitor:
@@ -2041,7 +2039,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
                           virDomainObjPtr vm,
                           virDomainRNGDefPtr rng)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
     virErrorPtr orig_err;
@@ -2102,9 +2099,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
         goto cleanup;
     teardowncgroup = true;
 
-    if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD)
-        qemuDomainPrepareChardevSourceTLS(rng->source.chardev, cfg);
-
     /* build required metadata */
     if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps)))
         goto cleanup;
@@ -2119,7 +2113,7 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
         goto cleanup;
 
     if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD) {
-        if (qemuDomainAddChardevTLSObjects(conn, driver, cfg, vm,
+        if (qemuDomainAddChardevTLSObjects(conn, driver, vm,
                                            rng->source.chardev,
                                            rng->info.alias, charAlias,
                                            &tlsAlias, &secAlias) < 0)
@@ -2171,7 +2165,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
     VIR_FREE(objAlias);
     VIR_FREE(devstr);
     virDomainCCWAddressSetFree(ccwaddrs);
-    virObjectUnref(cfg);
     return ret;
 
  exit_monitor:
-- 
2.9.3


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