--- src/util/virnetdev.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/util/virnetdev.h | 10 ++++++ 2 files changed, 99 insertions(+), 0 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 86196a1..d07d8fa 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -968,6 +968,76 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname, } /** + * virNetDevGetVirtualFunctions: + * + * @pfname : name of the physical function interface name + * @virt_fns: array that will hold the pointers to the virtual_functions + * @num_virt_fns: number of virtual functions + * + * Returns 0 on success and -1 on failure + */ + +int +virNetDevGetVirtualFunctions(const char *pfname, + struct pci_config_address ***virt_fns, + unsigned int *num_virt_fns) +{ + int ret = -1; + char *pf_sysfs_device_link = NULL; + + + if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) + return ret; + + if (pciGetVirtualFunctions(pf_sysfs_device_link, virt_fns, + num_virt_fns) < 0) + goto out; + ret = 0; + +out: + VIR_FREE(pf_sysfs_device_link); + return ret; +} + +/** + * virNetDevGetNetName: + * + * @vf : pci address (BDF) of the Virtual Function + * @vfname: interface name of the virtual function returned by this function + * + * Returns 0 on success and -1 on failure + */ + +int +virNetDevGetNetName(struct pci_config_address *vf, char **vfname) +{ + int ret = -1; + pciDevice *dev = NULL; + char *pci_sysfs_device_link = NULL; + + dev = pciGetDevice(vf->domain, vf->bus, vf->slot, vf->function); + if (dev != NULL) { + if (pciSysfsFile(&pci_sysfs_device_link, dev->name) < 0) { + virReportSystemError(ENOSYS, "%s", + _("Failed to get PCI SYSFS file")); + goto out; + } + + if (pciDeviceNetName(pci_sysfs_device_link, vfname) < 0) { + virReportSystemError(ENOSYS, "%s", + _("Failed to get interface name of the VF")); + goto out; + } + } + ret = 0; + +out: + VIR_FREE(pci_sysfs_device_link); + pciFreeDevice(dev); + return ret; +} + +/** * virNetDevIsVirtualFunction: * @ifname : name of the interface * @@ -1055,6 +1125,25 @@ virNetDevGetPhysicalFunction(const char *ifname, char **pfname) } #else /* !__linux__ */ int +virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED, + struct pci_config_address ***virt_fns ATTRIBUTE_UNUSED, + unsigned int *num_virt_fns ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual functions on this platfornm")); + return -1; +} + +int +virNetDevGetNetName(struct pci_config_address *vf ATTRIBUTE_UNUSED, + char **vfname ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get Device name on this platfornm")); + return -1; +} + +int virNetDevIsVirtualFunction(const char *ifname ATTRIBUTE_UNUSED) { virReportSystemError(ENOSYS, "%s", diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 13ba1da..4d1573a 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -24,6 +24,7 @@ # define __VIR_NETDEV_H__ # include "virsocketaddr.h" +# include "pci.h" int virNetDevExists(const char *brname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; @@ -99,4 +100,13 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +int virNetDevGetVirtualFunctions(const char *pfname, + struct pci_config_address ***virt_fns, + unsigned int *num_virt_fns) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; + +int virNetDevGetNetName(struct pci_config_address *vf, char **vfname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + #endif /* __VIR_NETDEV_H__ */ -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list