From nobody Sun Apr 28 17:53:04 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520261037822375.75410223189203; Mon, 5 Mar 2018 06:43:57 -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 A05982823E; Mon, 5 Mar 2018 14:43:55 +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 975DC5C8AA; Mon, 5 Mar 2018 14:43:53 +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 6546818033EB; Mon, 5 Mar 2018 14:43:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w25EhpUl016206 for ; Mon, 5 Mar 2018 09:43:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 414A22024CAB; Mon, 5 Mar 2018 14:43:51 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD7E82026E03; Mon, 5 Mar 2018 14:43:50 +0000 (UTC) From: Erik Skultety To: libvir-list@redhat.com Date: Mon, 5 Mar 2018 15:43:45 +0100 Message-Id: <1dece353ebe8f1416614ee2edb4d357a282be210.1520260980.git.eskultet@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH] util: mdev: Treat the 'name' sysfs attribute as optional 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.30]); Mon, 05 Mar 2018 14:43:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When commit 3545cbef moved the sysfs attribute reading logic from _udev.c module to virmdev.c, it had to replace our udev read wrappers with the ones available from virfile.c. The problem is that the original logic worked correctly with udev read wrappers which don't return an error code for a missing attribute, virfile.c readers however - not so much. Therefore add another parameter to the macro, so we can again accept the fact that optional attributes may be missing. Signed-off-by: Erik Skultety Reviewed-by: John Ferlan --- src/util/virmdev.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 124933506..688f2efb5 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -505,10 +505,13 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, int ret =3D -1; virMediatedDeviceTypePtr tmp =3D NULL; =20 -#define MDEV_GET_SYSFS_ATTR(attr, dst, cb) \ +#define MDEV_GET_SYSFS_ATTR(attr, dst, cb, optional) \ do { \ - if (cb(dst, "%s/%s", sysfspath, attr) < 0) \ - goto cleanup; \ + errno =3D 0; \ + if (cb(dst, "%s/%s", sysfspath, attr) < 0) { \ + if (errno !=3D ENOENT || !optional) \ + goto cleanup; \ + } \ } while (0) =20 if (VIR_ALLOC(tmp) < 0) @@ -517,10 +520,12 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) goto cleanup; =20 - MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString); - MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api, virFileReadValueSt= ring); + /* @name sysfs attribute is optional, so getting ENOENT is fine */ + MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true); + MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api, + virFileReadValueString, false); MDEV_GET_SYSFS_ATTR("available_instances", &tmp->available_instances, - virFileReadValueUint); + virFileReadValueUint, false); =20 #undef MDEV_GET_SYSFS_ATTR =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list