Create a qemuDomainAddChardevTLSObjects which will encapsulate the
qemuDomainGetChardevTLSObjects and qemuDomainAddTLSObjects so that
the callers don't need to worry about the props.
Move the dev->type and haveTLS checks in to the Add function to avoid
an unnecessary call to qemuDomainAddTLSObjects
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 80 ++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 37 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index bb90a34..503fb30 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1617,10 +1617,6 @@ qemuDomainGetChardevTLSObjects(virQEMUDriverConfigPtr cfg,
qemuDomainChrSourcePrivatePtr chrSourcePriv =
QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev);
- if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP ||
- dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES)
- return 0;
-
/* Add a secret object in order to access the TLS environment.
* The secinfo will only be created for serial TCP device. */
if (chrSourcePriv && chrSourcePriv->secinfo) {
@@ -1647,6 +1643,43 @@ qemuDomainGetChardevTLSObjects(virQEMUDriverConfigPtr cfg,
}
+static int
+qemuDomainAddChardevTLSObjects(virQEMUDriverPtr driver,
+ virQEMUDriverConfigPtr cfg,
+ virDomainObjPtr vm,
+ virDomainChrSourceDefPtr dev,
+ char *charAlias,
+ char **tlsAlias,
+ char **secAlias)
+{
+ int ret = -1;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ virJSONValuePtr tlsProps = NULL;
+ virJSONValuePtr secProps = NULL;
+
+ if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP ||
+ dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES)
+ return 0;
+
+ if (qemuDomainGetChardevTLSObjects(cfg, priv, dev, charAlias,
+ &tlsProps, tlsAlias,
+ &secProps, secAlias) < 0)
+ goto cleanup;
+
+ if (qemuDomainAddTLSObjects(driver, vm, *secAlias, &secProps,
+ *tlsAlias, &tlsProps) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(tlsProps);
+ virJSONValueFree(secProps);
+
+ return ret;
+}
+
+
int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -1660,8 +1693,6 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
char *charAlias = NULL;
char *devstr = NULL;
bool chardevAdded = false;
- virJSONValuePtr tlsProps = NULL;
- virJSONValuePtr secProps = NULL;
char *tlsAlias = NULL;
char *secAlias = NULL;
bool need_release = false;
@@ -1690,13 +1721,8 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
redirdev->source) < 0)
goto cleanup;
- if (qemuDomainGetChardevTLSObjects(cfg, priv, redirdev->source,
- charAlias, &tlsProps, &tlsAlias,
- &secProps, &secAlias) < 0)
- goto cleanup;
-
- if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
- tlsAlias, &tlsProps) < 0)
+ if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, redirdev->source,
+ charAlias, &tlsAlias, &secAlias) < 0)
goto audit;
qemuDomainObjEnterMonitor(driver, vm);
@@ -1721,9 +1747,7 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
if (ret < 0 && need_release)
qemuDomainReleaseDeviceAddress(vm, &redirdev->info, NULL);
VIR_FREE(tlsAlias);
- virJSONValueFree(tlsProps);
VIR_FREE(secAlias);
- virJSONValueFree(secProps);
VIR_FREE(charAlias);
VIR_FREE(devstr);
virObjectUnref(cfg);
@@ -1919,9 +1943,7 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
bool chardevAttached = false;
bool teardowncgroup = false;
bool teardowndevice = false;
- virJSONValuePtr tlsProps = NULL;
char *tlsAlias = NULL;
- virJSONValuePtr secProps = NULL;
char *secAlias = NULL;
bool need_release = false;
@@ -1960,13 +1982,8 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
dev) < 0)
goto cleanup;
- if (qemuDomainGetChardevTLSObjects(cfg, priv, dev, charAlias,
- &tlsProps, &tlsAlias,
- &secProps, &secAlias) < 0)
- goto cleanup;
-
- if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
- tlsAlias, &tlsProps) < 0)
+ if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, dev, charAlias,
+ &tlsAlias, &secAlias) < 0)
goto audit;
qemuDomainObjEnterMonitor(driver, vm);
@@ -1997,9 +2014,7 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
VIR_WARN("Unable to remove chr device from /dev");
}
VIR_FREE(tlsAlias);
- virJSONValueFree(tlsProps);
VIR_FREE(secAlias);
- virJSONValueFree(secProps);
VIR_FREE(charAlias);
VIR_FREE(devstr);
virObjectUnref(cfg);
@@ -2042,8 +2057,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
bool chardevAdded = false;
bool objAdded = false;
virJSONValuePtr props = NULL;
- virJSONValuePtr tlsProps = NULL;
- virJSONValuePtr secProps = NULL;
virDomainCCWAddressSetPtr ccwaddrs = NULL;
const char *type;
int ret = -1;
@@ -2111,13 +2124,8 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
rng->source.chardev) < 0)
goto cleanup;
- if (qemuDomainGetChardevTLSObjects(cfg, priv, rng->source.chardev,
- charAlias, &tlsProps, &tlsAlias,
- &secProps, &secAlias) < 0)
- goto cleanup;
-
- if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
- tlsAlias, &tlsProps) < 0)
+ if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, rng->source.chardev,
+ charAlias, &tlsAlias, &secAlias) <
0)
goto audit;
}
@@ -2150,8 +2158,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
audit:
virDomainAuditRNG(vm, NULL, rng, "attach", ret == 0);
cleanup:
- virJSONValueFree(tlsProps);
- virJSONValueFree(secProps);
virJSONValueFree(props);
if (ret < 0) {
if (releaseaddr)
--
2.9.3