[libvirt] [PATCH v3 3/4] qemuDomainAttachChrDevice: Fix chardev hotplug

Michal Privoznik mprivozn at redhat.com
Thu May 14 08:33:05 UTC 2015


Not every chardev is plugged onto virtio-serial bus. However, the
code introduced in 89e991a2aa36b04 assumes that. Incorrectly.
With previous patches we have three options where a chardev can
be plugged: virtio-serial, USB and PCI. This commit fixes the
attach part.  However, since we are not auto allocating USB
addresses yet, I'm just marking the place where appropriate code
should go.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_hotplug.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index fc45de1..a7fac98 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1556,11 +1556,18 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
         chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO)
         allowZero = true;
 
-    if (virDomainVirtioSerialAddrAutoAssign(NULL,
-                                            priv->vioserialaddrs,
-                                            &chr->info,
-                                            allowZero) < 0)
-        goto cleanup;
+    if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI) {
+        if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &chr->info) < 0)
+            goto cleanup;
+    } else if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) {
+        /* XXX */
+    } else {
+        if (virDomainVirtioSerialAddrAutoAssign(NULL,
+                                                priv->vioserialaddrs,
+                                                &chr->info,
+                                                allowZero) < 0)
+            goto cleanup;
+    }
     need_release = true;
 
     if (qemuBuildChrDeviceStr(&devstr, vm->def, chr, priv->qemuCaps) < 0)
@@ -1594,8 +1601,15 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
  cleanup:
     if (ret < 0 && virDomainObjIsActive(vm))
         qemuDomainChrInsertPreAllocCleanup(vm->def, chr);
-    if (ret < 0 && need_release)
-        virDomainVirtioSerialAddrRelease(priv->vioserialaddrs, &chr->info);
+    if (ret < 0 && need_release) {
+        if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI) {
+            qemuDomainReleaseDeviceAddress(vm, &chr->info, NULL);
+        } else if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) {
+            /* XXX */
+        } else {
+            virDomainVirtioSerialAddrRelease(priv->vioserialaddrs, &chr->info);
+        }
+    }
     VIR_FREE(charAlias);
     VIR_FREE(devstr);
     return ret;
-- 
2.3.6




More information about the libvir-list mailing list