From nobody Fri May 16 05:42:22 2025 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 1502415761074549.6608307713323; Thu, 10 Aug 2017 18:42:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F329880465; Fri, 11 Aug 2017 01:42:38 +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 160B25C6D7; Fri, 11 Aug 2017 01:42:38 +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 37A2D4A467; Fri, 11 Aug 2017 01:42:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7B1gVZa003125 for ; Thu, 10 Aug 2017 21:42:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5E429814B; Fri, 11 Aug 2017 01:42:31 +0000 (UTC) Received: from vhost2.laine.org (ovpn-117-36.phx2.redhat.com [10.3.117.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7564E71C33; Fri, 11 Aug 2017 01:42:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F329880465 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 F329880465 From: Laine Stump To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 21:42:16 -0400 Message-Id: <20170811014222.29548-2-laine@laine.org> In-Reply-To: <20170811014222.29548-1-laine@laine.org> References: <20170811014222.29548-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, moshele@mellanox.com Subject: [libvirt] [PATCH v2 1/7] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 11 Aug 2017 01:42:39 +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, it returns NULL (*not* a NULL-terminated string, but a NULL pointer) but still counts it as a success. --- No change from V1. Already ACKed. 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 183a9194d..e6868b55f 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