mirror of
https://github.com/systemd/systemd.git
synced 2025-09-09 17:44:49 +03:00
core: suppress various defaults deps for credentials mounts
The per-unit credentials mounts might show up for any kind of service, including very very early ones. Hence let's not order them after local-fs-pre.target, because otherwise we might trigger cyclic deps of services that want to plug before that but still use credentials.
This commit is contained in:
@@ -473,6 +473,22 @@ static bool mount_is_extrinsic(Unit *u) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool mount_is_credentials(Mount *m) {
|
||||||
|
const char *e;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
/* Returns true if this is a credentials mount. We don't want automatic dependencies on credential
|
||||||
|
* mounts, since they are managed by us for even the earliest services, and we never want anything to
|
||||||
|
* be ordered before them hence. */
|
||||||
|
|
||||||
|
e = path_startswith(m->where, UNIT(m)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
|
||||||
|
if (!e)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !isempty(path_startswith(e, "credentials"));
|
||||||
|
}
|
||||||
|
|
||||||
static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p, UnitDependencyMask mask) {
|
static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p, UnitDependencyMask mask) {
|
||||||
const char *after, *before, *e;
|
const char *after, *before, *e;
|
||||||
int r;
|
int r;
|
||||||
@@ -495,7 +511,10 @@ static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p,
|
|||||||
after = SPECIAL_LOCAL_FS_PRE_TARGET;
|
after = SPECIAL_LOCAL_FS_PRE_TARGET;
|
||||||
before = SPECIAL_INITRD_USR_FS_TARGET;
|
before = SPECIAL_INITRD_USR_FS_TARGET;
|
||||||
|
|
||||||
} else if (mount_is_network(p)) {
|
} else if (mount_is_credentials(m))
|
||||||
|
after = before = NULL;
|
||||||
|
|
||||||
|
else if (mount_is_network(p)) {
|
||||||
after = SPECIAL_REMOTE_FS_PRE_TARGET;
|
after = SPECIAL_REMOTE_FS_PRE_TARGET;
|
||||||
before = SPECIAL_REMOTE_FS_TARGET;
|
before = SPECIAL_REMOTE_FS_TARGET;
|
||||||
|
|
||||||
@@ -504,18 +523,32 @@ static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p,
|
|||||||
before = SPECIAL_LOCAL_FS_TARGET;
|
before = SPECIAL_LOCAL_FS_TARGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mount_is_nofail(m)) {
|
if (before && !mount_is_nofail(m)) {
|
||||||
r = unit_add_dependency_by_name(UNIT(m), UNIT_BEFORE, before, /* add_reference= */ true, mask);
|
r = unit_add_dependency_by_name(UNIT(m), UNIT_BEFORE, before, /* add_reference= */ true, mask);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, /* add_reference= */ true, mask);
|
if (after) {
|
||||||
|
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, /* add_reference= */ true, mask);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET,
|
||||||
|
/* add_reference= */ true, mask);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET,
|
/* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
|
||||||
/* add_reference= */ true, mask);
|
if (streq_ptr(p->fstype, "tmpfs") && !mount_is_credentials(m)) {
|
||||||
|
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_SWAP_TARGET,
|
||||||
|
/* add_reference= */ true, mask);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mount_add_default_dependencies(Mount *m) {
|
static int mount_add_default_dependencies(Mount *m) {
|
||||||
@@ -567,14 +600,6 @@ static int mount_add_default_dependencies(Mount *m) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is a tmpfs mount then we have to unmount it before we try to deactivate swaps */
|
|
||||||
if (streq_ptr(p->fstype, "tmpfs")) {
|
|
||||||
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_SWAP_TARGET,
|
|
||||||
/* add_reference= */ true, mask);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
|
return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user