[libvirt] [PATCH 6/6] node_device: replace duplicated code in hal and udev backends

Laine Stump laine at laine.org
Fri May 15 15:04:29 UTC 2015


Both the hal and udev drivers call virPCI*() functions to the the
SRIOV VF/PF info about PCI devices, and the UDEV backend calls
virPCI*() to get IOMMU group info. Since there is now a single
function call in node_device_linux_sysfs.c to do all of this, replace
all that code in the two backends with calls to
nodeDeviceSysfsGetPCIRelatedDevCaps().

Note that this results in the HAL driver (probably) unnecessarily
calling virPCIDevieAddressGetIOMMUGroupNum(), but in the case that the
host doesn't support IOMMU groups, that function turns into a NOP (it
returns -2, which causes the caller to skip the call to
virPCIDeviceAddressGetIOMMUGroupAddresses()). So in the worst case it
is a few extra cycles spent, and in the best case a mythical platform
that supported IOMMU groups but used HAL rather than UDEV would gain
proper reporting of IOMMU group info.
---
 src/node_device/node_device_hal.c  | 12 +-----------
 src/node_device/node_device_udev.c | 31 ++-----------------------------
 2 files changed, 3 insertions(+), 40 deletions(-)

diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 2379e88..2d3bc17 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -153,20 +153,10 @@ gather_pci_cap(LibHalContext *ctx, const char *udi,
             ignore_value(virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function));
         }
 
-        if (!virPCIGetPhysicalFunction(sysfs_path,
-                                       &d->pci_dev.physical_function))
-            d->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
-
-        int ret = virPCIGetVirtualFunctions(sysfs_path,
-                                            &d->pci_dev.virtual_functions,
-                                            &d->pci_dev.num_virtual_functions);
-        if (ret < 0) {
+        if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, d) < 0) {
             VIR_FREE(sysfs_path);
             return -1;
         }
-
-        if (d->pci_dev.num_virtual_functions > 0)
-            d->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
         VIR_FREE(sysfs_path);
     }
 
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 29da036..100b44d 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -413,11 +413,10 @@ static int udevProcessPCI(struct udev_device *device,
 {
     const char *syspath = NULL;
     virNodeDevCapDataPtr data = &def->caps->data;
-    virPCIDeviceAddress addr;
     virPCIEDeviceInfoPtr pci_express = NULL;
     virPCIDevicePtr pciDev = NULL;
     udevPrivate *priv = driver->privateData;
-    int tmpGroup, ret = -1;
+    int ret = -1;
     char *p;
     int rc;
 
@@ -496,34 +495,8 @@ static int udevProcessPCI(struct udev_device *device,
         data->pci_dev.numa_node = -1;
     }
 
-    if (!virPCIGetPhysicalFunction(syspath, &data->pci_dev.physical_function))
-        data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
-
-    rc = virPCIGetVirtualFunctions(syspath,
-                                   &data->pci_dev.virtual_functions,
-                                   &data->pci_dev.num_virtual_functions);
-    /* Out of memory */
-    if (rc < 0)
-        goto out;
-    else if (!rc && (data->pci_dev.num_virtual_functions > 0))
-        data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
-
-    /* iommu group */
-    addr.domain = data->pci_dev.domain;
-    addr.bus = data->pci_dev.bus;
-    addr.slot = data->pci_dev.slot;
-    addr.function = data->pci_dev.function;
-    tmpGroup = virPCIDeviceAddressGetIOMMUGroupNum(&addr);
-    if (tmpGroup == -1) {
-        /* error was already reported */
+    if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath, data) < 0)
         goto out;
-        /* -2 return means there is no iommu_group data */
-    } else if (tmpGroup >= 0) {
-        if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &data->pci_dev.iommuGroupDevices,
-                                                      &data->pci_dev.nIommuGroupDevices) < 0)
-            goto out;
-        data->pci_dev.iommuGroupNumber = tmpGroup;
-    }
 
     if (!(pciDev = virPCIDeviceNew(data->pci_dev.domain,
                                    data->pci_dev.bus,
-- 
2.1.0




More information about the libvir-list mailing list