Blame SOURCES/libvirt-util-Don-t-check-if-entries-under-sys-fs-resctrl-info-are-directories.patch

404507
From eaeaf49524c3b7f26afb86bdeddba8d86bce4790 Mon Sep 17 00:00:00 2001
404507
Message-Id: <eaeaf49524c3b7f26afb86bdeddba8d86bce4790@dist-git>
404507
From: Martin Kletzander <mkletzan@redhat.com>
404507
Date: Wed, 31 Jan 2018 16:32:39 +0100
404507
Subject: [PATCH] util: Don't check if entries under /sys/fs/resctrl/(info/)
404507
 are directories
404507
404507
We are skipping non-directories under /sys/fs/resctrl/(info/) since those are not
404507
interesting for us.  However in tests it can sometimes happen that ent->d_type
404507
is 0 instead of 4 (DT_DIR) for directories.
404507
404507
I've seen it fail on two machines.  Different machines, different systems, I
404507
cannot reproduce it even using the same setup.  So one of the ways how to work
404507
around this is call stat() on it.  The other one is not checking if it is a
404507
directory since we'll find out eventually when we want to read some files
404507
underneath it.
404507
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
(cherry picked from commit f2e16994f7d660a54daba1059441dc0dcf4d9cbd)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
---
404507
 src/util/virresctrl.c | 27 +++++++++++++++------------
404507
 1 file changed, 15 insertions(+), 12 deletions(-)
404507
404507
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
404507
index 684cb22fd8..42876c6e2b 100644
404507
--- a/src/util/virresctrl.c
404507
+++ b/src/util/virresctrl.c
404507
@@ -410,10 +410,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
404507
 
404507
     while ((rv = virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH "/info")) > 0) {
404507
         VIR_DEBUG("Parsing info type '%s'", ent->d_name);
404507
-
404507
-        if (ent->d_type != DT_DIR)
404507
-            continue;
404507
-
404507
         if (ent->d_name[0] != 'L')
404507
             continue;
404507
 
404507
@@ -436,19 +432,29 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
404507
         rv = virFileReadValueUint(&i_type->control.max_allocation,
404507
                                   SYSFS_RESCTRL_PATH "/info/%s/num_closids",
404507
                                   ent->d_name);
404507
-        if (rv == -2)
404507
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
-                           _("Cannot get num_closids from resctrl cache info"));
404507
-        if (rv < 0)
404507
+        if (rv == -2) {
404507
+            /* The file doesn't exist, so it's unusable for us,
404507
+             *  but we can scan further */
404507
+            VIR_WARN("The path '" SYSFS_RESCTRL_PATH "/info/%s/num_closids' "
404507
+                     "does not exist",
404507
+                     ent->d_name);
404507
+        } else if (rv < 0) {
404507
+            /* Other failures are fatal, so just quit */
404507
             goto cleanup;
404507
+        }
404507
 
404507
         rv = virFileReadValueString(&i_type->cbm_mask,
404507
                                     SYSFS_RESCTRL_PATH
404507
                                     "/info/%s/cbm_mask",
404507
                                     ent->d_name);
404507
-        if (rv == -2)
404507
+        if (rv == -2) {
404507
+            /* If the previous file exists, so should this one.  Hence -2 is
404507
+             * fatal in this case as well (errors out in next condition) - the
404507
+             * kernel interface might've changed too much or something else is
404507
+             * wrong. */
404507
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
404507
                            _("Cannot get cbm_mask from resctrl cache info"));
404507
+        }
404507
         if (rv < 0)
404507
             goto cleanup;
404507
 
404507
@@ -1169,9 +1175,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
404507
         goto error;
404507
 
404507
     while ((rv = virDirRead(dirp, &ent, SYSFS_RESCTRL_PATH)) > 0) {
404507
-        if (ent->d_type != DT_DIR)
404507
-            continue;
404507
-
404507
         if (STREQ(ent->d_name, "info"))
404507
             continue;
404507
 
404507
-- 
404507
2.16.1
404507