mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
qemu: Refactor qemuDomainGetChardevTLSObjects to converge code
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@redhat.com>
This commit is contained in:
parent
ee4f382a9c
commit
479b045b54
@ -1620,10 +1620,6 @@ qemuDomainGetChardevTLSObjects(virQEMUDriverConfigPtr cfg,
|
|||||||
qemuDomainChrSourcePrivatePtr chrSourcePriv =
|
qemuDomainChrSourcePrivatePtr chrSourcePriv =
|
||||||
QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev);
|
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.
|
/* Add a secret object in order to access the TLS environment.
|
||||||
* The secinfo will only be created for serial TCP device. */
|
* The secinfo will only be created for serial TCP device. */
|
||||||
if (chrSourcePriv && chrSourcePriv->secinfo) {
|
if (chrSourcePriv && chrSourcePriv->secinfo) {
|
||||||
@ -1650,6 +1646,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,
|
int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
|
||||||
virQEMUDriverPtr driver,
|
virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -1663,8 +1696,6 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
|
|||||||
char *charAlias = NULL;
|
char *charAlias = NULL;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
bool chardevAdded = false;
|
bool chardevAdded = false;
|
||||||
virJSONValuePtr tlsProps = NULL;
|
|
||||||
virJSONValuePtr secProps = NULL;
|
|
||||||
char *tlsAlias = NULL;
|
char *tlsAlias = NULL;
|
||||||
char *secAlias = NULL;
|
char *secAlias = NULL;
|
||||||
bool need_release = false;
|
bool need_release = false;
|
||||||
@ -1693,13 +1724,8 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
|
|||||||
redirdev->source) < 0)
|
redirdev->source) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainGetChardevTLSObjects(cfg, priv, redirdev->source,
|
if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, redirdev->source,
|
||||||
charAlias, &tlsProps, &tlsAlias,
|
charAlias, &tlsAlias, &secAlias) < 0)
|
||||||
&secProps, &secAlias) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
|
|
||||||
tlsAlias, &tlsProps) < 0)
|
|
||||||
goto audit;
|
goto audit;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
@ -1724,9 +1750,7 @@ int qemuDomainAttachRedirdevDevice(virConnectPtr conn,
|
|||||||
if (ret < 0 && need_release)
|
if (ret < 0 && need_release)
|
||||||
qemuDomainReleaseDeviceAddress(vm, &redirdev->info, NULL);
|
qemuDomainReleaseDeviceAddress(vm, &redirdev->info, NULL);
|
||||||
VIR_FREE(tlsAlias);
|
VIR_FREE(tlsAlias);
|
||||||
virJSONValueFree(tlsProps);
|
|
||||||
VIR_FREE(secAlias);
|
VIR_FREE(secAlias);
|
||||||
virJSONValueFree(secProps);
|
|
||||||
VIR_FREE(charAlias);
|
VIR_FREE(charAlias);
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
@ -1922,9 +1946,7 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
|
|||||||
bool chardevAttached = false;
|
bool chardevAttached = false;
|
||||||
bool teardowncgroup = false;
|
bool teardowncgroup = false;
|
||||||
bool teardowndevice = false;
|
bool teardowndevice = false;
|
||||||
virJSONValuePtr tlsProps = NULL;
|
|
||||||
char *tlsAlias = NULL;
|
char *tlsAlias = NULL;
|
||||||
virJSONValuePtr secProps = NULL;
|
|
||||||
char *secAlias = NULL;
|
char *secAlias = NULL;
|
||||||
bool need_release = false;
|
bool need_release = false;
|
||||||
|
|
||||||
@ -1963,13 +1985,8 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
|
|||||||
dev) < 0)
|
dev) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainGetChardevTLSObjects(cfg, priv, dev, charAlias,
|
if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, dev, charAlias,
|
||||||
&tlsProps, &tlsAlias,
|
&tlsAlias, &secAlias) < 0)
|
||||||
&secProps, &secAlias) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
|
|
||||||
tlsAlias, &tlsProps) < 0)
|
|
||||||
goto audit;
|
goto audit;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
@ -2000,9 +2017,7 @@ int qemuDomainAttachChrDevice(virConnectPtr conn,
|
|||||||
VIR_WARN("Unable to remove chr device from /dev");
|
VIR_WARN("Unable to remove chr device from /dev");
|
||||||
}
|
}
|
||||||
VIR_FREE(tlsAlias);
|
VIR_FREE(tlsAlias);
|
||||||
virJSONValueFree(tlsProps);
|
|
||||||
VIR_FREE(secAlias);
|
VIR_FREE(secAlias);
|
||||||
virJSONValueFree(secProps);
|
|
||||||
VIR_FREE(charAlias);
|
VIR_FREE(charAlias);
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
@ -2045,8 +2060,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
|
|||||||
bool chardevAdded = false;
|
bool chardevAdded = false;
|
||||||
bool objAdded = false;
|
bool objAdded = false;
|
||||||
virJSONValuePtr props = NULL;
|
virJSONValuePtr props = NULL;
|
||||||
virJSONValuePtr tlsProps = NULL;
|
|
||||||
virJSONValuePtr secProps = NULL;
|
|
||||||
virDomainCCWAddressSetPtr ccwaddrs = NULL;
|
virDomainCCWAddressSetPtr ccwaddrs = NULL;
|
||||||
const char *type;
|
const char *type;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -2114,13 +2127,8 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
|
|||||||
rng->source.chardev) < 0)
|
rng->source.chardev) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainGetChardevTLSObjects(cfg, priv, rng->source.chardev,
|
if (qemuDomainAddChardevTLSObjects(driver, cfg, vm, rng->source.chardev,
|
||||||
charAlias, &tlsProps, &tlsAlias,
|
charAlias, &tlsAlias, &secAlias) < 0)
|
||||||
&secProps, &secAlias) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (qemuDomainAddTLSObjects(driver, vm, secAlias, &secProps,
|
|
||||||
tlsAlias, &tlsProps) < 0)
|
|
||||||
goto audit;
|
goto audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2153,8 +2161,6 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
|
|||||||
audit:
|
audit:
|
||||||
virDomainAuditRNG(vm, NULL, rng, "attach", ret == 0);
|
virDomainAuditRNG(vm, NULL, rng, "attach", ret == 0);
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(tlsProps);
|
|
||||||
virJSONValueFree(secProps);
|
|
||||||
virJSONValueFree(props);
|
virJSONValueFree(props);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (releaseaddr)
|
if (releaseaddr)
|
||||||
|
Loading…
Reference in New Issue
Block a user