From nobody Wed Feb 11 10:18:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1489178323395764.5336214303112; Fri, 10 Mar 2017 12:38:43 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AKZdcV046129; Fri, 10 Mar 2017 15:35:39 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2AKZML7018986 for ; Fri, 10 Mar 2017 15:35:22 -0500 Received: from vhost2.laine.org (ovpn-116-174.phx2.redhat.com [10.3.116.174]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AKZHih012172 for ; Fri, 10 Mar 2017 15:35:22 -0500 From: Laine Stump To: libvir-list@redhat.com Date: Fri, 10 Mar 2017 15:35:03 -0500 Message-Id: <20170310203512.15478-11-laine@laine.org> In-Reply-To: <20170310203512.15478-1-laine@laine.org> References: <20170310203512.15478-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/19] util: new function virNetDevPFGetVF() 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Given an SRIOV PF netdev name (e.g. "enp2s0f0") and VF#, this new function returns the netdev name of the referenced VF device (e.g. "enp2s11f6"), or NULL if the device isn't bound to a net driver. --- src/libvirt_private.syms | 1 + src/util/virnetdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdev.h | 3 +++ 3 files changed, 62 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ef027cc..e9705ae 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1997,6 +1997,7 @@ virNetDevGetVLanID; virNetDevIfStateTypeFromString; virNetDevIfStateTypeToString; virNetDevIsVirtualFunction; +virNetDevPFGetVF; virNetDevReplaceMacAddress; virNetDevReplaceNetConfig; virNetDevRestoreMacAddress; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index ffc2fb4..49a11f3 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1311,6 +1311,54 @@ virNetDevGetPhysicalFunction(const char *ifname, cha= r **pfname) return ret; } =20 + +/** + * virNetDevPFGetVF: + * + * @pfname: netdev name of the physical function (PF) + * @vf: virtual function (VF) number for the device of interest + * @vfname: name of the physical function interface name + * + * Finds the netdev name of VF# @vf of SRIOV PF @pfname, and puts it + * in @vfname. The caller must free @vfname when it's finished with + * it. + * + * Returns 0 on success, -1 on failure + * + */ +int +virNetDevPFGetVF(const char *pfname, int vf, char **vfname) +{ + char *virtfnName =3D NULL; + char *virtfnSysfsPath =3D NULL; + int ret =3D -1; + + if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0) + goto cleanup; + + /* this provides the path to the VF's directory in sysfs, + * e.g. "/sys/class/net/enp2s0f0/virtfn3" + */ + if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0) + goto cleanup; + + /* and this gets the netdev name associated with it, which is a + * directory entry in [virtfnSysfsPath]/net, + * e.g. "/sys/class/net/enp2s0f0/virtfn3/net/enp2s11f4" - in this + * example the VF for enp2s0f0 vf#3 is "enp2s11f4". (If the VF + * isn't bound to a netdev driver, it won't have a netdev name, + * and vfname will be NULL). + */ + ret =3D virPCIGetNetName(virtfnSysfsPath, vfname); + + cleanup: + VIR_FREE(virtfnName); + VIR_FREE(virtfnSysfsPath); + + return ret; +} + + /** * virNetDevGetVirtualFunctionInfo: * @vfname: name of the virtual function interface @@ -1391,6 +1439,16 @@ virNetDevGetPhysicalFunction(const char *ifname ATTR= IBUTE_UNUSED, } =20 int +virNetDevPFGetVF(const char *pfname ATTRIBUTE_UNUSED, + int vf ATTRIBUTE_UNUSED, + char **vfname ATTRUBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Unable to get virtual function name on this pl= atform")); + return -1; +} + +int virNetDevGetVirtualFunctionInfo(const char *vfname ATTRIBUTE_UNUSED, char **pfname ATTRIBUTE_UNUSED, int *vf ATTRIBUTE_UNUSED) diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 236cf83..ecc28c8 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -178,6 +178,9 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname= , const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; + int virNetDevGetVirtualFunctions(const char *pfname, char ***vfname, virPCIDeviceAddressPtr **virt_fns, --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list