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.
This commit is contained in:
Laine Stump 2015-05-11 13:50:37 -04:00
parent 601b0fa872
commit d52d7a64b0
2 changed files with 3 additions and 40 deletions

View 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);
}

View 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)
if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath, data) < 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 */
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,