]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: rename cgroup_modify_nft_set() → unit_modify_nft_set() 29482/head
authorLennart Poettering <lennart@poettering.net>
Fri, 6 Oct 2023 16:38:22 +0000 (18:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 6 Oct 2023 16:42:22 +0000 (18:42 +0200)
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
src/core/cgroup.h
src/core/unit.c

index e2046f2c8691366c4f3c223dde85a3cb61410a2c..b6c1a7265e92ea1687f1c16a605230aabc98eeac 100644 (file)
@@ -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);
 
index bd6345820c5f69be993d4d27263537c2c9c27ebf..b189ed7485ba2563d0d46a5435b6f16fa7b7e78b 100644 (file)
@@ -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);
index eed092b4dccfcf7d23521b8eb1c6238b8e6da803..109148b02ab72cad6546618098c105f9eb2d4c61 100644 (file)
@@ -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;
 }