From: Kamalesh Babulal Date: Tue, 20 Dec 2022 16:09:02 +0000 (+0530) Subject: api: cgroup v2 – enable controller at the leaf node X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28f2c34c0f1e39c41027969bd984b183f5e37b3e;p=thirdparty%2Flibcgroup.git api: cgroup v2 – enable controller at the leaf node 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 --- 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;