From 8b82355e51021ecd29d3be767f24290fafb4d47f Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Fri, 21 Oct 2016 09:38:18 -0400 Subject: [PATCH] qemu: Introduce qemuDomainGetChardevTLSObjects for hotplug As it turns out more than one place will need these objects, so rather than cut-copy-paste in each, make a helper --- src/qemu/qemu_hotplug.c | 42 ++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 258826c532..8dd48ee491 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1474,6 +1474,32 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, } +static int +qemuDomainGetChardevTLSObjects(virQEMUDriverConfigPtr cfg, + qemuDomainObjPrivatePtr priv, + virDomainChrSourceDefPtr dev, + char *charAlias, + virJSONValuePtr *tlsProps, + char **tlsAlias) +{ + if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP || !cfg->chardevTLS) + return 0; + + if (qemuBuildTLSx509BackendProps(cfg->chardevTLSx509certdir, + dev->data.tcp.listen, + cfg->chardevTLSx509verify, + priv->qemuCaps, + tlsProps) < 0) + return -1; + + if (!(*tlsAlias = qemuAliasTLSObjFromChardevAlias(charAlias))) + return -1; + dev->data.tcp.tlscreds = true; + + return 0; +} + + int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainRedirdevDefPtr redirdev) @@ -1730,19 +1756,9 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, if (qemuDomainChrPreInsert(vmdef, chr) < 0) goto cleanup; - if (dev->type == VIR_DOMAIN_CHR_TYPE_TCP && - cfg->chardevTLS) { - if (qemuBuildTLSx509BackendProps(cfg->chardevTLSx509certdir, - dev->data.tcp.listen, - cfg->chardevTLSx509verify, - priv->qemuCaps, - &tlsProps) < 0) - goto cleanup; - - if (!(tlsAlias = qemuAliasTLSObjFromChardevAlias(charAlias))) - goto cleanup; - dev->data.tcp.tlscreds = true; - } + if (qemuDomainGetChardevTLSObjects(cfg, priv, dev, charAlias, + &tlsProps, &tlsAlias) < 0) + goto cleanup; qemuDomainObjEnterMonitor(driver, vm); if (tlsAlias) {