]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: drop cgroup v1 support from cg_mask_supported_subtree()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Aug 2025 21:57:13 +0000 (06:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 17 Nov 2025 12:30:29 +0000 (21:30 +0900)
We have dropped cgroup v1 support in v258. Let's drop unused legacy code.

src/basic/cgroup-util.c

index 91c230208d30e5cb03fe074630276c6bd7bf645a..f811be5a915955c1bf8bd527c3eaa5b20ba254c3 100644 (file)
@@ -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;