[libvirt] [PATCH 4.5/4 variant 2] util: Use stat() on files under /sys/fs/resctrl/info

Martin Kletzander posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/024a75c710d412d1a32e42782b69239f9c7c6d30.1517240003.git.mkletzan@redhat.com
There is a newer version of this series
src/util/virresctrl.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
[libvirt] [PATCH 4.5/4 variant 2] util: Use stat() on files under /sys/fs/resctrl/info
Posted by Martin Kletzander 6 years, 2 months ago
We are skipping non-directories under /sys/fs/resctrl/info/ since those are not
interesting for us.  However in tests it can sometimes happen that ent->d_type
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 work
around this is call stat() on it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/util/virresctrl.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 684cb22fd8a2..12dda76f9d33 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -409,11 +409,32 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
     }

     while ((rv = virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0) {
+        struct stat st;
+        char *path = NULL;
+
         VIR_DEBUG("Parsing info type '%s'", ent->d_name);

+        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 syscalls in tests
+
         if (ent->d_type != DT_DIR)
             continue;

+           But the following does, for some reason.
+        */
+        if ((st.st_mode & S_IFMT) != S_IFDIR)
+            continue;
+
         if (ent->d_name[0] != 'L')
             continue;

--
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list