assert(ret_ipv6_map_fd);
assert(ret_has_any);
- for (p = u; p; p = UNIT_DEREF(p->slice)) {
+ for (p = u; p; p = UNIT_GET_SLICE(p)) {
CGroupContext *cc;
cc = unit_get_cgroup_context(p);
return ipv6_map_fd;
}
- for (p = u; p; p = UNIT_DEREF(p->slice)) {
+ for (p = u; p; p = UNIT_GET_SLICE(p)) {
CGroupContext *cc;
cc = unit_get_cgroup_context(p);
if (c && c->entry##_set) \
return c->entry; \
\
- while ((u = UNIT_DEREF(u->slice))) { \
+ while ((u = UNIT_GET_SLICE(u))) { \
c = unit_get_cgroup_context(u); \
if (c && c->default_##entry##_set) \
return c->default_##entry; \
return true;
/* If any parent slice has an IP access list defined, it applies too */
- for (p = UNIT_DEREF(u->slice); p; p = UNIT_DEREF(p->slice)) {
+ for (p = UNIT_GET_SLICE(u); p; p = UNIT_GET_SLICE(p)) {
c = unit_get_cgroup_context(p);
if (!c)
return false;
}
CGroupMask unit_get_siblings_mask(Unit *u) {
+ Unit *slice;
assert(u);
/* Returns the mask of controllers all of the unit's siblings
* require, i.e. the members mask of the unit's parent slice
* if there is one. */
- if (UNIT_ISSET(u->slice))
- return unit_get_members_mask(UNIT_DEREF(u->slice));
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ return unit_get_members_mask(slice);
return unit_get_subtree_mask(u); /* we are the top-level slice */
}
CGroupMask unit_get_ancestor_disable_mask(Unit *u) {
CGroupMask mask;
+ Unit *slice;
assert(u);
mask = unit_get_disable_mask(u);
/* Returns the mask of controllers which are marked as forcibly
* disabled in any ancestor unit or the unit in question. */
- if (UNIT_ISSET(u->slice))
- mask |= unit_get_ancestor_disable_mask(UNIT_DEREF(u->slice));
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ mask |= unit_get_ancestor_disable_mask(slice);
return mask;
}
}
void unit_invalidate_cgroup_members_masks(Unit *u) {
+ Unit *slice;
+
assert(u);
/* Recurse invalidate the member masks cache all the way up the tree */
u->cgroup_members_mask_valid = false;
- if (UNIT_ISSET(u->slice))
- unit_invalidate_cgroup_members_masks(UNIT_DEREF(u->slice));
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ unit_invalidate_cgroup_members_masks(slice);
}
const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask) {
FLAGS_SET(u->cgroup_realized_mask, mask))
return u->cgroup_path;
- u = UNIT_DEREF(u->slice);
+ u = UNIT_GET_SLICE(u);
}
return NULL;
}
char *unit_default_cgroup_path(const Unit *u) {
- _cleanup_free_ char *escaped = NULL, *slice = NULL;
+ _cleanup_free_ char *escaped = NULL, *slice_path = NULL;
+ Unit *slice;
int r;
assert(u);
if (unit_has_name(u, SPECIAL_ROOT_SLICE))
return strdup(u->manager->cgroup_root);
- if (UNIT_ISSET(u->slice) && !unit_has_name(UNIT_DEREF(u->slice), SPECIAL_ROOT_SLICE)) {
- r = cg_slice_to_path(UNIT_DEREF(u->slice)->id, &slice);
+ slice = UNIT_GET_SLICE(u);
+ if (slice && !unit_has_name(slice, SPECIAL_ROOT_SLICE)) {
+ r = cg_slice_to_path(slice->id, &slice_path);
if (r < 0)
return NULL;
}
if (!escaped)
return NULL;
- return path_join(empty_to_root(u->manager->cgroup_root), slice, escaped);
+ return path_join(empty_to_root(u->manager->cgroup_root), slice_path, escaped);
}
int unit_set_cgroup_path(Unit *u, const char *path) {
* hierarchy downwards to the unit in question. */
static int unit_realize_cgroup_now_enable(Unit *u, ManagerState state) {
CGroupMask target_mask, enable_mask, new_target_mask, new_enable_mask;
+ Unit *slice;
int r;
assert(u);
/* First go deal with this unit's parent, or we won't be able to enable
* any new controllers at this layer. */
- if (UNIT_ISSET(u->slice)) {
- r = unit_realize_cgroup_now_enable(UNIT_DEREF(u->slice), state);
+ slice = UNIT_GET_SLICE(u);
+ if (slice) {
+ r = unit_realize_cgroup_now_enable(slice, state);
if (r < 0)
return r;
}
* Returns 0 on success and < 0 on failure. */
static int unit_realize_cgroup_now(Unit *u, ManagerState state) {
CGroupMask target_mask, enable_mask;
+ Unit *slice;
int r;
assert(u);
return r;
/* Enable controllers above us, if there are any */
- if (UNIT_ISSET(u->slice)) {
- r = unit_realize_cgroup_now_enable(UNIT_DEREF(u->slice), state);
+ slice = UNIT_GET_SLICE(u);
+ if (slice) {
+ r = unit_realize_cgroup_now_enable(slice, state);
if (r < 0)
return r;
}
/* Parent comes after children */
unit_add_to_cgroup_realize_queue(u);
- } while ((u = UNIT_DEREF(u->slice)));
+
+ u = UNIT_GET_SLICE(u);
+ } while (u);
}
int unit_realize_cgroup(Unit *u) {
+ Unit *slice;
+
assert(u);
if (!UNIT_HAS_CGROUP_CONTEXT(u))
* This call will defer work on the siblings and derealized ancestors to the next event loop
* iteration and synchronously creates the parent cgroups (unit_realize_cgroup_now). */
- if (UNIT_ISSET(u->slice))
- unit_add_family_to_cgroup_realize_queue(UNIT_DEREF(u->slice));
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ unit_add_family_to_cgroup_realize_queue(slice);
/* And realize this one now (and apply the values) */
return unit_realize_cgroup_now(u, manager_state(u->manager));
assert(s);
- if (UNIT_ISSET(u->slice))
+ if (UNIT_GET_SLICE(u))
return 0;
r = slice_build_parent_slice(u->id, &a);
if (r < 0)
return log_unit_error_errno(UNIT(s), r, "Failed to determine parent slice: %m");
- if (parent ? !unit_has_name(UNIT_DEREF(UNIT(s)->slice), parent) : UNIT_ISSET(UNIT(s)->slice))
+ if (parent ? !unit_has_name(UNIT_GET_SLICE(UNIT(s)), parent) : !!UNIT_GET_SLICE(UNIT(s)))
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Located outside of parent slice. Refusing.");
return 0;
}
static int specifier_cgroup_slice(char specifier, const void *data, const void *userdata, char **ret) {
- const Unit *u = userdata;
+ const Unit *u = userdata, *slice;
char *n;
assert(u);
bad_specifier(u, specifier);
- if (UNIT_ISSET(u->slice)) {
- const Unit *slice;
-
- slice = UNIT_DEREF(u->slice);
-
+ slice = UNIT_GET_SLICE(u);
+ if (slice) {
if (slice->cgroup_path)
n = strdup(slice->cgroup_path);
else
}
Unit* unit_free(Unit *u) {
+ Unit *slice;
char *t;
if (!u)
/* A unit is being dropped from the tree, make sure our family is realized properly. Do this after we
* detach the unit from slice tree in order to eliminate its effect on controller masks. */
- if (UNIT_ISSET(u->slice))
- unit_add_family_to_cgroup_realize_queue(UNIT_DEREF(u->slice));
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ unit_add_family_to_cgroup_realize_queue(slice);
if (u->on_console)
manager_unref_console(u->manager);
}
static int unit_add_slice_dependencies(Unit *u) {
+ Unit *slice;
assert(u);
if (!UNIT_HAS_CGROUP_CONTEXT(u))
relationship). */
UnitDependencyMask mask = u->type == UNIT_SLICE ? UNIT_DEPENDENCY_IMPLICIT : UNIT_DEPENDENCY_FILE;
- if (UNIT_ISSET(u->slice))
- return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, UNIT_DEREF(u->slice), true, mask);
+ slice = UNIT_GET_SLICE(u);
+ if (slice)
+ return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, slice, true, mask);
if (unit_has_name(u, SPECIAL_ROOT_SLICE))
return 0;
!unit_has_name(slice, SPECIAL_ROOT_SLICE))
return -EPERM;
- if (UNIT_DEREF(u->slice) == slice)
+ if (UNIT_GET_SLICE(u) == slice)
return 0;
/* Disallow slice changes if @u is already bound to cgroups */
- if (UNIT_ISSET(u->slice) && u->cgroup_realized)
+ if (UNIT_GET_SLICE(u) && u->cgroup_realized)
return -EBUSY;
unit_ref_set(&u->slice, u, slice);
assert(u);
- if (UNIT_ISSET(u->slice))
+ if (UNIT_GET_SLICE(u))
return 0;
if (u->instance) {
}
const char *unit_slice_name(Unit *u) {
+ Unit *slice;
assert(u);
- if (!UNIT_ISSET(u->slice))
+ slice = UNIT_GET_SLICE(u);
+ if (!slice)
return NULL;
- return UNIT_DEREF(u->slice)->id;
+ return slice->id;
}
int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
return unit_has_dependency(u, UNIT_ATOM_TRIGGERS, NULL);
}
+static inline Unit* UNIT_GET_SLICE(const Unit *u) {
+ assert(u);
+ return u->slice.target;
+}
+
Unit* unit_new(Manager *m, size_t size);
Unit* unit_free(Unit *u);
DEFINE_TRIVIAL_CLEANUP_FUNC(Unit *, unit_free);
assert_se(manager_load_startable_unit_or_warn(m, "parent-deep.slice", NULL, &parent_deep) >= 0);
assert_se(manager_load_startable_unit_or_warn(m, "nomem.slice", NULL, &nomem_parent) >= 0);
assert_se(manager_load_startable_unit_or_warn(m, "nomemleaf.service", NULL, &nomem_leaf) >= 0);
- assert_se(UNIT_DEREF(son->slice) == parent);
- assert_se(UNIT_DEREF(daughter->slice) == parent);
- assert_se(UNIT_DEREF(parent_deep->slice) == parent);
- assert_se(UNIT_DEREF(grandchild->slice) == parent_deep);
- assert_se(UNIT_DEREF(nomem_leaf->slice) == nomem_parent);
- root = UNIT_DEREF(parent->slice);
- assert_se(UNIT_DEREF(nomem_parent->slice) == root);
+ assert_se(UNIT_GET_SLICE(son) == parent);
+ assert_se(UNIT_GET_SLICE(daughter) == parent);
+ assert_se(UNIT_GET_SLICE(parent_deep) == parent);
+ assert_se(UNIT_GET_SLICE(grandchild) == parent_deep);
+ assert_se(UNIT_GET_SLICE(nomem_leaf) == nomem_parent);
+ root = UNIT_GET_SLICE(parent);
+ assert_se(UNIT_GET_SLICE(nomem_parent) == root);
/* Verify per-unit cgroups settings. */
ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(son), CGROUP_MASK_CPU);
assert_se(manager_load_startable_unit_or_warn(m, "dml.slice", NULL, &dml) >= 0);
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough.slice", NULL, &dml_passthrough) >= 0);
- assert_se(UNIT_DEREF(dml_passthrough->slice) == dml);
+ assert_se(UNIT_GET_SLICE(dml_passthrough) == dml);
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-empty.service", NULL, &dml_passthrough_empty) >= 0);
- assert_se(UNIT_DEREF(dml_passthrough_empty->slice) == dml_passthrough);
+ assert_se(UNIT_GET_SLICE(dml_passthrough_empty) == dml_passthrough);
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-dml.service", NULL, &dml_passthrough_set_dml) >= 0);
- assert_se(UNIT_DEREF(dml_passthrough_set_dml->slice) == dml_passthrough);
+ assert_se(UNIT_GET_SLICE(dml_passthrough_set_dml) == dml_passthrough);
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-ml.service", NULL, &dml_passthrough_set_ml) >= 0);
- assert_se(UNIT_DEREF(dml_passthrough_set_ml->slice) == dml_passthrough);
+ assert_se(UNIT_GET_SLICE(dml_passthrough_set_ml) == dml_passthrough);
assert_se(manager_load_startable_unit_or_warn(m, "dml-override.slice", NULL, &dml_override) >= 0);
- assert_se(UNIT_DEREF(dml_override->slice) == dml);
+ assert_se(UNIT_GET_SLICE(dml_override) == dml);
assert_se(manager_load_startable_unit_or_warn(m, "dml-override-empty.service", NULL, &dml_override_empty) >= 0);
- assert_se(UNIT_DEREF(dml_override_empty->slice) == dml_override);
+ assert_se(UNIT_GET_SLICE(dml_override_empty) == dml_override);
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard.slice", NULL, &dml_discard) >= 0);
- assert_se(UNIT_DEREF(dml_discard->slice) == dml);
+ assert_se(UNIT_GET_SLICE(dml_discard) == dml);
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard-empty.service", NULL, &dml_discard_empty) >= 0);
- assert_se(UNIT_DEREF(dml_discard_empty->slice) == dml_discard);
+ assert_se(UNIT_GET_SLICE(dml_discard_empty) == dml_discard);
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard-set-ml.service", NULL, &dml_discard_set_ml) >= 0);
- assert_se(UNIT_DEREF(dml_discard_set_ml->slice) == dml_discard);
+ assert_se(UNIT_GET_SLICE(dml_discard_set_ml) == dml_discard);
- root = UNIT_DEREF(dml->slice);
- assert_se(!UNIT_ISSET(root->slice));
+ assert_se(root = UNIT_GET_SLICE(dml));
+ assert_se(!UNIT_GET_SLICE(root));
assert_se(unit_get_ancestor_memory_low(root) == CGROUP_LIMIT_MIN);