From nobody Sat Apr 27 20:23:39 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 1515431880935511.65536718186115; Mon, 8 Jan 2018 09:18:00 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB1E912BA1; Mon, 8 Jan 2018 17:17:58 +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 2039A60C96; Mon, 8 Jan 2018 17:17: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 9C42D18033D9; Mon, 8 Jan 2018 17:17:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w08H9Vhh013272 for ; Mon, 8 Jan 2018 12:09:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0C53B5D72E; Mon, 8 Jan 2018 17:09:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3E365D964 for ; Mon, 8 Jan 2018 17:09:27 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CC8A15DF for ; Mon, 8 Jan 2018 17:09:26 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Mon, 08 Jan 2018 10:09:24 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Mon, 8 Jan 2018 10:08:59 -0700 Message-Id: <20180108170859.19508-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 08 Jan 2018 17:09:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 08 Jan 2018 17:09:26 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: edand@mellanox.com Subject: [libvirt] [PATCH V2] nodedev: Fix failing to parse PCI address for non-PCI network devices 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 08 Jan 2018 17:17:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Based loosely on a patch from Fei Li . Commit 8708ca01c added virNetDevSwitchdevFeature() to check if a network device has Switchdev capabilities. virNetDevSwitchdevFeature() attempts to retrieve the PCI device associated with the network device, ignoring non-PCI devices. It does so via the following call chain virNetDevSwitchdevFeature()->virNetDevGetPCIDevice()-> virPCIGetDeviceAddressFromSysfsLink() For non-PCI network devices (qeth, Xen vif, etc), virPCIGetDeviceAddressFromSysfsLink() will report an error when virPCIDeviceAddressParse() fails. virPCIDeviceAddressParse() also logs an error. After commit 8708ca01c there are now two errors reported for each non-PCI network device even though the errors are harmless. To avoid changing virPCIGetDeviceAddressFromSysfsLink(), virPCIDeviceAddressParse() and related code that has quite a few call sites, add a function to check if a network device is a PCI device and use it in virNetDevSwitchdevFeature() before attempting to retrieve the PCI device. --- Suggestions welcome on a better name for virPCIIsPCIDevice, or even a better approach to solving this issue. Currently virPCIIsPCIDevice assumes the device is PCI if its subsystem starts with 'pci'. I'd be happy to hear if there is a better way to determine if a network device is PCI. src/libvirt_private.syms | 1 + src/util/virnetdev.c | 25 ++++++++++++++++++++++--- src/util/virpci.c | 32 ++++++++++++++++++++++++++++++++ src/util/virpci.h | 3 +++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a705fa846..bdf98ded1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2458,6 +2458,7 @@ virPCIGetVirtualFunctionInfo; virPCIGetVirtualFunctions; virPCIHeaderTypeFromString; virPCIHeaderTypeToString; +virPCIIsPCIDevice; virPCIIsVirtualFunction; virPCIStubDriverTypeFromString; virPCIStubDriverTypeToString; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index eb2d119bf..a9af08797 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1148,6 +1148,21 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link= , const char *ifname, } =20 =20 +static bool +virNetDevIsPCIDevice(const char *devName) +{ + char *vfSysfsDevicePath =3D NULL; + bool ret; + + if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device/subsystem"= ) < 0) + return false; + + ret =3D virPCIIsPCIDevice(vfSysfsDevicePath); + VIR_FREE(vfSysfsDevicePath); + return ret; +} + + static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { @@ -3236,14 +3251,18 @@ virNetDevSwitchdevFeature(const char *ifname, if (is_vf =3D=3D 1 && virNetDevGetPhysicalFunction(ifname, &pfname) < = 0) goto cleanup; =20 - pci_device_ptr =3D pfname ? virNetDevGetPCIDevice(pfname) : - virNetDevGetPCIDevice(ifname); + if (pfname =3D=3D NULL && VIR_STRDUP(pfname, ifname) < 0) + goto cleanup; + /* No PCI device, then no feature bit to check/add */ - if (pci_device_ptr =3D=3D NULL) { + if (!virNetDevIsPCIDevice(pfname)) { ret =3D 0; goto cleanup; } =20 + if ((pci_device_ptr =3D virNetDevGetPCIDevice(pfname)) =3D=3D NULL) + goto cleanup; + if (!(nl_msg =3D nlmsg_alloc_simple(family_id, NLM_F_REQUEST | NLM_F_ACK))) { virReportOOMError(); diff --git a/src/util/virpci.c b/src/util/virpci.c index fe57bef32..f22d89cd7 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2651,6 +2651,38 @@ virPCIGetDeviceAddressFromSysfsLink(const char *devi= ce_link) return bdf; } =20 +/** + * virPCIIsPCIDevice: + * @device_link: sysfs path for the device + * + * Returns true if the device specified in @device_link sysfs + * path is a PCI device, otherwise returns false. + */ +bool +virPCIIsPCIDevice(const char *device_link) +{ + char *device_path =3D NULL; + char *subsys =3D NULL; + bool ret; + + if (!virFileExists(device_link)) { + VIR_DEBUG("'%s' does not exist", device_link); + return false; + } + + device_path =3D canonicalize_file_name(device_link); + if (device_path =3D=3D NULL) { + VIR_DEBUG("Failed to resolve device link '%s'", device_link); + return false; + } + + subsys =3D last_component(device_path); + ret =3D STRPREFIX(subsys, "pci"); + + VIR_FREE(device_path); + return ret; +} + /** * virPCIGetPhysicalFunction: * @vf_sysfs_path: sysfs path for the virtual function diff --git a/src/util/virpci.h b/src/util/virpci.h index f1fbe39e6..489d8a777 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -190,6 +190,9 @@ int virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, con= st char *matcher); virPCIDeviceAddressPtr virPCIGetDeviceAddressFromSysfsLink(const char *device_link); =20 +bool +virPCIIsPCIDevice(const char *device_link); + int virPCIGetPhysicalFunction(const char *vf_sysfs_path, virPCIDeviceAddressPtr *pf); =20 --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list