]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/cgroup: drop unnecessary cgroup version check in several getters
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 6 Apr 2025 18:16:53 +0000 (03:16 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Apr 2025 18:25:46 +0000 (03:25 +0900)
After 2b61489e5a53eb2611e1e573519c209ca07de98e, these checks are not
necessary anymore.

src/core/cgroup.c

index d55c50b3180e3c06540c4c44b07cd6c250073f8d..e1371c94f35893fc635bc84b936c2337d2b11dc6 100644 (file)
@@ -537,8 +537,7 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_
         uint64_t unit_value;
         int r;
 
-        /* Compare kernel memcg configuration against our internal systemd state. Unsupported (and will
-         * return -ENODATA) on cgroup v1.
+        /* Compare kernel memcg configuration against our internal systemd state.
          *
          * Returns:
          *
@@ -553,17 +552,6 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_
 
         assert(u);
 
-        r = cg_all_unified();
-        if (r < 0)
-                return log_debug_errno(r, "Failed to determine cgroup hierarchy version: %m");
-
-        /* Unsupported on v1.
-         *
-         * We don't return ENOENT, since that could actually mask a genuine problem where somebody else has
-         * silently masked the controller. */
-        if (r == 0)
-                return -ENODATA;
-
         /* The root slice doesn't have any controller files, so we can't compare anything. */
         if (unit_has_name(u, SPECIAL_ROOT_SLICE))
                 return -ENODATA;
@@ -2047,22 +2035,13 @@ CGroupMask unit_get_own_mask(Unit *u) {
 CGroupMask unit_get_delegate_mask(Unit *u) {
         CGroupContext *c;
 
-        /* If delegation is turned on, then turn on selected controllers, unless we are on the legacy hierarchy and the
-         * process we fork into is known to drop privileges, and hence shouldn't get access to the controllers.
+        /* If delegation is turned on, then turn on selected controllers.
          *
          * Note that on the unified hierarchy it is safe to delegate controllers to unprivileged services. */
 
         if (!unit_cgroup_delegate(u))
                 return 0;
 
-        if (cg_all_unified() <= 0) {
-                ExecContext *e;
-
-                e = unit_get_exec_context(u);
-                if (e && !exec_context_maintains_privileges(e))
-                        return 0;
-        }
-
         assert_se(c = unit_get_cgroup_context(u));
         return CGROUP_MASK_EXTEND_JOINED(c->delegate_controllers);
 }
@@ -3376,12 +3355,6 @@ int unit_check_oomd_kill(Unit *u) {
         if (!crt || !crt->cgroup_path)
                 return 0;
 
-        r = cg_all_unified();
-        if (r < 0)
-                return log_unit_debug_errno(u, r, "Couldn't determine whether we are in all unified mode: %m");
-        if (r == 0)
-                return 0;
-
         r = cg_get_xattr_malloc(crt->cgroup_path, "user.oomd_ooms", &value, /* ret_size= */ NULL);
         if (r < 0 && !ERRNO_IS_XATTR_ABSENT(r))
                 return r;
@@ -4007,12 +3980,6 @@ static int unit_get_cpu_usage_raw(const Unit *u, const CGroupRuntime *crt, nsec_
         if ((get_cpu_accounting_mask() & ~crt->cgroup_realized_mask) != 0)
                 return -ENODATA;
 
-        r = cg_all_unified();
-        if (r < 0)
-                return r;
-        if (r == 0)
-                return cg_get_attribute_as_uint64("cpuacct", crt->cgroup_path, "cpuacct.usage", ret);
-
         _cleanup_free_ char *val = NULL;
         uint64_t us;
 
@@ -4133,8 +4100,6 @@ static uint64_t unit_get_effective_limit_one(Unit *u, CGroupLimitType type) {
 
         cc = ASSERT_PTR(unit_get_cgroup_context(u));
         switch (type) {
-                /* Note: on legacy/hybrid hierarchies memory_max stays CGROUP_LIMIT_MAX unless configured
-                 * explicitly. Effective value of MemoryLimit= (cgroup v1) is not implemented. */
                 case CGROUP_LIMIT_MEMORY_MAX:
                         return cc->memory_max;
                 case CGROUP_LIMIT_MEMORY_HIGH:
@@ -4191,12 +4156,6 @@ static int unit_get_io_accounting_raw(
         if (unit_has_host_root_cgroup(u))
                 return -ENODATA; /* TODO: return useful data for the top-level cgroup */
 
-        r = cg_all_unified();
-        if (r < 0)
-                return r;
-        if (r == 0)
-                return -ENODATA;
-
         if (!FLAGS_SET(crt->cgroup_realized_mask, CGROUP_MASK_IO))
                 return -ENODATA;
 
@@ -4589,12 +4548,6 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) {
         if ((crt->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0)
                 return -ENODATA;
 
-        r = cg_all_unified();
-        if (r < 0)
-                return r;
-        if (r == 0)
-                return -ENODATA;
-
         r = cg_get_attribute("cpuset", crt->cgroup_path, name, &v);
         if (r == -ENOENT)
                 return -ENODATA;