From nobody Thu May 15 04:10:16 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 1516872392911638.6594110456113; Thu, 25 Jan 2018 01:26:32 -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 11E0881DF4; Thu, 25 Jan 2018 09:26:32 +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 C7FC7609A5; Thu, 25 Jan 2018 09:26:31 +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 81A3118033D9; Thu, 25 Jan 2018 09:26:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0P9QTk1000980 for ; Thu, 25 Jan 2018 04:26:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id C53CB2C317; Thu, 25 Jan 2018 09:26:29 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64B3A2C7A2; Thu, 25 Jan 2018 09:25:46 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:59 +0100 Message-Id: <3bead6533469e008107b2f1d5586030d6a819b0a.1516872173.git.eskultet@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH 12/15] util: pci: Introduce virPCIGetMdevTypes helper 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.25]); Thu, 25 Jan 2018 09:26:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a replacement for the existing udevPCIGetMdevTypesCap which is static to the udev backend. This simple helper constructs the sysfs path from the device's base path for each mdev type and queries the corresponding attributes of that type. Signed-off-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/util/virpci.c | 58 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virpci.h | 4 ++++ 3 files changed, 63 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 75eaf1d4c..8d4c8dd3f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2456,6 +2456,7 @@ virPCIDeviceWaitForCleanup; virPCIEDeviceInfoFree; virPCIGetDeviceAddressFromSysfsLink; virPCIGetHeaderType; +virPCIGetMdevTypes; virPCIGetNetName; virPCIGetPhysicalFunction; virPCIGetVirtualFunctionIndex; diff --git a/src/util/virpci.c b/src/util/virpci.c index fe57bef32..12d7ef0e4 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3027,6 +3027,64 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_de= vice_path, return ret; } =20 + +int +virPCIGetMdevTypes(const char *sysfspath, + virMediatedDeviceTypePtr **types) +{ + int ret =3D -1; + int dirret =3D -1; + DIR *dir =3D NULL; + struct dirent *entry; + char *types_path =3D NULL; + char *tmppath =3D NULL; + virMediatedDeviceTypePtr mdev_type =3D NULL; + virMediatedDeviceTypePtr *mdev_types =3D NULL; + size_t ntypes =3D 0; + size_t i; + + if (virAsprintf(&types_path, "%s/mdev_supported_types", sysfspath) < 0) + return -1; + + if ((dirret =3D virDirOpenIfExists(&dir, types_path)) < 0) + goto cleanup; + + if (dirret =3D=3D 0) { + ret =3D 0; + goto cleanup; + } + + while ((dirret =3D virDirRead(dir, &entry, types_path)) > 0) { + /* append the type id to the path and read the attributes from the= re */ + if (virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name) < 0) + goto cleanup; + + if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0) + goto cleanup; + + if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0) + goto cleanup; + + VIR_FREE(tmppath); + } + + if (dirret < 0) + goto cleanup; + + VIR_STEAL_PTR(*types, mdev_types); + ret =3D ntypes; + ntypes =3D 0; + cleanup: + virMediatedDeviceTypeFree(mdev_type); + for (i =3D 0; i < ntypes; i++) + virMediatedDeviceTypeFree(mdev_types[i]); + VIR_FREE(mdev_types); + VIR_FREE(types_path); + VIR_FREE(tmppath); + VIR_DIR_CLOSE(dir); + return ret; +} + #else static const char *unsupported =3D N_("not supported on non-linux platform= s"); =20 diff --git a/src/util/virpci.h b/src/util/virpci.h index f1fbe39e6..a0bc0a474 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -25,6 +25,7 @@ # define __VIR_PCI_H__ =20 # include "internal.h" +# include "virmdev.h" # include "virobject.h" # include "virutil.h" =20 @@ -249,4 +250,7 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrTy= pe); =20 void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); =20 +int virPCIGetMdevTypes(const char *sysfspath, + virMediatedDeviceType ***types); + #endif /* __VIR_PCI_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list