diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-04-13 18:37:25 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-05-25 16:03:01 +0200 |
commit | d219a2b07cc5dc8ffd5010f08561fab2780d8616 (patch) | |
tree | 5f805afabd4d1434ebf1dc38390870160001d3ef /src/core/cgroup.c | |
parent | 12f64221b0af5a9380a840ebeb897c2cd6cff955 (diff) | |
download | systemd-d219a2b07cc5dc8ffd5010f08561fab2780d8616.tar.gz |
core: convert Slice= into a proper dependency (and add a back dependency)
The slice a unit is assigned to is currently a UnitRef reference. Let's
turn it into a proper dependency, to simplify and clean up code a bit.
Now that new dep types are cheaper, deps should generally be preferable
over everything else, if the concept applies.
This brings one major benefit: we often have to iterate through all unit
a slice contains. So far we iterated through all Before= dependencies of
the slice unit to achieve that, filtering out unrelated units, and
taking benefit of the fact that slice units are implicitly ordered
Before= the units they contain. By making Slice= a proper dependency,
and having an accompanying SliceOf= dependency type, this is much
simpler and nicer as we can directly enumerate the units a slice
contains.
The forward dependency is actually called InSlice internally, since we
already used the UNIT_SLICE name as UnitType field. However, since we
don't intend to expose the dependency to users as dep anyway (we already
have the regular Slice D-Bus property for this) this shouldn't matter.
The SliceOf= implicit dependency type (the erverse of Slice=/InSlice=)
is exported over the bus, to make things a bit nicer to debug and
discoverable.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r-- | src/core/cgroup.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 97820eb264..5b00faa6f6 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1702,12 +1702,8 @@ CGroupMask unit_get_members_mask(Unit *u) { if (u->type == UNIT_SLICE) { Unit *member; - UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_BEFORE) { - if (UNIT_DEREF(member->slice) != u) - continue; - + UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_SLICE_OF) u->cgroup_members_mask |= unit_get_subtree_mask(member); /* note that this calls ourselves again, for the children */ - } } u->cgroup_members_mask_valid = true; @@ -2362,13 +2358,10 @@ static int unit_realize_cgroup_now_disable(Unit *u, ManagerState state) { if (u->type != UNIT_SLICE) return 0; - UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_BEFORE) { + UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_SLICE_OF) { CGroupMask target_mask, enable_mask, new_target_mask, new_enable_mask; int r; - if (UNIT_DEREF(m->slice) != u) - continue; - /* The cgroup for this unit might not actually be fully realised yet, in which case it isn't * holding any controllers open anyway. */ if (!m->cgroup_realized) @@ -2530,11 +2523,7 @@ void unit_add_family_to_cgroup_realize_queue(Unit *u) { /* Children of u likely changed when we're called */ u->cgroup_members_mask_valid = false; - UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_BEFORE) { - - /* Skip units that have a dependency on the slice but aren't actually in it. */ - if (UNIT_DEREF(m->slice) != u) - continue; + UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_SLICE_OF) { /* No point in doing cgroup application for units without active processes. */ if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(m))) @@ -3799,12 +3788,8 @@ void unit_invalidate_cgroup_bpf(Unit *u) { if (u->type == UNIT_SLICE) { Unit *member; - UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_BEFORE) { - if (UNIT_DEREF(member->slice) != u) - continue; - + UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_SLICE_OF) unit_invalidate_cgroup_bpf(member); - } } } |