]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: drop several more cgroup version check
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Apr 2025 18:39:24 +0000 (03:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Apr 2025 18:56:04 +0000 (03:56 +0900)
src/core/bpf-firewall.c
src/core/bpf-util.c
src/core/cgroup.c
src/core/exec-invoke.c
src/core/execute.c
src/core/service.c
src/core/unit.c

index 26f50500cefb2c7e411314d5eeb2b5172cbd8b30..69000c1389f1225279736f4e40132224eabfcbdc 100644 (file)
@@ -845,23 +845,12 @@ int bpf_firewall_supported(void) {
 
         /* Checks whether BPF firewalling is supported. For this, we check the following things:
          *
-         * - whether the unified hierarchy is being used
          * - the BPF implementation in the kernel supports BPF_PROG_TYPE_CGROUP_SKB programs, which we require
          * - the BPF implementation in the kernel supports the BPF_PROG_DETACH call, which we require
          */
         if (supported >= 0)
                 return supported;
 
-        r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER);
-        if (r < 0)
-                return log_error_errno(r, "bpf-firewall: Can't determine whether the unified hierarchy is used: %m");
-        if (r == 0) {
-                bpf_firewall_unsupported_reason =
-                        log_debug_errno(SYNTHETIC_ERRNO(EUCLEAN),
-                                        "bpf-firewall: Not running with unified cgroup hierarchy, BPF firewalling is not supported.");
-                return supported = BPF_FIREWALL_UNSUPPORTED;
-        }
-
         /* prog_name is NULL since it is supported only starting from v4.15 kernel. */
         r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, NULL, &program);
         if (r < 0) {
index b337ba9afbd2f65d9bd5e7135863e779d1e90048..2c07a402cb9219b5e7bcb015da3cf6aacc488d72 100644 (file)
@@ -13,17 +13,6 @@ bool cgroup_bpf_supported(void) {
         if (supported >= 0)
                 return supported;
 
-        r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER);
-        if (r < 0) {
-                log_warning_errno(r, "Can't determine whether the unified hierarchy is used: %m");
-                return (supported = false);
-        }
-
-        if (r == 0) {
-                log_info("Not running with unified cgroup hierarchy, disabling cgroup BPF features.");
-                return (supported = false);
-        }
-
         r = dlopen_bpf();
         if (r < 0) {
                 log_full_errno(in_initrd() ? LOG_DEBUG : LOG_INFO,
index 6aa9f1fc3e7fe01b6bfc30de1118b57112d0b06c..e08652c76f35a83c12ecc93a4d712066782ed421 100644 (file)
@@ -1586,9 +1586,6 @@ void unit_modify_nft_set(Unit *u, bool add) {
         if (!UNIT_HAS_CGROUP_CONTEXT(u))
                 return;
 
-        if (cg_all_unified() <= 0)
-                return;
-
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
         if (!crt || crt->cgroup_id == 0)
                 return;
@@ -2243,13 +2240,6 @@ int unit_watch_cgroup(Unit *u) {
         if (crt->cgroup_control_inotify_wd >= 0)
                 return 0;
 
-        /* Only applies to the unified hierarchy */
-        r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER);
-        if (r < 0)
-                return log_error_errno(r, "Failed to determine whether the name=systemd hierarchy is unified: %m");
-        if (r == 0)
-                return 0;
-
         /* No point in watch the top-level slice, it's never going to run empty. */
         if (unit_has_name(u, SPECIAL_ROOT_SLICE))
                 return 0;
@@ -2310,13 +2300,6 @@ int unit_watch_cgroup_memory(Unit *u) {
         if (crt->cgroup_memory_inotify_wd >= 0)
                 return 0;
 
-        /* Only applies to the unified hierarchy */
-        r = cg_all_unified();
-        if (r < 0)
-                return log_error_errno(r, "Failed to determine whether the memory controller is unified: %m");
-        if (r == 0)
-                return 0;
-
         r = hashmap_ensure_allocated(&u->manager->cgroup_memory_inotify_wd_unit, &trivial_hash_ops);
         if (r < 0)
                 return log_oom();
index 9f2ce4d42b54f134b6b91fcbdeccf6174e973aa0..5809d28c8a7942513a68a7c148b095a24cd80743 100644 (file)
@@ -5210,7 +5210,7 @@ int exec_invoke(
                         }
                 }
 
-                if (cg_unified() > 0 && is_pressure_supported() > 0) {
+                if (is_pressure_supported() > 0) {
                         if (cgroup_context_want_memory_pressure(cgroup_context)) {
                                 r = cg_get_path("memory", params->cgroup_path, "memory.pressure", &memory_pressure_path);
                                 if (r < 0) {
index dade528b8cf5fcf93ea76fb1d9950137c7cb7540..32af8c51abd323ae0830fbee621165edb2ae2715 100644 (file)
@@ -576,7 +576,7 @@ int exec_spawn(
                                   "--log-level", max_log_levels,
                                   "--log-target", log_target_to_string(manager_get_executor_log_target(unit->manager))),
                         environ,
-                        cg_unified() > 0 ? subcgroup_path : NULL,
+                        subcgroup_path,
                         &pidref);
 
         /* Drop the ambient set again, so no processes other than sd-executore spawned from the manager inherit it. */
index c64fa06335e05afcaf27aced73e07e8d6e142af6..b835af1f3aa54ab9a95b29c9abc153b68ba9bfa1 100644 (file)
@@ -729,9 +729,6 @@ static int service_verify(Service *s) {
         if (s->type == SERVICE_SIMPLE && s->exec_command[SERVICE_EXEC_START_POST] && exec_context_has_credentials(&s->exec_context))
                 log_unit_warning(UNIT(s), "Service uses a combination of Type=simple, ExecStartPost=, and credentials. This could lead to race conditions. Continuing.");
 
-        if (s->exit_type == SERVICE_EXIT_CGROUP && cg_unified() < CGROUP_UNIFIED_SYSTEMD)
-                log_unit_warning(UNIT(s), "Service has ExitType=cgroup set, but we are running with legacy cgroups v1, which might not work correctly. Continuing.");
-
         if (s->restart_max_delay_usec == USEC_INFINITY && s->restart_steps > 0)
                 log_unit_warning(UNIT(s), "Service has RestartSteps= but no RestartMaxDelaySec= setting. Ignoring.");
 
index fa283a8b04afcd0990cdc63f0f6d9b5453fbd018..849ae46d074aebcb26def1e7dde5b5959c0b205c 100644 (file)
@@ -1571,9 +1571,6 @@ static int unit_add_oomd_dependencies(Unit *u) {
         if (!wants_oomd)
                 return 0;
 
-        if (!cg_all_unified())
-                return 0;
-
         r = cg_mask_supported(&mask);
         if (r < 0)
                 return log_debug_errno(r, "Failed to determine supported controllers: %m");
@@ -4808,16 +4805,7 @@ int unit_kill_context(Unit *u, KillOperation k) {
 
                 } else if (r > 0) {
 
-                        /* FIXME: For now, on the legacy hierarchy, we will not wait for the cgroup members to die if
-                         * we are running in a container or if this is a delegation unit, simply because cgroup
-                         * notification is unreliable in these cases. It doesn't work at all in containers, and outside
-                         * of containers it can be confused easily by left-over directories in the cgroup — which
-                         * however should not exist in non-delegated units. On the unified hierarchy that's different,
-                         * there we get proper events. Hence rely on them. */
-
-                        if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0 ||
-                            (detect_container() == 0 && !unit_cgroup_delegate(u)))
-                                wait_for_exit = true;
+                        wait_for_exit = true;
 
                         if (send_sighup) {
                                 r = unit_pid_set(u, &pid_set);