]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: call virNetDevGetPhysPortID() in less places
authorLaine Stump <laine@redhat.com>
Thu, 2 Dec 2021 18:52:48 +0000 (13:52 -0500)
committerLaine Stump <laine@redhat.com>
Mon, 6 Dec 2021 18:04:28 +0000 (13:04 -0500)
Whenever virPCIGetNetName() is called, it is either called with
physPortID = NULL, or with it set by the caller calling
virNetDevGetPhysPortID() soon before virPCIGetNetName(). The
physPortID is then used *only* in virPCIGetNetName().

Rather than replicating that same call to virNetDevGetPhysPortID() in
all the callers of virPCIGetNetName(), lets just have all those
callers send the NetDevName whose physPortID they want down to
virPCIGetNetName(), and let virPCIGetNetName() call
virNetDevGetPhysPortID().

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virnetdev.c
src/util/virpci.c
src/util/virpci.h

index 861b426c586c14289f1eab46ac524724fd49c470..d93b2c6a838c8c78040c05bbb48593ddd97a328b 100644 (file)
@@ -1297,18 +1297,12 @@ int
 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;
 }
@@ -1336,14 +1330,6 @@ virNetDevPFGetVF(const char *pfname, int vf, char **vfname)
 {
     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);
 
@@ -1360,7 +1346,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **vfname)
      * 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);
 }
 
 
index f7afcb6e78806ad72b4539925132ce811233cb14..0d476cd8b453977cac86f0698a41a049f614ecf0 100644 (file)
@@ -2390,15 +2390,10 @@ virPCIGetVirtualFunctionsFull(const char *sysfs_path,
             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);
@@ -2474,8 +2469,20 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress *addr,
  * @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)
  *
@@ -2484,9 +2491,10 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress *addr,
 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;
@@ -2495,6 +2503,11 @@ virPCIGetNetName(const char *device_link_sysfs_path,
 
     *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) {
@@ -2585,7 +2598,6 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
     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;
@@ -2614,17 +2626,11 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
         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
@@ -2751,7 +2757,7 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress *dev G_GNUC_UNUSED,
 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));
index 7f332fc131ac0714755599215a0060a8ceefc496..b9b9cd7b3444277d3d6ebc444b84f44d3c1ff5e6 100644 (file)
@@ -245,7 +245,7 @@ int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress *addr,
 
 int virPCIGetNetName(const char *device_link_sysfs_path,
                      size_t idx,
-                     const char *physPortID,
+                     const char *physPortNetDevName,
                      char **netname);
 
 bool virPCIDeviceAddressIsValid(virPCIDeviceAddress *addr,