From nobody Thu Apr 25 06:35:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501818528616859.7387053232825; Thu, 3 Aug 2017 20:48:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00DA485550; Fri, 4 Aug 2017 03:48:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AF2E944AF; Fri, 4 Aug 2017 03:48:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8C26C1803B21; Fri, 4 Aug 2017 03:48:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v743aq71001773 for ; Thu, 3 Aug 2017 23:36:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50D5A8908B; Fri, 4 Aug 2017 03:36:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-71.phx2.redhat.com [10.3.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id D37C26F925; Fri, 4 Aug 2017 03:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00DA485550 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00DA485550 From: Laine Stump To: libvir-list@redhat.com Date: Thu, 3 Aug 2017 23:36:42 -0400 Message-Id: <20170804033644.4923-2-laine@laine.org> In-Reply-To: <20170804033644.4923-1-laine@laine.org> References: <20170804033644.4923-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: moshele@mellanox.com, edand@mellanox.com Subject: [libvirt] [PATCH 1/3] util: new function virNetDevGetPhysPortID() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 04 Aug 2017 03:48:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" On Linux each network device *can* (but not necessarily *does*) have an attribute called phys_port_id which can be read from the file of that name in the netdev's sysfs directory. The examples I've seen have been a many-digit hexadecimal number (as an ASCII string). This value can be useful when a single PCI device is associated with multiple netdevs (e.g a dual port Mellanox SR-IOV NIC - this card has a single PCI Physical Function (PF), and that PF has two netdevs associated with it (the "net" subdirectory of the PF in sysfs has two links rather than the usual single link to a netdev directory). Each of the PF netdevs has a different phys_port_id. The Virtual Functions (VF) are similar - the PF (a PCI device) has "n" VFs (also each of these is a PCI device), each VF has two netdevs, and each of the VF netdevs points back to the VF PCI device (with the "device" entry in its sysfs directory) as well as having a phys_port_id matching the PF netdev it is associated with. virNetDevGetPhysPortID() simply attempts to read the phys_port_id for the given netdev and return it to the caller. If this particular netdev driver doesn't support phys_port_id (most don't), it returns NULL (*not* a NULL-terminated string, but a NULL pointer) but still counts it as a success. --- src/libvirt_private.syms | 1 + src/util/virnetdev.c | 51 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdev.h | 5 +++++ 3 files changed, 57 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 32ac0835e..28d089396 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2113,6 +2113,7 @@ virNetDevGetMTU; virNetDevGetName; virNetDevGetOnline; virNetDevGetPhysicalFunction; +virNetDevGetPhysPortID; virNetDevGetPromiscuous; virNetDevGetRcvAllMulti; virNetDevGetRcvMulti; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 90b7bee34..a2664de78 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1170,6 +1170,46 @@ virNetDevGetPCIDevice(const char *devName) =20 =20 /** + * virNetDevGetPhysPortID: + * + * @ifname: name of a netdev + * + * @physPortID: pointer to char* that will receive @ifname's + * phys_port_id from sysfs (null terminated + * string). Could be NULL if @ifname's net driver doesn't + * support phys_port_id (most netdev drivers + * don't). Caller is responsible for freeing the string + * when finished. + * + * Returns 0 on success or -1 on failure. + */ +int +virNetDevGetPhysPortID(const char *ifname, + char **physPortID) +{ + int ret =3D -1; + char *physPortIDFile =3D NULL; + + *physPortID =3D NULL; + + if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) + goto cleanup; + + /* a failure to read just means the driver doesn't support + * phys_port_id, so set success now and ignore the return from + * virFileReadAllQuiet(). + */ + ret =3D 0; + + ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); + + cleanup: + VIR_FREE(physPortIDFile); + return ret; +} + + +/** * virNetDevGetVirtualFunctions: * * @pfname : name of the physical function interface name @@ -1433,6 +1473,17 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, = char **pfname, =20 #else /* !__linux__ */ int +virNetDevGetPhysPortID(const char *ifname ATTRIBUTE_UNUSED, + char **physPortID ATTRIBUTE_UNUSED) +{ + /* this actually should never be called, and is just here to + * satisfy the linker. + */ + *physPortID =3D NULL; + return 0; +} + +int virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED, char ***vfname ATTRIBUTE_UNUSED, virPCIDeviceAddressPtr **virt_fns ATTRIBUTE_U= NUSED, diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 51fcae544..9205c0e86 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -226,6 +226,11 @@ int virNetDevGetPhysicalFunction(const char *ifname, c= har **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; =20 +int virNetDevGetPhysPortID(const char *ifname, + char **physPortID) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_RETURN_CHECK; + int virNetDevGetVirtualFunctions(const char *pfname, char ***vfname, virPCIDeviceAddressPtr **virt_fns, --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 06:35:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501817823005190.8373151777123; Thu, 3 Aug 2017 20:37:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6274620271; Fri, 4 Aug 2017 03:37:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAB4678A27; Fri, 4 Aug 2017 03:36:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 39B2D14B1E; Fri, 4 Aug 2017 03:36:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v743aqP6001792 for ; Thu, 3 Aug 2017 23:36:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9CA66F925; Fri, 4 Aug 2017 03:36:52 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-71.phx2.redhat.com [10.3.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E7BB8908B; Fri, 4 Aug 2017 03:36:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6274620271 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6274620271 From: Laine Stump To: libvir-list@redhat.com Date: Thu, 3 Aug 2017 23:36:43 -0400 Message-Id: <20170804033644.4923-3-laine@laine.org> In-Reply-To: <20170804033644.4923-1-laine@laine.org> References: <20170804033644.4923-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: moshele@mellanox.com, edand@mellanox.com Subject: [libvirt] [PATCH 2/3] util: support matching a phys_port_id in virPCIGetNetName() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 04 Aug 2017 03:37:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A single PCI device may have multiple netdevs associated with it. Each of those netdevs will have a different phys_port_id entry in sysfs. This patch modifies virPCIGetNetName() to allow matching the netdev for a PCI device that has the same phys_port_id that the caller wants. --- src/util/virhostdev.c | 2 +- src/util/virnetdev.c | 6 +++--- src/util/virpci.c | 49 ++++++++++++++++++++++++++++++++++++++++-------= -- src/util/virpci.h | 4 +++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 579563c3f..fcefebd07 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -326,7 +326,7 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, cha= r **linkdev, * type=3D'hostdev'>, and it is only those devices that should * end up calling this function. */ - if (virPCIGetNetName(sysfs_path, linkdev) < 0) + if (virPCIGetNetName(sysfs_path, NULL, linkdev) < 0) goto cleanup; =20 if (!linkdev) { diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index a2664de78..1c150b7d7 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1262,7 +1262,7 @@ virNetDevGetVirtualFunctions(const char *pfname, goto cleanup; } =20 - if (virPCIGetNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) + if (virPCIGetNetName(pci_sysfs_device_link, NULL, &((*vfname)[i]))= < 0) goto cleanup; =20 if (!(*vfname)[i]) @@ -1362,7 +1362,7 @@ virNetDevGetPhysicalFunction(const char *ifname, char= **pfname) if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) return ret; =20 - if (virPCIGetNetName(physfn_sysfs_path, pfname) < 0) + if (virPCIGetNetName(physfn_sysfs_path, NULL, pfname) < 0) goto cleanup; =20 if (!*pfname) { @@ -1422,7 +1422,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **v= fname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, vfname); + ret =3D virPCIGetNetName(virtfnSysfsPath, NULL, vfname); =20 cleanup: VIR_FREE(virtfnName); diff --git a/src/util/virpci.c b/src/util/virpci.c index 2c1b75855..5d811ada6 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -24,6 +24,7 @@ #include =20 #include "virpci.h" +#include "virnetdev.h" =20 #include #include @@ -2857,12 +2858,15 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddress= Ptr addr, * Returns the network device name of a pci device */ int -virPCIGetNetName(char *device_link_sysfs_path, char **netname) +virPCIGetNetName(char *device_link_sysfs_path, + char *physPortID, + char **netname) { char *pcidev_sysfs_net_path =3D NULL; int ret =3D -1; DIR *dir =3D NULL; struct dirent *entry =3D NULL; + char *thisPhysPortID =3D NULL; =20 if (virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path, "net") =3D=3D -1) { @@ -2873,21 +2877,47 @@ virPCIGetNetName(char *device_link_sysfs_path, char= **netname) if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) { /* this *isn't* an error - caller needs to check for netname =3D= =3D NULL */ ret =3D 0; - goto out; + goto cleanup; } =20 while (virDirRead(dir, &entry, pcidev_sysfs_net_path) > 0) { - /* Assume a single directory entry */ - if (VIR_STRDUP(*netname, entry->d_name) > 0) - ret =3D 0; + /* if the caller sent a physPortID, compare it to the + * physportID of this netdev. If not, accept the first netdev + */ + if (physPortID) { + if (virNetDevGetPhysPortID(entry->d_name, &thisPhysPortID) < 0) + goto cleanup; + + /* if this one doesn't match, keep looking */ + if (STRNEQ_NULLABLE(physPortID, thisPhysPortID)) { + VIR_FREE(thisPhysPortID); + continue; + } + } + if (VIR_STRDUP(*netname, entry->d_name) < 0) + goto cleanup; + + ret =3D 0; break; } =20 + if (ret < 0) { + if (physPortID) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find network device with " + "phys_port_id '%s' under PCI device at %s"), + physPortID, device_link_sysfs_path); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("PCI device at %s had a net directory, " + "but it was empty"), + device_link_sysfs_path); + } + } + cleanup: VIR_DIR_CLOSE(dir); - - out: VIR_FREE(pcidev_sysfs_net_path); - + VIR_FREE(thisPhysPortID); return ret; } =20 @@ -2915,7 +2945,7 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_dev= ice_path, goto cleanup; } =20 - if (virPCIGetNetName(pf_sysfs_device_path, pfname) < 0) + if (virPCIGetNetName(pf_sysfs_device_path, NULL, pfname) < 0) goto cleanup; =20 if (!*pfname) { @@ -2992,6 +3022,7 @@ virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPt= r dev ATTRIBUTE_UNUSED, =20 int virPCIGetNetName(char *device_link_sysfs_path ATTRIBUTE_UNUSED, + char *physPortID ATTRIBUTE_UNUSED, char **netname ATTRIBUTE_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); diff --git a/src/util/virpci.h b/src/util/virpci.h index 570684e75..c0e54d785 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -207,7 +207,9 @@ int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_= device_link, int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr, char **pci_sysfs_device_link); =20 -int virPCIGetNetName(char *device_link_sysfs_path, char **netname); +int virPCIGetNetName(char *device_link_sysfs_path, + char *physPortID, + char **netname); =20 int virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link) --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 06:35:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501818536274659.8826001248747; Thu, 3 Aug 2017 20:48:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 354E037EEF; Fri, 4 Aug 2017 03:48:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09ED2944B0; Fri, 4 Aug 2017 03:48:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B5DF2180BA82; Fri, 4 Aug 2017 03:48:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v743ar82001830 for ; Thu, 3 Aug 2017 23:36:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8AB3F8908E; Fri, 4 Aug 2017 03:36:53 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-71.phx2.redhat.com [10.3.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DB9F8908C; Fri, 4 Aug 2017 03:36:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 354E037EEF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 354E037EEF From: Laine Stump To: libvir-list@redhat.com Date: Thu, 3 Aug 2017 23:36:44 -0400 Message-Id: <20170804033644.4923-4-laine@laine.org> In-Reply-To: <20170804033644.4923-1-laine@laine.org> References: <20170804033644.4923-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: moshele@mellanox.com, edand@mellanox.com Subject: [libvirt] [PATCH 3/3] util: match phys_port_id when converting PF-netdev to/from VF-netdev X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 04 Aug 2017 03:48:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch updates functions in netdev.c to pay attention to phys_port_id. It uses the new function virNetDevGetPhysPortID() to learn the phys_port_id of a VF or PF, then sends that info to virPCIGetNetName(), which has newly been modified to take an optional phys_port_id. --- src/util/virnetdev.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 1c150b7d7..83b255219 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1231,13 +1231,17 @@ virNetDevGetVirtualFunctions(const char *pfname, char *pf_sysfs_device_link =3D NULL; char *pci_sysfs_device_link =3D NULL; char *pciConfigAddr =3D NULL; + char *pfPhysPortID =3D NULL; =20 *virt_fns =3D NULL; *n_vfname =3D 0; *max_vfs =3D 0; =20 + if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) + goto cleanup; + if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - return ret; + goto cleanup; =20 if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns, n_vfname, max_vfs) < 0) @@ -1262,8 +1266,10 @@ virNetDevGetVirtualFunctions(const char *pfname, goto cleanup; } =20 - if (virPCIGetNetName(pci_sysfs_device_link, NULL, &((*vfname)[i]))= < 0) + if (virPCIGetNetName(pci_sysfs_device_link, + pfPhysPortID, &((*vfname)[i])) < 0) { goto cleanup; + } =20 if (!(*vfname)[i]) VIR_INFO("VF does not have an interface name"); @@ -1276,6 +1282,7 @@ virNetDevGetVirtualFunctions(const char *pfname, 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); @@ -1357,13 +1364,19 @@ int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { char *physfn_sysfs_path =3D NULL; + char *vfPhysPortID =3D NULL; int ret =3D -1; =20 + if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) + goto cleanup; + if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) - return ret; + goto cleanup; =20 - if (virPCIGetNetName(physfn_sysfs_path, NULL, pfname) < 0) + if (virPCIGetNetName(physfn_sysfs_path, + vfPhysPortID, pfname) < 0) { goto cleanup; + } =20 if (!*pfname) { /* this shouldn't be possible. A VF can't exist unless its @@ -1377,6 +1390,7 @@ virNetDevGetPhysicalFunction(const char *ifname, char= **pfname) =20 ret =3D 0; cleanup: + VIR_FREE(vfPhysPortID); VIR_FREE(physfn_sysfs_path); return ret; } @@ -1404,8 +1418,16 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) { char *virtfnName =3D NULL; char *virtfnSysfsPath =3D NULL; + char *pfPhysPortID =3D NULL; int ret =3D -1; =20 + /* 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; =20 @@ -1422,11 +1444,12 @@ 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). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, NULL, vfname); + ret =3D virPCIGetNetName(virtfnSysfsPath, pfPhysPortID, vfname); =20 cleanup: VIR_FREE(virtfnName); VIR_FREE(virtfnSysfsPath); + VIR_FREE(pfPhysPortID); =20 return ret; } --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list