[PATCH v2 08/10] qemu_hotplug: generate pci address list on demand

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

 



Dropping the caching of pci address set.
Instead of using the cached address set, functions in qemu_hotplug.c
now recalculate it on demand.
---
 src/qemu/qemu_domain_address.c |  6 ------
 src/qemu/qemu_hotplug.c        | 47 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index add6fb5..2191009 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -1825,12 +1825,6 @@ qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
     if (!devstr)
         devstr = info->alias;
 
-    if (virDeviceInfoPCIAddressPresent(info) &&
-             virDomainPCIAddressReleaseSlot(priv->pciaddrs,
-                                            &info->addr.pci) < 0)
-        VIR_WARN("Unable to release PCI address on %s",
-                 NULLSTR(devstr));
-
     if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB &&
         priv->usbaddrs &&
         virDomainUSBAddressRelease(priv->usbaddrs, info) < 0)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3deeb0b..aafd937 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -314,6 +314,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     bool secobjAdded = false;
     bool encobjAdded = false;
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     const char *src = virDomainDiskGetSource(disk);
     virJSONValuePtr secobjProps = NULL;
@@ -345,7 +346,10 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
             goto error;
     } else if (!disk->info.type ||
                 disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-        if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &disk->info) < 0)
+        if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(vm->def,
+                                                              priv->qemuCaps)))
+            goto error;
+        if (virDomainPCIAddressEnsureAddr(pciaddrs, &disk->info) < 0)
             goto error;
     }
     releaseaddr = true;
@@ -420,6 +424,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     virJSONValueFree(encobjProps);
     qemuDomainSecretDiskDestroy(disk);
     virDomainCCWAddressSetFree(ccwaddrs);
+    virDomainPCIAddressSetFree(pciaddrs);
     VIR_FREE(devstr);
     VIR_FREE(drivestr);
     VIR_FREE(drivealias);
@@ -464,6 +469,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
     char *devstr = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
     bool releaseaddr = false;
 
     if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) {
@@ -502,7 +508,10 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
 
     if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
         controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-        if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &controller->info) < 0)
+        if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(vm->def,
+                                                              priv->qemuCaps)))
+            goto cleanup;
+        if (virDomainPCIAddressEnsureAddr(pciaddrs, &controller->info) < 0)
             goto cleanup;
     } else if (controller->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
         if (!(ccwaddrs = qemuDomainCCWAddrSetCreateFromDomain(vm->def)))
@@ -541,6 +550,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
 
     VIR_FREE(devstr);
     virDomainCCWAddressSetFree(ccwaddrs);
+    virDomainPCIAddressSetFree(pciaddrs);
     return ret;
 }
 
@@ -910,6 +920,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     virNetDevBandwidthPtr actualBandwidth;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
     size_t i;
 
     /* preallocate new slot for device */
@@ -1056,8 +1067,12 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("virtio-s390 net device cannot be hotplugged."));
         goto cleanup;
-    } else if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &net->info) < 0) {
-        goto cleanup;
+    } else {
+        if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(vm->def,
+                                                              priv->qemuCaps)))
+            goto cleanup;
+        if (virDomainPCIAddressEnsureAddr(pciaddrs, &net->info) < 0)
+            goto cleanup;
     }
 
     releaseaddr = true;
@@ -1224,6 +1239,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     VIR_FREE(vhostfdName);
     virObjectUnref(cfg);
     virDomainCCWAddressSetFree(ccwaddrs);
+    virDomainPCIAddressSetFree(pciaddrs);
 
     return ret;
 
@@ -1275,6 +1291,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
     bool teardownlabel = false;
     int backend;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
     unsigned int flags = 0;
 
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
@@ -1336,8 +1353,13 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
 
     if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) < 0)
         goto error;
-    if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, hostdev->info) < 0)
+
+    if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(vm->def, priv->qemuCaps)))
+        goto error;
+
+    if (virDomainPCIAddressEnsureAddr(pciaddrs, hostdev->info) < 0)
         goto error;
+
     releaseaddr = true;
     if (backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_PCI_CONFIGFD)) {
@@ -1397,6 +1419,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
 
  cleanup:
     virObjectUnref(cfg);
+    virDomainPCIAddressSetFree(pciaddrs);
     return -1;
 }
 
@@ -1569,6 +1592,7 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainDefPtr def,
 {
     int ret = -1;
     virDomainVirtioSerialAddrSetPtr vioaddrs = NULL;
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
 
     if (!(vioaddrs = virDomainVirtioSerialAddrSetCreateFromDomain(def)))
         goto cleanup;
@@ -1582,7 +1606,9 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainDefPtr def,
 
     } 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)
+        if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(def, priv->qemuCaps)))
+            goto cleanup;
+        if (virDomainPCIAddressEnsureAddr(pciaddrs, &chr->info) < 0)
             goto cleanup;
         ret = 1;
 
@@ -1614,6 +1640,7 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainDefPtr def,
 
  cleanup:
     virDomainVirtioSerialAddrSetFree(vioaddrs);
+    virDomainPCIAddressSetFree(pciaddrs);
     return ret;
 }
 
@@ -1705,6 +1732,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     bool objAdded = false;
     virJSONValuePtr props = NULL;
     virDomainCCWAddressSetPtr ccwaddrs = NULL;
+    virDomainPCIAddressSetPtr pciaddrs = NULL;
     const char *type;
     int ret = -1;
     int rv;
@@ -1732,8 +1760,10 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
 
     if (rng->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
         rng->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
-        if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &rng->info) < 0)
-            return -1;
+        if (!(pciaddrs = qemuDomainPCIAddrSetCreateFromDomain(vm->def, priv->qemuCaps)))
+            goto cleanup;
+        if (virDomainPCIAddressEnsureAddr(pciaddrs, &rng->info) < 0)
+            goto cleanup;
     } else if (rng->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
         if (!(ccwaddrs = qemuDomainCCWAddrSetCreateFromDomain(vm->def)))
             goto cleanup;
@@ -1791,6 +1821,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     VIR_FREE(objAlias);
     VIR_FREE(devstr);
     virDomainCCWAddressSetFree(ccwaddrs);
+    virDomainPCIAddressSetFree(pciaddrs);
     return ret;
 
  exit_monitor:
-- 
2.7.4 (Apple Git-66)

--
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]