]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
node_device: replace duplicated code in hal and udev backends
authorLaine Stump <laine@laine.org>
Mon, 11 May 2015 17:50:37 +0000 (13:50 -0400)
committerLaine Stump <laine@laine.org>
Mon, 18 May 2015 14:34:01 +0000 (10:34 -0400)
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
src/node_device/node_device_udev.c

index 2379e884fb1ca0674315d19a1fa25c1601fc0247..2d3bc170ecbd2f7885ed33266a690019ef9a79b1 100644 (file)
@@ -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);
     }
 
index 29da036e968d9ba949f398daf8913f08096e2cc1..100b44d2018691c2d98317228aa4457ef13ffe82 100644 (file)
@@ -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,