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@xxxxxxxxxx> --- 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) } 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 (ent->d_type != 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 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') @@ -1169,6 +1190,32 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) goto error; while ((rv = virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH)) > 0) { + struct stat st; + char *path = 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 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_type != DT_DIR) continue; -- 2.16.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list