From nobody Fri May 3 11:08:06 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 1516211363835671.22139162438; Wed, 17 Jan 2018 09:49:23 -0800 (PST) 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 14BFCC057F9F; Wed, 17 Jan 2018 17:49:16 +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 F051D17C24; Wed, 17 Jan 2018 17:49:13 +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 3FCFB4ED37; Wed, 17 Jan 2018 17:49:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0HHlBmY008822 for ; Wed, 17 Jan 2018 12:47:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 507126090C; Wed, 17 Jan 2018 17:47:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 493236FDDA for ; Wed, 17 Jan 2018 17:47:08 +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 39ED950F5A for ; Wed, 17 Jan 2018 17:47:06 +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); Wed, 17 Jan 2018 10:46:53 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Wed, 17 Jan 2018 10:46:32 -0700 Message-Id: <20180117174632.29046-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.30]); Wed, 17 Jan 2018 17:47:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 17 Jan 2018 17:47:06 +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.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: fli@suse.com Subject: [libvirt] [PATCH V3] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 17 Jan 2018 17:49:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 the errors, introduce virNetDevIsPCIDevice() and use it in virNetDevGetPCIDevice() before attempting to retrieve the associated PCI device. virNetDevIsPCIDevice() uses the 'subsystem' property of the device to determine if it is PCI. See the sysfs rules in kernel documentation for more details https://www.kernel.org/doc/html/latest/admin-guide/sysfs-rules.html Reviewed-by: Erik Skultety (but I'd wait with pushing --- V2: https://www.redhat.com/archives/libvir-list/2018-January/msg00233.html Changes in V3: Implement checking if netdev is PCI in virnetdev.c instead of virpci.c Addressed other comments from eskultet src/util/virnetdev.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index eb2d119bf..baf4a71fe 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -22,6 +22,7 @@ =20 #include =20 +#include "dirname.h" #include "virnetdev.h" #include "virnetlink.h" #include "virmacaddr.h" @@ -1147,6 +1148,48 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link= , const char *ifname, return 0; } =20 +/** + * Determine if the device path specified in devpath is a PCI Device + * by resolving the 'subsystem'-link in devpath and looking for + * 'pci' in the last component. For more information see the rules + * for accessing sysfs in the kernel docs + * + * https://www.kernel.org/doc/html/latest/admin-guide/sysfs-rules.html + * + * Returns true if devpath's susbsystem is pci, false otherwise. + */ +static bool +virNetDevIsPCIDevice(const char *devpath) +{ + char *subsys_link =3D NULL; + char *abs_path =3D NULL; + char *subsys =3D NULL; + bool ret =3D false; + + if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0) + return false; + + if (!virFileExists(subsys_link)) + goto cleanup; + + if (virFileIsLink(subsys_link) !=3D 1) + goto cleanup; + + if (virFileResolveLink(subsys_link, &abs_path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to resolve device subsystem symlink %s"), + subsys_link); + goto cleanup; + } + + subsys =3D last_component(abs_path); + ret =3D STRPREFIX(subsys, "pci"); + + cleanup: + VIR_FREE(subsys_link); + VIR_FREE(abs_path); + return ret; +} =20 static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) @@ -1158,6 +1201,9 @@ virNetDevGetPCIDevice(const char *devName) if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) goto cleanup; =20 + if (!virNetDevIsPCIDevice(vfSysfsDevicePath)) + goto cleanup; + vfPCIAddr =3D virPCIGetDeviceAddressFromSysfsLink(vfSysfsDevicePath); if (!vfPCIAddr) goto cleanup; --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list