char *pf_sysfs_device_link = NULL;
char *pci_sysfs_device_link = NULL;
char *pciConfigAddr = NULL;
+ char *pfPhysPortID = NULL;
*virt_fns = NULL;
*n_vfname = 0;
*max_vfs = 0;
+ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0)
+ goto cleanup;
+
if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0)
- return ret;
+ goto cleanup;
if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns,
n_vfname, max_vfs) < 0)
}
if (virPCIGetNetName(pci_sysfs_device_link, 0,
- NULL, &((*vfname)[i])) < 0) {
+ pfPhysPortID, &((*vfname)[i])) < 0) {
goto cleanup;
}
VIR_FREE(*vfname);
VIR_FREE(*virt_fns);
}
+ VIR_FREE(pfPhysPortID);
VIR_FREE(pf_sysfs_device_link);
VIR_FREE(pci_sysfs_device_link);
VIR_FREE(pciConfigAddr);
virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
{
char *physfn_sysfs_path = NULL;
+ char *vfPhysPortID = NULL;
int ret = -1;
+ if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0)
+ goto cleanup;
+
if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0)
- return ret;
+ goto cleanup;
if (virPCIGetNetName(physfn_sysfs_path, 0,
- NULL, pfname) < 0)
+ vfPhysPortID, pfname) < 0) {
goto cleanup;
+ }
if (!*pfname) {
/* this shouldn't be possible. A VF can't exist unless its
ret = 0;
cleanup:
+ VIR_FREE(vfPhysPortID);
VIR_FREE(physfn_sysfs_path);
return ret;
}
{
char *virtfnName = NULL;
char *virtfnSysfsPath = NULL;
+ char *pfPhysPortID = NULL;
int ret = -1;
+ /* a VF may have multiple "ports", each one having its own netdev,
+ * and each netdev having a different phys_port_id. Be sure we get
+ * the VF netdev with a phys_port_id matchine that of pfname
+ */
+ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0)
+ goto cleanup;
+
if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0)
goto cleanup;
* isn't bound to a netdev driver, it won't have a netdev name,
* and vfname will be NULL).
*/
- ret = virPCIGetNetName(virtfnSysfsPath, 0, NULL, vfname);
+ ret = virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname);
cleanup:
VIR_FREE(virtfnName);
VIR_FREE(virtfnSysfsPath);
+ VIR_FREE(pfPhysPortID);
return ret;
}