virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
{
g_autofree char *physfn_sysfs_path = NULL;
- g_autofree char *vfPhysPortID = NULL;
-
- if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0)
- return -1;
if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0)
return -1;
- if (virPCIGetNetName(physfn_sysfs_path, 0,
- vfPhysPortID, pfname) < 0) {
+ if (virPCIGetNetName(physfn_sysfs_path, 0, ifname, pfname) < 0)
return -1;
- }
return 0;
}
{
g_autofree char *virtfnName = NULL;
g_autofree char *virtfnSysfsPath = NULL;
- g_autofree char *pfPhysPortID = NULL;
-
- /* 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)
- return -1;
virtfnName = g_strdup_printf("virtfn%d", vf);
* isn't bound to a netdev driver, it won't have a netdev name,
* and vfname will be NULL).
*/
- return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname);
+ return virPCIGetNetName(virtfnSysfsPath, 0, pfname, vfname);
}
return -1;
}
- if (pfNetDevName) {
- g_autofree char *pfPhysPortID = NULL;
-
- if (virNetDevGetPhysPortID(pfNetDevName, &pfPhysPortID) < 0 ||
- virPCIGetNetName(device_link, 0, pfPhysPortID, &fnc.ifname) < 0) {
-
- g_free(fnc.addr);
- return -1;
- }
+ if (pfNetDevName &&
+ virPCIGetNetName(device_link, 0, pfNetDevName, &fnc.ifname) < 0) {
+ g_free(fnc.addr);
+ return -1;
}
VIR_APPEND_ELEMENT(list->functions, list->nfunctions, fnc);
* @device_link_sysfs_path: sysfs path to the PCI device
* @idx: used to choose which netdev when there are several
* (ignored if physPortID is set or physPortName is available)
- * @physPortID: match this string in the netdev's phys_port_id
- * (or NULL to ignore and use phys_port_name or idx instead)
+
+ * @physPortNetDevName: if non-null, attempt to learn the phys_port_id
+ * of the netdev interface named
+ * @physPortNetDevName, and find a netdev for
+ * this PCI device that has the same
+ * phys_port_id. if @physPortNetDevName is NULL,
+ * or has no phys_port_id, then use
+ * phys_port_name or idx to determine which
+ * netdev to return. (NB: as of today, only mlx
+ * drivers/cards can have multiple phys_ports for
+ * a single PCI device; on all other devices
+ * there is only a single choice of netdev, and
+ * phys_port_id, phys_port_name, and idx are
+ * unavailable/unused)
* @netname: used to return the name of the netdev
* (set to NULL (but returns success) if there is no netdev)
*
int
virPCIGetNetName(const char *device_link_sysfs_path,
size_t idx,
- const char *physPortID,
+ const char *physPortNetDevName,
char **netname)
{
+ g_autofree char *physPortID = NULL;
g_autofree char *pcidev_sysfs_net_path = NULL;
g_autofree char *firstEntryName = NULL;
g_autoptr(DIR) dir = NULL;
*netname = NULL;
+ if (physPortNetDevName &&
+ virNetDevGetPhysPortID(physPortNetDevName, &physPortID) < 0) {
+ return -1;
+ }
+
virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path, "net");
if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) {
g_autofree virPCIDeviceAddress *pf_config_address = NULL;
g_autofree char *pf_sysfs_device_path = NULL;
g_autofree char *vfname = NULL;
- g_autofree char *vfPhysPortID = NULL;
if (virPCIGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address) < 0)
return -1;
if (virPCIGetNetName(vf_sysfs_device_path, 0, NULL, &vfname) < 0)
return -1;
- if (vfname) {
- if (virNetDevGetPhysPortID(vfname, &vfPhysPortID) < 0)
- return -1;
- }
pfNetDevIdx = 0;
}
- if (virPCIGetNetName(pf_sysfs_device_path,
- pfNetDevIdx, vfPhysPortID, pfname) < 0) {
+ if (virPCIGetNetName(pf_sysfs_device_path, pfNetDevIdx, vfname, pfname) < 0)
return -1;
- }
if (!*pfname) {
/* this shouldn't be possible. A VF can't exist unless its
int
virPCIGetNetName(const char *device_link_sysfs_path G_GNUC_UNUSED,
size_t idx G_GNUC_UNUSED,
- const char *physPortID G_GNUC_UNUSED,
+ const char *physPortNetDevName G_GNUC_UNUSED,
char **netname G_GNUC_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));