diff mbox

[2/3] qemu: hotplug: generate vioserial address list on demand

Message ID d4902e7b53a06672621722b8b97ca0d859bd3e23.1463249776.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson May 14, 2016, 6:25 p.m. UTC
The hotplug address allocation depends on the vioserialaddrs
cache being populated elsewhere. However the cache isn't needed
and we can just generate the address list on demand from the
VM's definition
---
 src/qemu/qemu_hotplug.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

-- 
2.7.4

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

Patch

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f40b34d..28a49a0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1486,38 +1486,51 @@  qemuDomainChrRemove(virDomainDefPtr vmdef,
 }
 
 static int
-qemuDomainAttachChrDeviceAssignAddr(qemuDomainObjPrivatePtr priv,
+qemuDomainAttachChrDeviceAssignAddr(virDomainDefPtr def,
+                                    qemuDomainObjPrivatePtr priv,
                                     virDomainChrDefPtr chr)
 {
+    int ret = -1;
+    virDomainVirtioSerialAddrSetPtr vioaddrs = NULL;
+
+    if (!(vioaddrs = virDomainVirtioSerialAddrSetCreateFromDomain(def)))
+        goto cleanup;
+
     if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
         chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO) {
-        if (virDomainVirtioSerialAddrAutoAssign(NULL, priv->vioserialaddrs,
+        if (virDomainVirtioSerialAddrAutoAssign(def, vioaddrs,
                                                 &chr->info, true) < 0)
-            return -1;
-        return 1;
+            goto cleanup;
+        ret = 1;
 
     } else if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
                chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI) {
         if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &chr->info) < 0)
-            return -1;
-        return 1;
+            goto cleanup;
+        ret = 1;
 
     } else if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
                chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
-        if (virDomainVirtioSerialAddrAutoAssign(NULL, priv->vioserialaddrs,
+        if (virDomainVirtioSerialAddrAutoAssign(def, vioaddrs,
                                                 &chr->info, false) < 0)
-            return -1;
-        return 1;
+            goto cleanup;
+        ret = 1;
     }
 
+    if (ret == 1)
+        goto cleanup;
+
     if (chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL ||
         chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Unsupported address type for character device"));
-        return -1;
+        goto cleanup;
     }
 
-    return 0;
+    ret = 0;
+ cleanup:
+    virDomainVirtioSerialAddrSetFree(vioaddrs);
+    return ret;
 }
 
 int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
@@ -1540,7 +1553,7 @@  int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
     if (qemuAssignDeviceChrAlias(vmdef, chr, -1) < 0)
         goto cleanup;
 
-    if ((rc = qemuDomainAttachChrDeviceAssignAddr(priv, chr)) < 0)
+    if ((rc = qemuDomainAttachChrDeviceAssignAddr(vm->def, priv, chr)) < 0)
         goto cleanup;
     if (rc == 1)
         need_release = true;