From nobody Sun Apr 28 04:21:09 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 1517244333543330.79949813244457; Mon, 29 Jan 2018 08:45:33 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFC023E50B; Mon, 29 Jan 2018 16:45:31 +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 1CA911825C; Mon, 29 Jan 2018 16:45: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 B865518033DD; Mon, 29 Jan 2018 16:45:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0TGjRI8014670 for ; Mon, 29 Jan 2018 11:45:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5D6A878E84; Mon, 29 Jan 2018 16:45:27 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 316E178E9C for ; Mon, 29 Jan 2018 16:45:05 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 2C17E1200FE for ; Mon, 29 Jan 2018 17:45:04 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 29 Jan 2018 17:45:01 +0100 Message-Id: <51b20206e8bea823e0b206d3458c5d40dad1025b.1517244250.git.mkletzan@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4.5/4 variant 2] util: Use stat() on files under /sys/fs/resctrl/info 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 29 Jan 2018 16:45:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We are skipping non-directories under /sys/fs/resctrl/(info/) since those a= re not interesting for us. However in tests it can sometimes happen that ent->d_t= ype is 0 instead of 4 (DT_DIR) for directories. I've seen it fail on two machines. Different machines, different systems, I cannot reproduce it even using the same setup. So one of the ways how to w= ork around this is call stat() on it. Signed-off-by: Martin Kletzander --- src/util/virresctrl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++= +- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 684cb22fd8a2..2c1d07ff3a25 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -409,9 +409,30 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) } =20 while ((rv =3D virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0= ) { + struct stat st; + char *path =3D NULL; + VIR_DEBUG("Parsing info type '%s'", ent->d_name); =20 - if (ent->d_type !=3D DT_DIR) + if (virAsprintf(&path, SYSFS_RESCTRL_PATH "/info/%s", ent->d_name)= < 0) + continue; + + if (stat(path, &st) < 0) { + virReportSystemError(errno, _("Cannot stat '%s'"), path); + VIR_FREE(path); + continue; + } + VIR_FREE(path); + + /* + * So this doesn't work on some machines when we're mocking syscal= ls in tests + * + * if (ent->d_type !=3D DT_DIR) + * continue; + * + * But the following does, for some reason. + */ + if ((st.st_mode & S_IFMT) !=3D S_IFDIR) continue; =20 if (ent->d_name[0] !=3D 'L') @@ -1169,6 +1190,32 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto error; =20 while ((rv =3D virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH)) > 0) { + struct stat st; + char *path =3D NULL; + + VIR_DEBUG("Parsing info type '%s'", ent->d_name); + + if (virAsprintf(&path, SYSFS_RESCTRL_PATH "/%s", ent->d_name) < 0) + continue; + + if (stat(path, &st) < 0) { + virReportSystemError(errno, _("Cannot stat '%s'"), path); + VIR_FREE(path); + continue; + } + VIR_FREE(path); + + /* + * So this doesn't work on some machines when we're mocking syscal= ls in tests + * + * if (ent->d_type !=3D DT_DIR) + * continue; + * + * But the following does, for some reason. + */ + if ((st.st_mode & S_IFMT) !=3D S_IFDIR) + continue; + if (ent->d_type !=3D DT_DIR) continue; =20 --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list