]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: fix cgroups v2 controllers detection
authorPavel Hrdina <phrdina@redhat.com>
Mon, 22 Jul 2019 12:37:36 +0000 (14:37 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 25 Jul 2019 08:50:44 +0000 (10:50 +0200)
When creating new group for cgroups v2 the we cannot check
cgroups.controllers for that cgroup because the directory is created
later.  In that case we should check cgroups.subtree_control of parent
group to get list of controllers enabled for child cgroups.

In order to achieve that we will prefer the parent group if it exists,
the current group will be used only for root group.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgroupv1.c
src/util/vircgroupv2.c

index 2270a520d67a0d2ebc8dcead68cd994796d712d2..825f62a97b9cf637cf3664fcbce0522ddf15ef31 100644 (file)
@@ -407,7 +407,7 @@ 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);
+            int rc = group->backends[i]->detectControllers(group, controllers, parent);
             if (rc < 0)
                 return -1;
             controllersAvailable |= rc;
index a91719f89df055e94c3ad6257ec56060dd85dc1b..77451b0cb63c6373b4793448ca0c30aabf80f0bc 100644 (file)
@@ -98,7 +98,8 @@ typedef char *
 
 typedef int
 (*virCgroupDetectControllersCB)(virCgroupPtr group,
-                                int controllers);
+                                int controllers,
+                                virCgroupPtr parent);
 
 typedef bool
 (*virCgroupHasControllerCB)(virCgroupPtr cgroup,
index 7968ab3cf02b05904683ec59fa16e13fb84c1734..4231d8d6faa303240ad82255e306cd4a57554c5c 100644 (file)
@@ -420,7 +420,8 @@ virCgroupV1StealPlacement(virCgroupPtr group)
 
 static int
 virCgroupV1DetectControllers(virCgroupPtr group,
-                             int controllers)
+                             int controllers,
+                             virCgroupPtr parent ATTRIBUTE_UNUSED)
 {
     size_t i;
     size_t j;
index 9d8a38925ad08999eaa0e28ddb539e30155adf8c..9c44b3473e07a70fb4b03c4c7c1d37bc7795a8f9 100644 (file)
@@ -242,7 +242,8 @@ virCgroupV2StealPlacement(virCgroupPtr group)
 
 
 static int
-virCgroupV2ParseControllersFile(virCgroupPtr group)
+virCgroupV2ParseControllersFile(virCgroupPtr group,
+                                virCgroupPtr parent)
 {
     int rc;
     VIR_AUTOFREE(char *) contStr = NULL;
@@ -250,10 +251,17 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
     char **contList = NULL;
     char **tmp;
 
-    if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
-                    group->unified.mountPoint,
-                    NULLSTR_EMPTY(group->unified.placement)) < 0)
-        return -1;
+    if (parent) {
+        if (virAsprintf(&contFile, "%s%s/cgroup.subtree_control",
+                        parent->unified.mountPoint,
+                        NULLSTR_EMPTY(parent->unified.placement)) < 0)
+            return -1;
+    } else {
+        if (virAsprintf(&contFile, "%s%s/cgroup.controllers",
+                        group->unified.mountPoint,
+                        NULLSTR_EMPTY(group->unified.placement)) < 0)
+            return -1;
+    }
 
     rc = virFileReadAll(contFile, 1024 * 1024, &contStr);
     if (rc < 0) {
@@ -286,11 +294,12 @@ virCgroupV2ParseControllersFile(virCgroupPtr group)
 
 static int
 virCgroupV2DetectControllers(virCgroupPtr group,
-                             int controllers)
+                             int controllers,
+                             virCgroupPtr parent)
 {
     size_t i;
 
-    if (virCgroupV2ParseControllersFile(group) < 0)
+    if (virCgroupV2ParseControllersFile(group, parent) < 0)
         return -1;
 
     /* In cgroup v2 there is no cpuacct controller, the cpu.stat file always