/*
- * Copyright (C) 2007-2011 Red Hat, Inc.
+ * Copyright (C) 2007-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return 0;
}
+/**
+ * virNetDevGetVirtualFunctions:
+ *
+ * @pfname : name of the physical function interface name
+ * @vfname: array that will hold the interface names of the virtual_functions
+ * @n_vfname: pointer to the number of virtual functions
+ *
+ * Returns 0 on success and -1 on failure
+ */
+
+int
+virNetDevGetVirtualFunctions(const char *pfname,
+ char ***vfname,
+ unsigned int *n_vfname)
+{
+ int ret = -1, i;
+ char *pf_sysfs_device_link = NULL;
+ char *pci_sysfs_device_link = NULL;
+ struct pci_config_address **virt_fns;
+ char *pciConfigAddr;
+
+ if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0)
+ return ret;
+
+ if (pciGetVirtualFunctions(pf_sysfs_device_link, &virt_fns,
+ n_vfname) < 0)
+ goto cleanup;
+
+ if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ for (i = 0; i < *n_vfname; i++)
+ {
+ if (pciGetDeviceAddrString(virt_fns[i]->domain,
+ virt_fns[i]->bus,
+ virt_fns[i]->slot,
+ virt_fns[i]->function,
+ &pciConfigAddr) < 0) {
+ virReportSystemError(ENOSYS, "%s",
+ _("Failed to get PCI Config Address String"));
+ goto cleanup;
+ }
+ if (pciSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0) {
+ virReportSystemError(ENOSYS, "%s",
+ _("Failed to get PCI SYSFS file"));
+ goto cleanup;
+ }
+
+ if (pciDeviceNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) {
+ virReportSystemError(ENOSYS, "%s",
+ _("Failed to get interface name of the VF"));
+ goto cleanup;
+ }
+ }
+
+ ret = 0;
+
+cleanup:
+ if (ret < 0)
+ VIR_FREE(*vfname);
+ for (i = 0; i < *n_vfname; i++)
+ VIR_FREE(virt_fns[i]);
+ VIR_FREE(virt_fns);
+ VIR_FREE(pf_sysfs_device_link);
+ VIR_FREE(pci_sysfs_device_link);
+ VIR_FREE(pciConfigAddr);
+ return ret;
+}
+
/**
* virNetDevIsVirtualFunction:
* @ifname : name of the interface
return ret;
}
#else /* !__linux__ */
+
+int
+virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED,
+ char ***vfname ATTRIBUTE_UNUSED,
+ unsigned int *n_vfname ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to get virtual functions on this platfornm"));
+ return -1;
+}
+
int
virNetDevIsVirtualFunction(const char *ifname ATTRIBUTE_UNUSED)
{
/*
- * Copyright (C) 2007-2011 Red Hat, Inc.
+ * Copyright (C) 2007-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
int virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virNetDevGetVirtualFunctions(const char *pfname,
+ char ***vfname,
+ unsigned int *n_vfname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
+ ATTRIBUTE_RETURN_CHECK;
+
#endif /* __VIR_NETDEV_H__ */