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/slice.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/slice.c')
-rw-r--r-- | src/core/slice.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/core/slice.c b/src/core/slice.c index 5d836a11e6..595f704a17 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -47,7 +47,7 @@ static void slice_set_state(Slice *t, SliceState state) { } static int slice_add_parent_slice(Slice *s) { - Unit *u = UNIT(s), *parent; + Unit *u = UNIT(s); _cleanup_free_ char *a = NULL; int r; @@ -60,12 +60,7 @@ static int slice_add_parent_slice(Slice *s) { if (r <= 0) /* 0 means root slice */ return r; - r = manager_load_unit(u->manager, a, NULL, NULL, &parent); - if (r < 0) - return r; - - unit_ref_set(&u->slice, u, parent); - return 0; + return unit_add_dependency_by_name(u, UNIT_IN_SLICE, a, true, UNIT_DEPENDENCY_IMPLICIT); } static int slice_add_default_dependencies(Slice *s) { @@ -346,14 +341,11 @@ static void slice_enumerate_perpetual(Manager *m) { static bool slice_freezer_action_supported_by_children(Unit *s) { Unit *member; + int r; assert(s); - UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_BEFORE) { - int r; - - if (UNIT_DEREF(member->slice) != s) - continue; + UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_SLICE_OF) { if (member->type == UNIT_SLICE) { r = slice_freezer_action_supported_by_children(member); @@ -380,10 +372,7 @@ static int slice_freezer_action(Unit *s, FreezerAction action) { return 0; } - UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_BEFORE) { - if (UNIT_DEREF(member->slice) != s) - continue; - + UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_SLICE_OF) { if (action == FREEZER_FREEZE) r = UNIT_VTABLE(member)->freeze(member); else |