|
|
c08e08 |
From 2f9e75564e04ed3e6f7aacb264ea69f5582050ca Mon Sep 17 00:00:00 2001
|
|
|
c08e08 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
c08e08 |
Date: Tue, 19 Oct 2021 18:00:58 -0700
|
|
|
c08e08 |
Subject: [PATCH] Revert "core: convert Slice= into a proper dependency (and
|
|
|
c08e08 |
add a back dependency)"
|
|
|
c08e08 |
|
|
|
c08e08 |
This reverts commit d219a2b07cc5dc8ffd5010f08561fab2780d8616.
|
|
|
c08e08 |
---
|
|
|
c08e08 |
man/org.freedesktop.systemd1.xml | 6 -----
|
|
|
c08e08 |
src/basic/unit-def.c | 2 --
|
|
|
c08e08 |
src/basic/unit-def.h | 4 ----
|
|
|
c08e08 |
src/core/cgroup.c | 23 ++++++++++++++----
|
|
|
c08e08 |
src/core/dbus-unit.c | 3 +--
|
|
|
c08e08 |
src/core/load-fragment.c | 2 +-
|
|
|
c08e08 |
src/core/slice.c | 21 +++++++++++++----
|
|
|
c08e08 |
src/core/unit-dependency-atom.c | 8 -------
|
|
|
c08e08 |
src/core/unit-dependency-atom.h | 4 +---
|
|
|
c08e08 |
src/core/unit.c | 40 +++++++++-----------------------
|
|
|
c08e08 |
src/core/unit.h | 7 ++++--
|
|
|
c08e08 |
11 files changed, 54 insertions(+), 66 deletions(-)
|
|
|
c08e08 |
|
|
|
c08e08 |
diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml
|
|
|
c08e08 |
index c14c5b6601..c87feea201 100644
|
|
|
c08e08 |
--- a/man/org.freedesktop.systemd1.xml
|
|
|
c08e08 |
+++ b/man/org.freedesktop.systemd1.xml
|
|
|
c08e08 |
@@ -1650,8 +1650,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
|
|
|
c08e08 |
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
c08e08 |
readonly as JoinsNamespaceOf = ['...', ...];
|
|
|
c08e08 |
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
c08e08 |
- readonly as SliceOf = ['...', ...];
|
|
|
c08e08 |
- @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
c08e08 |
readonly as RequiresMountsFor = ['...', ...];
|
|
|
c08e08 |
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
c08e08 |
readonly as Documentation = ['...', ...];
|
|
|
c08e08 |
@@ -1799,8 +1797,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
|
|
|
c08e08 |
|
|
|
c08e08 |
|
|
|
c08e08 |
|
|
|
c08e08 |
-
|
|
|
c08e08 |
-
|
|
|
c08e08 |
|
|
|
c08e08 |
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -1949,8 +1945,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
|
|
|
c08e08 |
|
|
|
c08e08 |
<variablelist class="dbus-property" generated="True" extra-ref="JoinsNamespaceOf"/>
|
|
|
c08e08 |
|
|
|
c08e08 |
- <variablelist class="dbus-property" generated="True" extra-ref="SliceOf"/>
|
|
|
c08e08 |
-
|
|
|
c08e08 |
<variablelist class="dbus-property" generated="True" extra-ref="RequiresMountsFor"/>
|
|
|
c08e08 |
|
|
|
c08e08 |
<variablelist class="dbus-property" generated="True" extra-ref="Documentation"/>
|
|
|
c08e08 |
diff --git a/src/basic/unit-def.c b/src/basic/unit-def.c
|
|
|
c08e08 |
index 2667e61dc4..23e4825bd7 100644
|
|
|
c08e08 |
--- a/src/basic/unit-def.c
|
|
|
c08e08 |
+++ b/src/basic/unit-def.c
|
|
|
c08e08 |
@@ -289,8 +289,6 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
|
|
|
c08e08 |
[UNIT_JOINS_NAMESPACE_OF] = "JoinsNamespaceOf",
|
|
|
c08e08 |
[UNIT_REFERENCES] = "References",
|
|
|
c08e08 |
[UNIT_REFERENCED_BY] = "ReferencedBy",
|
|
|
c08e08 |
- [UNIT_IN_SLICE] = "InSlice",
|
|
|
c08e08 |
- [UNIT_SLICE_OF] = "SliceOf",
|
|
|
c08e08 |
};
|
|
|
c08e08 |
|
|
|
c08e08 |
DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
|
|
|
c08e08 |
diff --git a/src/basic/unit-def.h b/src/basic/unit-def.h
|
|
|
c08e08 |
index 08651efa57..e72452702a 100644
|
|
|
c08e08 |
--- a/src/basic/unit-def.h
|
|
|
c08e08 |
+++ b/src/basic/unit-def.h
|
|
|
c08e08 |
@@ -254,10 +254,6 @@ typedef enum UnitDependency {
|
|
|
c08e08 |
UNIT_REFERENCES, /* Inverse of 'references' is 'referenced_by' */
|
|
|
c08e08 |
UNIT_REFERENCED_BY,
|
|
|
c08e08 |
|
|
|
c08e08 |
- /* Slice= */
|
|
|
c08e08 |
- UNIT_IN_SLICE,
|
|
|
c08e08 |
- UNIT_SLICE_OF,
|
|
|
c08e08 |
-
|
|
|
c08e08 |
_UNIT_DEPENDENCY_MAX,
|
|
|
c08e08 |
_UNIT_DEPENDENCY_INVALID = -EINVAL,
|
|
|
c08e08 |
} UnitDependency;
|
|
|
c08e08 |
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
|
|
|
c08e08 |
index 5c07aa71d1..9033bea169 100644
|
|
|
c08e08 |
--- a/src/core/cgroup.c
|
|
|
c08e08 |
+++ b/src/core/cgroup.c
|
|
|
c08e08 |
@@ -1706,8 +1706,12 @@ CGroupMask unit_get_members_mask(Unit *u) {
|
|
|
c08e08 |
if (u->type == UNIT_SLICE) {
|
|
|
c08e08 |
Unit *member;
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_SLICE_OF)
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
+ if (UNIT_DEREF(member->slice) != u)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
u->cgroup_members_mask |= unit_get_subtree_mask(member); /* note that this calls ourselves again, for the children */
|
|
|
c08e08 |
+ }
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
u->cgroup_members_mask_valid = true;
|
|
|
c08e08 |
@@ -2365,10 +2369,13 @@ static int unit_realize_cgroup_now_disable(Unit *u, ManagerState state) {
|
|
|
c08e08 |
if (u->type != UNIT_SLICE)
|
|
|
c08e08 |
return 0;
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_SLICE_OF) {
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
CGroupMask target_mask, enable_mask, new_target_mask, new_enable_mask;
|
|
|
c08e08 |
int r;
|
|
|
c08e08 |
|
|
|
c08e08 |
+ if (UNIT_DEREF(m->slice) != u)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
/* The cgroup for this unit might not actually be fully realised yet, in which case it isn't
|
|
|
c08e08 |
* holding any controllers open anyway. */
|
|
|
c08e08 |
if (!m->cgroup_realized)
|
|
|
c08e08 |
@@ -2530,7 +2537,11 @@ void unit_add_family_to_cgroup_realize_queue(Unit *u) {
|
|
|
c08e08 |
/* Children of u likely changed when we're called */
|
|
|
c08e08 |
u->cgroup_members_mask_valid = false;
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_SLICE_OF) {
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(m, u, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
+
|
|
|
c08e08 |
+ /* Skip units that have a dependency on the slice but aren't actually in it. */
|
|
|
c08e08 |
+ if (UNIT_DEREF(m->slice) != u)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
|
|
|
c08e08 |
/* No point in doing cgroup application for units without active processes. */
|
|
|
c08e08 |
if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(m)))
|
|
|
c08e08 |
@@ -3869,8 +3880,12 @@ void unit_invalidate_cgroup_bpf(Unit *u) {
|
|
|
c08e08 |
if (u->type == UNIT_SLICE) {
|
|
|
c08e08 |
Unit *member;
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_SLICE_OF)
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(member, u, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
+ if (UNIT_DEREF(member->slice) != u)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
unit_invalidate_cgroup_bpf(member);
|
|
|
c08e08 |
+ }
|
|
|
c08e08 |
}
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
|
|
|
c08e08 |
index 124b9e496b..f861988bd8 100644
|
|
|
c08e08 |
--- a/src/core/dbus-unit.c
|
|
|
c08e08 |
+++ b/src/core/dbus-unit.c
|
|
|
c08e08 |
@@ -875,7 +875,6 @@ const sd_bus_vtable bus_unit_vtable[] = {
|
|
|
c08e08 |
SD_BUS_PROPERTY("PropagatesStopTo", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
SD_BUS_PROPERTY("StopPropagatedFrom", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
SD_BUS_PROPERTY("JoinsNamespaceOf", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
- SD_BUS_PROPERTY("SliceOf", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
SD_BUS_PROPERTY("RequiresMountsFor", "as", property_get_requires_mounts_for, offsetof(Unit, requires_mounts_for), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
SD_BUS_PROPERTY("Documentation", "as", NULL, offsetof(Unit, documentation), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
SD_BUS_PROPERTY("Description", "s", property_get_description, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
c08e08 |
@@ -2273,7 +2272,7 @@ static int bus_unit_set_transient_property(
|
|
|
c08e08 |
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unit name '%s' is not a slice", s);
|
|
|
c08e08 |
|
|
|
c08e08 |
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
|
|
c08e08 |
- r = unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE);
|
|
|
c08e08 |
+ r = unit_set_slice(u, slice);
|
|
|
c08e08 |
if (r < 0)
|
|
|
c08e08 |
return r;
|
|
|
c08e08 |
|
|
|
c08e08 |
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
|
|
c08e08 |
index 8fb3c378ee..a068fdf313 100644
|
|
|
c08e08 |
--- a/src/core/load-fragment.c
|
|
|
c08e08 |
+++ b/src/core/load-fragment.c
|
|
|
c08e08 |
@@ -3575,7 +3575,7 @@ int config_parse_unit_slice(
|
|
|
c08e08 |
return 0;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
- r = unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE);
|
|
|
c08e08 |
+ r = unit_set_slice(u, slice);
|
|
|
c08e08 |
if (r < 0) {
|
|
|
c08e08 |
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id);
|
|
|
c08e08 |
return 0;
|
|
|
c08e08 |
diff --git a/src/core/slice.c b/src/core/slice.c
|
|
|
c08e08 |
index 2e43c00119..009c98b434 100644
|
|
|
c08e08 |
--- a/src/core/slice.c
|
|
|
c08e08 |
+++ b/src/core/slice.c
|
|
|
c08e08 |
@@ -47,7 +47,7 @@ static void slice_set_state(Slice *t, SliceState state) {
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
static int slice_add_parent_slice(Slice *s) {
|
|
|
c08e08 |
- Unit *u = UNIT(s);
|
|
|
c08e08 |
+ Unit *u = UNIT(s), *parent;
|
|
|
c08e08 |
_cleanup_free_ char *a = NULL;
|
|
|
c08e08 |
int r;
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -60,7 +60,12 @@ static int slice_add_parent_slice(Slice *s) {
|
|
|
c08e08 |
if (r <= 0) /* 0 means root slice */
|
|
|
c08e08 |
return r;
|
|
|
c08e08 |
|
|
|
c08e08 |
- return unit_add_dependency_by_name(u, UNIT_IN_SLICE, a, true, UNIT_DEPENDENCY_IMPLICIT);
|
|
|
c08e08 |
+ r = manager_load_unit(u->manager, a, NULL, NULL, &parent);
|
|
|
c08e08 |
+ if (r < 0)
|
|
|
c08e08 |
+ return r;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
+ unit_ref_set(&u->slice, u, parent);
|
|
|
c08e08 |
+ return 0;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
static int slice_add_default_dependencies(Slice *s) {
|
|
|
c08e08 |
@@ -349,11 +354,14 @@ static void slice_enumerate_perpetual(Manager *m) {
|
|
|
c08e08 |
|
|
|
c08e08 |
static bool slice_freezer_action_supported_by_children(Unit *s) {
|
|
|
c08e08 |
Unit *member;
|
|
|
c08e08 |
- int r;
|
|
|
c08e08 |
|
|
|
c08e08 |
assert(s);
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_SLICE_OF) {
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
+ int r;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
+ if (UNIT_DEREF(member->slice) != s)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
|
|
|
c08e08 |
if (member->type == UNIT_SLICE) {
|
|
|
c08e08 |
r = slice_freezer_action_supported_by_children(member);
|
|
|
c08e08 |
@@ -380,7 +388,10 @@ static int slice_freezer_action(Unit *s, FreezerAction action) {
|
|
|
c08e08 |
return 0;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
- UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_SLICE_OF) {
|
|
|
c08e08 |
+ UNIT_FOREACH_DEPENDENCY(member, s, UNIT_ATOM_BEFORE) {
|
|
|
c08e08 |
+ if (UNIT_DEREF(member->slice) != s)
|
|
|
c08e08 |
+ continue;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
if (action == FREEZER_FREEZE)
|
|
|
c08e08 |
r = UNIT_VTABLE(member)->freeze(member);
|
|
|
c08e08 |
else
|
|
|
c08e08 |
diff --git a/src/core/unit-dependency-atom.c b/src/core/unit-dependency-atom.c
|
|
|
c08e08 |
index 761835828a..9a8e4615f1 100644
|
|
|
c08e08 |
--- a/src/core/unit-dependency-atom.c
|
|
|
c08e08 |
+++ b/src/core/unit-dependency-atom.c
|
|
|
c08e08 |
@@ -93,8 +93,6 @@ static const UnitDependencyAtom atom_map[_UNIT_DEPENDENCY_MAX] = {
|
|
|
c08e08 |
[UNIT_JOINS_NAMESPACE_OF] = UNIT_ATOM_JOINS_NAMESPACE_OF,
|
|
|
c08e08 |
[UNIT_REFERENCES] = UNIT_ATOM_REFERENCES,
|
|
|
c08e08 |
[UNIT_REFERENCED_BY] = UNIT_ATOM_REFERENCED_BY,
|
|
|
c08e08 |
- [UNIT_IN_SLICE] = UNIT_ATOM_IN_SLICE,
|
|
|
c08e08 |
- [UNIT_SLICE_OF] = UNIT_ATOM_SLICE_OF,
|
|
|
c08e08 |
|
|
|
c08e08 |
/* These are dependency types without effect on our state engine. We maintain them only to make
|
|
|
c08e08 |
* things discoverable/debuggable as they are the inverse dependencies to some of the above. As they
|
|
|
c08e08 |
@@ -228,12 +226,6 @@ UnitDependency unit_dependency_from_unique_atom(UnitDependencyAtom atom) {
|
|
|
c08e08 |
case UNIT_ATOM_REFERENCED_BY:
|
|
|
c08e08 |
return UNIT_REFERENCED_BY;
|
|
|
c08e08 |
|
|
|
c08e08 |
- case UNIT_ATOM_IN_SLICE:
|
|
|
c08e08 |
- return UNIT_IN_SLICE;
|
|
|
c08e08 |
-
|
|
|
c08e08 |
- case UNIT_ATOM_SLICE_OF:
|
|
|
c08e08 |
- return UNIT_SLICE_OF;
|
|
|
c08e08 |
-
|
|
|
c08e08 |
default:
|
|
|
c08e08 |
return _UNIT_DEPENDENCY_INVALID;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
diff --git a/src/core/unit-dependency-atom.h b/src/core/unit-dependency-atom.h
|
|
|
c08e08 |
index c5f8f5d400..f79f1b732a 100644
|
|
|
c08e08 |
--- a/src/core/unit-dependency-atom.h
|
|
|
c08e08 |
+++ b/src/core/unit-dependency-atom.h
|
|
|
c08e08 |
@@ -77,9 +77,7 @@ typedef enum UnitDependencyAtom {
|
|
|
c08e08 |
UNIT_ATOM_JOINS_NAMESPACE_OF = UINT64_C(1) << 29,
|
|
|
c08e08 |
UNIT_ATOM_REFERENCES = UINT64_C(1) << 30,
|
|
|
c08e08 |
UNIT_ATOM_REFERENCED_BY = UINT64_C(1) << 31,
|
|
|
c08e08 |
- UNIT_ATOM_IN_SLICE = UINT64_C(1) << 32,
|
|
|
c08e08 |
- UNIT_ATOM_SLICE_OF = UINT64_C(1) << 33,
|
|
|
c08e08 |
- _UNIT_DEPENDENCY_ATOM_MAX = (UINT64_C(1) << 34) - 1,
|
|
|
c08e08 |
+ _UNIT_DEPENDENCY_ATOM_MAX = (UINT64_C(1) << 32) - 1,
|
|
|
c08e08 |
_UNIT_DEPENDENCY_ATOM_INVALID = -EINVAL,
|
|
|
c08e08 |
} UnitDependencyAtom;
|
|
|
c08e08 |
|
|
|
c08e08 |
diff --git a/src/core/unit.c b/src/core/unit.c
|
|
|
c08e08 |
index 38d3eb703f..48810a2ba9 100644
|
|
|
c08e08 |
--- a/src/core/unit.c
|
|
|
c08e08 |
+++ b/src/core/unit.c
|
|
|
c08e08 |
@@ -692,10 +692,11 @@ Unit* unit_free(Unit *u) {
|
|
|
c08e08 |
job_free(j);
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
+ unit_clear_dependencies(u);
|
|
|
c08e08 |
+
|
|
|
c08e08 |
/* A unit is being dropped from the tree, make sure our family is realized properly. Do this after we
|
|
|
c08e08 |
* detach the unit from slice tree in order to eliminate its effect on controller masks. */
|
|
|
c08e08 |
slice = UNIT_GET_SLICE(u);
|
|
|
c08e08 |
- unit_clear_dependencies(u);
|
|
|
c08e08 |
if (slice)
|
|
|
c08e08 |
unit_add_family_to_cgroup_realize_queue(slice);
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -721,6 +722,7 @@ Unit* unit_free(Unit *u) {
|
|
|
c08e08 |
|
|
|
c08e08 |
unit_unwatch_all_pids(u);
|
|
|
c08e08 |
|
|
|
c08e08 |
+ unit_ref_unset(&u->slice);
|
|
|
c08e08 |
while (u->refs_by_target)
|
|
|
c08e08 |
unit_ref_unset(u->refs_by_target);
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -3032,8 +3034,6 @@ int unit_add_dependency(
|
|
|
c08e08 |
[UNIT_JOINS_NAMESPACE_OF] = UNIT_JOINS_NAMESPACE_OF, /* symmetric! 👓 */
|
|
|
c08e08 |
[UNIT_REFERENCES] = UNIT_REFERENCED_BY,
|
|
|
c08e08 |
[UNIT_REFERENCED_BY] = UNIT_REFERENCES,
|
|
|
c08e08 |
- [UNIT_IN_SLICE] = UNIT_SLICE_OF,
|
|
|
c08e08 |
- [UNIT_SLICE_OF] = UNIT_IN_SLICE,
|
|
|
c08e08 |
};
|
|
|
c08e08 |
Unit *original_u = u, *original_other = other;
|
|
|
c08e08 |
UnitDependencyAtom a;
|
|
|
c08e08 |
@@ -3077,21 +3077,6 @@ int unit_add_dependency(
|
|
|
c08e08 |
return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
|
|
c08e08 |
"Requested dependency TriggeredBy=%s refused (%s units cannot trigger other units).", other->id, unit_type_to_string(other->type));
|
|
|
c08e08 |
|
|
|
c08e08 |
- if (FLAGS_SET(a, UNIT_ATOM_IN_SLICE) && other->type != UNIT_SLICE)
|
|
|
c08e08 |
- return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
|
|
c08e08 |
- "Requested dependency Slice=%s refused (%s is not a slice unit).", other->id, other->id);
|
|
|
c08e08 |
- if (FLAGS_SET(a, UNIT_ATOM_SLICE_OF) && u->type != UNIT_SLICE)
|
|
|
c08e08 |
- return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
|
|
c08e08 |
- "Requested dependency SliceOf=%s refused (%s is not a slice unit).", other->id, u->id);
|
|
|
c08e08 |
-
|
|
|
c08e08 |
- if (FLAGS_SET(a, UNIT_ATOM_IN_SLICE) && !UNIT_HAS_CGROUP_CONTEXT(u))
|
|
|
c08e08 |
- return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
|
|
c08e08 |
- "Requested dependency Slice=%s refused (%s is not a cgroup unit).", other->id, u->id);
|
|
|
c08e08 |
-
|
|
|
c08e08 |
- if (FLAGS_SET(a, UNIT_ATOM_SLICE_OF) && !UNIT_HAS_CGROUP_CONTEXT(other))
|
|
|
c08e08 |
- return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
|
|
|
c08e08 |
- "Requested dependency SliceOf=%s refused (%s is not a cgroup unit).", other->id, other->id);
|
|
|
c08e08 |
-
|
|
|
c08e08 |
r = unit_add_dependency_hashmap(&u->dependencies, d, other, mask, 0);
|
|
|
c08e08 |
if (r < 0)
|
|
|
c08e08 |
return r;
|
|
|
c08e08 |
@@ -3270,15 +3255,15 @@ reset:
|
|
|
c08e08 |
return r;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
-int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask) {
|
|
|
c08e08 |
- int r;
|
|
|
c08e08 |
-
|
|
|
c08e08 |
+int unit_set_slice(Unit *u, Unit *slice) {
|
|
|
c08e08 |
assert(u);
|
|
|
c08e08 |
assert(slice);
|
|
|
c08e08 |
|
|
|
c08e08 |
- /* Sets the unit slice if it has not been set before. Is extra careful, to only allow this for units
|
|
|
c08e08 |
- * that actually have a cgroup context. Also, we don't allow to set this for slices (since the parent
|
|
|
c08e08 |
- * slice is derived from the name). Make sure the unit we set is actually a slice. */
|
|
|
c08e08 |
+ /* Sets the unit slice if it has not been set before. Is extra
|
|
|
c08e08 |
+ * careful, to only allow this for units that actually have a
|
|
|
c08e08 |
+ * cgroup context. Also, we don't allow to set this for slices
|
|
|
c08e08 |
+ * (since the parent slice is derived from the name). Make
|
|
|
c08e08 |
+ * sure the unit we set is actually a slice. */
|
|
|
c08e08 |
|
|
|
c08e08 |
if (!UNIT_HAS_CGROUP_CONTEXT(u))
|
|
|
c08e08 |
return -EOPNOTSUPP;
|
|
|
c08e08 |
@@ -3303,10 +3288,7 @@ int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask) {
|
|
|
c08e08 |
if (UNIT_GET_SLICE(u) && u->cgroup_realized)
|
|
|
c08e08 |
return -EBUSY;
|
|
|
c08e08 |
|
|
|
c08e08 |
- r = unit_add_dependency(u, UNIT_IN_SLICE, slice, true, mask);
|
|
|
c08e08 |
- if (r < 0)
|
|
|
c08e08 |
- return r;
|
|
|
c08e08 |
-
|
|
|
c08e08 |
+ unit_ref_set(&u->slice, u, slice);
|
|
|
c08e08 |
return 1;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -3356,7 +3338,7 @@ int unit_set_default_slice(Unit *u) {
|
|
|
c08e08 |
if (r < 0)
|
|
|
c08e08 |
return r;
|
|
|
c08e08 |
|
|
|
c08e08 |
- return unit_set_slice(u, slice, UNIT_DEPENDENCY_FILE);
|
|
|
c08e08 |
+ return unit_set_slice(u, slice);
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
const char *unit_slice_name(Unit *u) {
|
|
|
c08e08 |
diff --git a/src/core/unit.h b/src/core/unit.h
|
|
|
c08e08 |
index 759104ffa7..7a8bfd0568 100644
|
|
|
c08e08 |
--- a/src/core/unit.h
|
|
|
c08e08 |
+++ b/src/core/unit.h
|
|
|
c08e08 |
@@ -202,6 +202,8 @@ typedef struct Unit {
|
|
|
c08e08 |
dual_timestamp active_exit_timestamp;
|
|
|
c08e08 |
dual_timestamp inactive_enter_timestamp;
|
|
|
c08e08 |
|
|
|
c08e08 |
+ UnitRef slice;
|
|
|
c08e08 |
+
|
|
|
c08e08 |
/* Per type list */
|
|
|
c08e08 |
LIST_FIELDS(Unit, units_by_type);
|
|
|
c08e08 |
|
|
|
c08e08 |
@@ -716,7 +718,8 @@ static inline Unit* UNIT_TRIGGER(Unit *u) {
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
static inline Unit* UNIT_GET_SLICE(const Unit *u) {
|
|
|
c08e08 |
- return unit_has_dependency(u, UNIT_ATOM_IN_SLICE, NULL);
|
|
|
c08e08 |
+ assert(u);
|
|
|
c08e08 |
+ return u->slice.target;
|
|
|
c08e08 |
}
|
|
|
c08e08 |
|
|
|
c08e08 |
Unit* unit_new(Manager *m, size_t size);
|
|
|
c08e08 |
@@ -761,7 +764,7 @@ Unit *unit_follow_merge(Unit *u) _pure_;
|
|
|
c08e08 |
int unit_load_fragment_and_dropin(Unit *u, bool fragment_required);
|
|
|
c08e08 |
int unit_load(Unit *unit);
|
|
|
c08e08 |
|
|
|
c08e08 |
-int unit_set_slice(Unit *u, Unit *slice, UnitDependencyMask mask);
|
|
|
c08e08 |
+int unit_set_slice(Unit *u, Unit *slice);
|
|
|
c08e08 |
int unit_set_default_slice(Unit *u);
|
|
|
c08e08 |
|
|
|
c08e08 |
const char *unit_description(Unit *u) _pure_;
|
|
|
c08e08 |
--
|
|
|
c08e08 |
2.31.1
|
|
|
c08e08 |
|