From 49b6babb76c306ccf9a06845cd6a4cb2083e051a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 6 Oct 2023 18:38:22 +0200 Subject: [PATCH] =?utf8?q?cgroup:=20rename=20cgroup=5Fmodify=5Fnft=5Fset()?= =?utf8?q?=20=E2=86=92=20unit=5Fmodify=5Fnft=5Fset()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is the only function that cgroup.h exports that is prefixed with cgroup_ where this does not refer to some type such as CGroupContext or CGroupTasksMax or so. It simply operates on a unit. And it doesn't even modify a cgroup, but just modifies an nft set. Hence, to make the naming scheme systematic, change prefix from cgroup_ to unit_, matching the majority of the functions that operate on Unit* in the file. --- src/core/cgroup.c | 13 ++++++++----- src/core/cgroup.h | 2 +- src/core/unit.c | 5 +---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index e2046f2c869..b6c1a7265e9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1387,19 +1387,20 @@ static void cgroup_apply_firewall(Unit *u) { (void) bpf_firewall_install(u); } -void cgroup_modify_nft_set(Unit *u, bool add) { +void unit_modify_nft_set(Unit *u, bool add) { int r; - CGroupContext *c; assert(u); if (!MANAGER_IS_SYSTEM(u->manager)) return; + if (!UNIT_HAS_CGROUP_CONTEXT(u)) + return; + if (cg_all_unified() <= 0) return; - assert_se(c = unit_get_cgroup_context(u)); if (u->cgroup_id == 0) return; @@ -1411,6 +1412,8 @@ void cgroup_modify_nft_set(Unit *u, bool add) { assert(u->manager->fw_ctx); } + CGroupContext *c = ASSERT_PTR(unit_get_cgroup_context(u)); + FOREACH_ARRAY(nft_set, c->nft_set_context.sets, c->nft_set_context.n_sets) { uint64_t element = u->cgroup_id; @@ -1864,7 +1867,7 @@ static void cgroup_context_apply( if (apply_mask & CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES) cgroup_apply_restrict_network_interfaces(u); - cgroup_modify_nft_set(u, /* add = */ true); + unit_modify_nft_set(u, /* add = */ true); } static bool unit_get_needs_bpf_firewall(Unit *u) { @@ -3042,7 +3045,7 @@ void unit_prune_cgroup(Unit *u) { (void) lsm_bpf_cleanup(u); /* Remove cgroup from the global LSM BPF map */ #endif - cgroup_modify_nft_set(u, /* add = */ false); + unit_modify_nft_set(u, /* add = */ false); is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE); diff --git a/src/core/cgroup.h b/src/core/cgroup.h index bd6345820c5..b189ed7485b 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -278,7 +278,7 @@ static inline bool cgroup_context_want_memory_pressure(const CGroupContext *c) { int cgroup_context_add_device_allow(CGroupContext *c, const char *dev, const char *mode); int cgroup_context_add_bpf_foreign_program(CGroupContext *c, uint32_t attach_type, const char *path); -void cgroup_modify_nft_set(Unit *u, bool add); +void unit_modify_nft_set(Unit *u, bool add); CGroupMask unit_get_own_mask(Unit *u); CGroupMask unit_get_delegate_mask(Unit *u); diff --git a/src/core/unit.c b/src/core/unit.c index eed092b4dcc..109148b02ab 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3843,10 +3843,7 @@ int unit_coldplug(Unit *u) { if (u->nop_job) RET_GATHER(r, job_coldplug(u->nop_job)); - CGroupContext *c = unit_get_cgroup_context(u); - if (c) - cgroup_modify_nft_set(u, /* add = */ true); - + unit_modify_nft_set(u, /* add = */ true); return r; } -- 2.47.3