]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: cgroup v2 – enable controller at the leaf node
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 20 Dec 2022 16:09:02 +0000 (21:39 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 6 Jan 2023 15:28:47 +0000 (08:28 -0700)
With cgroup v2, while creating a cgroup with a controller, the whole
hierarchy tree is walked, and the controller is enabled up to the parent
cgroup of the leaf node, this guarantees that the attached controller is
available in the leaf cgroups cgroup.controllers file, but this is
incomplete because the controller is not enabled in the leaf cgroup.

We do not have a separate API that is called to enable the controllers
but as a workaround, one can always call the
cgroup_set_values_recursive() to enable the controller in the leaf node.
To maintain the idea/compatibility with the cgroup v1, where creating a
cgroup on the controller mount point/hierarchy is equivalent to enabling
the controller in the cgroup v2, let's enable the controller in the leaf
node too.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 2354704ff739326b6d3251c76d1ef8e3c6621be7..cd0b5e4d019f2be188f833f02e3e7c5bf53c6ea8 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2706,6 +2706,12 @@ static int _cgroup_create_cgroup(const struct cgroup * const cgroup,
                goto err;
 
        if (controller) {
+               if (version == CGROUP_V2) {
+                       error = cgroupv2_subtree_control(base, controller->name, true);
+                       if (error)
+                               goto err;
+               }
+
                error = cgroup_set_values_recursive(base, controller, false);
                if (error)
                        goto err;