From: Laine Stump Date: Mon, 11 May 2015 17:50:37 +0000 (-0400) Subject: node_device: replace duplicated code in hal and udev backends X-Git-Tag: v1.2.16-rc1~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d52d7a64b083645cbd355a34476963d1623b617a;p=thirdparty%2Flibvirt.git node_device: replace duplicated code in hal and udev backends 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. --- diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 2379e884fb..2d3bc170ec 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 29da036e96..100b44d201 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,