[PATCH v2 3/3] qemu: always generate the same alias for tls-creds-x509 object

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

 



There was inconsistency between alias used to create tls-creds-x509
object and alias used to link that object to chardev while hotpluging.
Hotplug ends with this error:

  error: Failed to detach device from channel-tcp.xml
  error: internal error: unable to execute QEMU command 'chardev-add':
  No TLS credentials with id 'objcharchannel3_tls0'

In XML we have for example alias "serial0", but on qemu command line we
generate "charserial0".

The issue was that code, that creates QMP command to hotplug chardev
devices uses only the second alias "charserial0" and that alias is also
used to link the tls-creds-x509 object.

This patch unifies the aliases for tls-creds-x509 to be always generated
from "charserial0".

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                                          | 4 ++--
 src/qemu/qemu_hotplug.c                                          | 9 +++++++--
 .../qemuxml2argv-serial-tcp-tlsx509-chardev-verify.args          | 4 ++--
 .../qemuxml2argv-serial-tcp-tlsx509-chardev.args                 | 4 ++--
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 848937c..8282162 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4949,10 +4949,10 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
             if (qemuBuildTLSx509CommandLine(cmd, cfg->chardevTLSx509certdir,
                                             dev->data.tcp.listen,
                                             cfg->chardevTLSx509verify,
-                                            alias, qemuCaps) < 0)
+                                            charAlias, qemuCaps) < 0)
                 goto error;
 
-            if (!(objalias = qemuAliasTLSObjFromChardevAlias(alias)))
+            if (!(objalias = qemuAliasTLSObjFromChardevAlias(charAlias)))
                 goto error;
             virBufferAsprintf(&buf, ",tls-creds=%s", objalias);
             VIR_FREE(objalias);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index af87581..2cb2267 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1738,7 +1738,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
                                          &tlsProps) < 0)
             goto cleanup;
 
-        if (!(tlsAlias = qemuAliasTLSObjFromChardevAlias(chr->info.alias)))
+        if (!(tlsAlias = qemuAliasTLSObjFromChardevAlias(charAlias)))
             goto cleanup;
         dev->data.tcp.tlscreds = true;
     }
@@ -4387,6 +4387,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
     virDomainChrDefPtr tmpChr;
     char *objAlias = NULL;
     char *devstr = NULL;
+    char *charAlias = NULL;
 
     if (!(tmpChr = virDomainChrFind(vmdef, chr))) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -4399,9 +4400,12 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
 
     sa_assert(tmpChr->info.alias);
 
+    if (!(charAlias = qemuAliasChardevFromDevAlias(tmpChr->info.alias)))
+        goto cleanup;
+
     if (tmpChr->source.type == VIR_DOMAIN_CHR_TYPE_TCP &&
         cfg->chardevTLS &&
-        !(objAlias = qemuAliasTLSObjFromChardevAlias(tmpChr->info.alias)))
+        !(objAlias = qemuAliasTLSObjFromChardevAlias(charAlias)))
         goto cleanup;
 
     if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
@@ -4427,6 +4431,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
  cleanup:
     qemuDomainResetDeviceRemoval(vm);
     VIR_FREE(devstr);
+    VIR_FREE(charAlias);
     virObjectUnref(cfg);
     return ret;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev-verify.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev-verify.args
index f521e33..003d11d 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev-verify.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev-verify.args
@@ -25,9 +25,9 @@ server,nowait \
 -chardev udp,id=charserial0,host=127.0.0.1,port=2222,localaddr=127.0.0.1,\
 localport=1111 \
 -device isa-serial,chardev=charserial0,id=serial0 \
--object tls-creds-x509,id=objserial1_tls0,dir=/etc/pki/libvirt-chardev,\
+-object tls-creds-x509,id=objcharserial1_tls0,dir=/etc/pki/libvirt-chardev,\
 endpoint=client,verify-peer=yes \
 -chardev socket,id=charserial1,host=127.0.0.1,port=5555,\
-tls-creds=objserial1_tls0 \
+tls-creds=objcharserial1_tls0 \
 -device isa-serial,chardev=charserial1,id=serial1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev.args
index 4c8c23e..b456cce 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-tlsx509-chardev.args
@@ -25,9 +25,9 @@ server,nowait \
 -chardev udp,id=charserial0,host=127.0.0.1,port=2222,localaddr=127.0.0.1,\
 localport=1111 \
 -device isa-serial,chardev=charserial0,id=serial0 \
--object tls-creds-x509,id=objserial1_tls0,dir=/etc/pki/libvirt-chardev,\
+-object tls-creds-x509,id=objcharserial1_tls0,dir=/etc/pki/libvirt-chardev,\
 endpoint=client,verify-peer=no \
 -chardev socket,id=charserial1,host=127.0.0.1,port=5555,\
-tls-creds=objserial1_tls0 \
+tls-creds=objcharserial1_tls0 \
 -device isa-serial,chardev=charserial1,id=serial1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
-- 
2.10.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]