From nobody Thu May 15 04:07:09 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 1516872349184259.49344268007326; Thu, 25 Jan 2018 01:25:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4030876540; Thu, 25 Jan 2018 09:25:48 +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 1B71F5C89F; Thu, 25 Jan 2018 09:25:48 +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 D72DC3FB1D; Thu, 25 Jan 2018 09:25:47 +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 w0P9Pk0S000519 for ; Thu, 25 Jan 2018 04:25:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46C1D2C316; Thu, 25 Jan 2018 09:25:46 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB3CE2C325; Thu, 25 Jan 2018 09:25:37 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 10:23:58 +0100 Message-Id: <1772f4644bcee90619f959ac087b8cd7196cc368.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 11/15] util: mdev: Introduce virMediatedDeviceTypeReadAttrs getter 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 25 Jan 2018 09:25:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This should serve as a replacement for the existing udevFillMdevType which is responsible for fetching the device type's attributes from the sysfs interface. The problem with the existing solution is that it's tied to the udev backend. Signed-off-by: Erik Skultety --- src/util/virmdev.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virmdev.h | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index db679b8a6..b57cc3ed9 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -496,3 +496,37 @@ virMediatedDeviceTypeFree(virMediatedDeviceTypePtr typ= e) VIR_FREE(type->device_api); VIR_FREE(type); } + + +int +virMediatedDeviceTypeReadAttrs(const char *sysfspath, + virMediatedDeviceTypePtr *type) +{ + int ret =3D -1; + virMediatedDeviceTypePtr tmp =3D NULL; + +#define MDEV_GET_SYSFS_ATTR(attr, dst, cb) \ + do { \ + if (cb(dst, "%s/%s", sysfspath, attr) < 0) \ + goto cleanup; \ + } while (0) \ + + if (VIR_ALLOC(tmp) < 0) + goto cleanup; + + if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) + goto cleanup; + + MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString); + MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api, virFileReadValueSt= ring); + MDEV_GET_SYSFS_ATTR("available_instances", &tmp->available_instances, + virFileReadValueUint); + +#undef MDEV_GET_SYSFS_ATTR + + VIR_STEAL_PTR(*type, tmp); + ret =3D 0; + cleanup: + virMediatedDeviceTypeFree(tmp); + return ret; +} diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 320610ab9..01ab02e75 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -129,4 +129,9 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListP= tr dst, =20 void virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type); + +int +virMediatedDeviceTypeReadAttrs(const char *sysfspath, + virMediatedDeviceTypePtr *type); + #endif /* __VIR_MDEV_H__ */ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list