From: Yu Watanabe Date: Fri, 29 Aug 2025 21:57:13 +0000 (+0900) Subject: cgroup-util: drop cgroup v1 support from cg_mask_supported_subtree() X-Git-Tag: v259-rc1~18^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=57c16d344b6fcdf34de1141f3fbb9dcfa3bfd3ee;p=thirdparty%2Fsystemd.git cgroup-util: drop cgroup v1 support from cg_mask_supported_subtree() We have dropped cgroup v1 support in v258. Let's drop unused legacy code. --- diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 91c230208d3..f811be5a915 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -560,21 +560,6 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch return 0; } -static int controller_is_v1_accessible(const char *root, const char *controller) { - const char *cpath, *dn; - - assert(controller); - - dn = controller_to_dirname(controller); - - /* If root if specified, we check that: - * - possible subcgroup is created at root, - * - we can modify the hierarchy. */ - - cpath = strjoina("/sys/fs/cgroup/", dn, root, root ? "/cgroup.procs" : NULL); - return access_nofollow(cpath, root ? W_OK : F_OK); -} - int cg_set_xattr(const char *path, const char *name, const void *value, size_t size, int flags) { _cleanup_free_ char *fs = NULL; int r; @@ -1814,48 +1799,22 @@ int cg_mask_supported_subtree(const char *root, CGroupMask *ret) { * are actually accessible. Only covers real controllers, i.e. not the CGROUP_CONTROLLER_BPF_xyz * pseudo-controllers. */ - r = cg_all_unified(); + /* We can read the supported and accessible controllers from the top-level cgroup attribute */ + _cleanup_free_ char *controllers = NULL, *path = NULL; + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path); if (r < 0) return r; - if (r > 0) { - _cleanup_free_ char *controllers = NULL, *path = NULL; - - /* In the unified hierarchy we can read the supported and accessible controllers from - * the top-level cgroup attribute */ - - r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path); - if (r < 0) - return r; - - r = read_one_line_file(path, &controllers); - if (r < 0) - return r; - - r = cg_mask_from_string(controllers, &mask); - if (r < 0) - return r; - - /* Mask controllers that are not supported in unified hierarchy. */ - mask &= CGROUP_MASK_V2; - - } else { - CGroupController c; - - /* In the legacy hierarchy, we check which hierarchies are accessible. */ - mask = 0; - for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) { - CGroupMask bit = CGROUP_CONTROLLER_TO_MASK(c); - const char *n; + r = read_one_line_file(path, &controllers); + if (r < 0) + return r; - if (!FLAGS_SET(CGROUP_MASK_V1, bit)) - continue; + r = cg_mask_from_string(controllers, &mask); + if (r < 0) + return r; - n = cgroup_controller_to_string(c); - if (controller_is_v1_accessible(root, n) >= 0) - mask |= bit; - } - } + /* Mask controllers that are not supported in cgroup v2. */ + mask &= CGROUP_MASK_V2; *ret = mask; return 0;