cgroup-setup: drop unnecessary controller argument

This also removes unnecessary cg_{create,attach,trim}_everywhere(),
and rename cg_enable_everywhere() -> cg_enable().
This commit is contained in:
Yu Watanabe
2025-04-16 03:56:04 +09:00
parent c35a585763
commit 188286eec6
13 changed files with 63 additions and 95 deletions
+8 -8
View File
@@ -2379,7 +2379,7 @@ static int unit_update_cgroup(
CGroupRuntime *crt = ASSERT_PTR(unit_get_cgroup_runtime(u));
/* First, create our own group */
r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, crt->cgroup_path);
r = cg_create(crt->cgroup_path);
if (r < 0)
return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(crt->cgroup_path));
created = r;
@@ -2405,7 +2405,7 @@ static int unit_update_cgroup(
CGroupMask result_mask = 0;
/* Enable all controllers we need */
r = cg_enable_everywhere(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask);
r = cg_enable(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask);
if (r < 0)
log_unit_warning_errno(u, r, "Failed to enable/disable controllers on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
@@ -2515,7 +2515,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
continue;
}
r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, p, pid->pid);
r = cg_attach(p, pid->pid);
if (r < 0) {
bool again = MANAGER_IS_USER(u->manager) && ERRNO_IS_NEG_PRIVILEGE(r);
@@ -2590,7 +2590,7 @@ int unit_remove_subcgroup(Unit *u, const char *suffix_path) {
log_unit_debug(u, "Removing subcgroup '%s'...", d);
r = cg_trim_everywhere(u->manager->cgroup_supported, d, delete_root);
r = cg_trim(d, delete_root);
if (r < 0)
return log_unit_debug_errno(u, r, "Failed to fully %s cgroup '%s': %m", delete_root ? "remove" : "trim", d);
@@ -3113,7 +3113,7 @@ void unit_prune_cgroup(Unit *u) {
is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE);
r = cg_trim_everywhere(u->manager->cgroup_supported, crt->cgroup_path, !is_root_slice);
r = cg_trim(crt->cgroup_path, !is_root_slice);
if (r < 0) {
int k = unit_prune_cgroup_via_bus(u);
@@ -3614,10 +3614,10 @@ int manager_setup_cgroup(Manager *m) {
/* 5. Make sure we are in the special "init.scope" unit in the root slice. */
const char *scope_path = strjoina(m->cgroup_root, "/" SPECIAL_INIT_SCOPE);
r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, scope_path, /* pid = */ 0);
r = cg_create_and_attach(scope_path, /* pid = */ 0);
if (r >= 0) {
/* Also, move all other userspace processes remaining in the root cgroup into that scope. */
r = cg_migrate(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, SYSTEMD_CGROUP_CONTROLLER, scope_path, 0);
r = cg_migrate(m->cgroup_root, scope_path, 0);
if (r < 0)
log_warning_errno(r, "Couldn't move remaining userspace processes, ignoring: %m");
@@ -3650,7 +3650,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) {
/* We can't really delete the group, since we are in it. But
* let's trim it. */
if (delete && m->cgroup_root && !FLAGS_SET(m->test_run_flags, MANAGER_TEST_RUN_MINIMAL))
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false);
(void) cg_trim(m->cgroup_root, false);
m->cgroup_empty_event_source = sd_event_source_disable_unref(m->cgroup_empty_event_source);
+3 -3
View File
@@ -4967,7 +4967,7 @@ int exec_invoke(
return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m");
}
r = cg_attach_everywhere(params->cgroup_supported, p, 0);
r = cg_attach(p, 0);
if (r == -EUCLEAN) {
*exit_status = EXIT_CGROUP;
return log_exec_error_errno(context, params, r,
@@ -5190,7 +5190,7 @@ int exec_invoke(
if (params->flags & EXEC_CGROUP_DELEGATE) {
_cleanup_free_ char *p = NULL;
r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, params->cgroup_path, uid, gid);
r = cg_set_access(params->cgroup_path, uid, gid);
if (r < 0) {
*exit_status = EXIT_CGROUP;
return log_exec_error_errno(context, params, r, "Failed to adjust control group access: %m");
@@ -5202,7 +5202,7 @@ int exec_invoke(
return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m");
}
if (r > 0) {
r = cg_set_access_recursive(SYSTEMD_CGROUP_CONTROLLER, p, uid, gid);
r = cg_set_access_recursive(p, uid, gid);
if (r < 0) {
*exit_status = EXIT_CGROUP;
return log_exec_error_errno(context, params, r, "Failed to adjust control subgroup access: %m");
+2 -2
View File
@@ -508,7 +508,7 @@ int exec_spawn(
/* If there's a subcgroup, then let's create it here now (the main cgroup was already
* realized by the unit logic) */
r = cg_create(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path);
r = cg_create(subcgroup_path);
if (r < 0)
return log_unit_error_errno(unit, r, "Failed to create subcgroup '%s': %m", subcgroup_path);
}
@@ -593,7 +593,7 @@ int exec_spawn(
* executed outside of the cgroup) and in the parent (so that we can be sure that when we kill the cgroup the
* process will be killed too). */
if (r == 0 && subcgroup_path)
(void) cg_attach(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path, pidref.pid);
(void) cg_attach(subcgroup_path, pidref.pid);
/* r > 0: Already in the right cgroup thanks to CLONE_INTO_CGROUP */
log_unit_debug(unit, "Forked %s as " PID_FMT " (%s CLONE_INTO_CGROUP)",
+1 -1
View File
@@ -371,7 +371,7 @@ static int scope_enter_start_chown(Scope *s) {
}
}
r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_runtime->cgroup_path, uid, gid);
r = cg_set_access(s->cgroup_runtime->cgroup_path, uid, gid);
if (r < 0) {
log_unit_error_errno(UNIT(s), r, "Failed to adjust control group access: %m");
_exit(EXIT_CGROUP);
+1 -1
View File
@@ -5405,7 +5405,7 @@ int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef
(void) ignore_signals(SIGPIPE);
if (crt && crt->cgroup_path) {
r = cg_attach_everywhere(u->manager->cgroup_supported, crt->cgroup_path, 0);
r = cg_attach(crt->cgroup_path, 0);
if (r < 0) {
log_unit_error_errno(u, r, "Failed to join unit cgroup %s: %m", empty_to_root(crt->cgroup_path));
_exit(EXIT_CGROUP);