From bb291add5db87fe36a82a18c6eb6aaf64dc07694 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 20 Dec 2022 21:39:02 +0530 Subject: [PATCH] =?utf8?q?api:=20cgroup=20v2=20=E2=80=93=20enable=20contro?= =?utf8?q?ller=20at=20the=20leaf=20node?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Tom Hromatka --- src/api.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api.c b/src/api.c index 2354704f..cd0b5e4d 100644 --- 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; -- 2.47.3