[libvirt] [PATCH v2 2/6] util: vircgroup: improve controller detection

Pavel Hrdina phrdina at redhat.com
Fri Jun 21 13:32:42 UTC 2019


This affects only cgroups v2 where enabled controllers are not based on
available mount points but on the list provided in cgroup.controllers
file.

Before this patch we were assuming that all controllers available in
root cgroup where available in all other sub-cgroups which was wrong.

In order to fix it we need to move the cgroup controllers detection
after cgroup placement was prepared in order to build correct path for
cgroup.controllers file.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
---
 src/util/vircgroup.c   | 32 ++++++++++++++++----------------
 src/util/vircgroupv2.c |  5 +++--
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b7e5f03521..da506fc0b0 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -381,22 +381,6 @@ virCgroupDetect(virCgroupPtr group,
             return -1;
     }
 
-    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
-        if (group->backends[i]) {
-            int rc = group->backends[i]->detectControllers(group, controllers, parent);
-            if (rc < 0)
-                return -1;
-            controllersAvailable |= rc;
-        }
-    }
-
-    /* Check that at least 1 controller is available */
-    if (controllersAvailable == 0) {
-        virReportSystemError(ENXIO, "%s",
-                             _("At least one cgroup controller is required"));
-        return -1;
-    }
-
     /* In some cases we can copy part of the placement info
      * based on the parent cgroup...
      */
@@ -421,6 +405,22 @@ virCgroupDetect(virCgroupPtr group,
         }
     }
 
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
+        if (group->backends[i]) {
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
+            if (rc < 0)
+                return -1;
+            controllersAvailable |= rc;
+        }
+    }
+
+    /* Check that at least 1 controller is available */
+    if (controllersAvailable == 0) {
+        virReportSystemError(ENXIO, "%s",
+                             _("At least one cgroup controller is required"));
+        return -1;
+    }
+
     return 0;
 }
 
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 2d09d77a29..29b5806a01 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -250,8 +250,9 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
     char **contList = NULL;
     char **tmp;
 
-    if (virAsprintf(&contFile, "%s/cgroup.controllers",
-                    group->unified.mountPoint) < 0)
+    if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
+                    group->unified.mountPoint,
+                    NULLSTR_EMPTY(group->unified.placement)) < 0)
         return -1;
 
     rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
-- 
2.21.0




More information about the libvir-list mailing list