From nobody Mon Dec 15 01:56:01 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 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