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.
This commit is contained in:
+5
-16
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user