/* We always use 'what' from /proc/self/mountinfo if mounted */
mask = m->from_proc_self_mountinfo ? UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT : UNIT_DEPENDENCY_FILE;
- r = unit_add_node_dependency(UNIT(m), p->what, false, dep, mask);
+ r = unit_add_node_dependency(UNIT(m), p->what, dep, mask);
if (r < 0)
return r;
if (!MANAGER_IS_SYSTEM(UNIT(m)->manager)) /* We only automatically manage mounts if we are in system mode */
return true;
+ if (UNIT(m)->perpetual) /* All perpetual units never change state */
+ return true;
+
if (PATH_IN_SET(m->where, /* Don't bother with the OS data itself */
- "/",
- "/usr"))
+ "/", /* (strictly speaking redundant: should already be covered by the perpetual flag check above) */
+ "/usr",
+ "/etc"))
return true;
if (PATH_STARTSWITH_SET(m->where,
int r;
assert(m);
-
- if (UNIT(m)->load_state != UNIT_LOADED)
- return 0;
+ assert(UNIT(m)->load_state == UNIT_LOADED);
if (!m->from_fragment && !m->from_proc_self_mountinfo && !UNIT(m)->perpetual)
return -ENOENT;
}
p = get_mount_parameters_fragment(m);
- if (p && !p->what) {
- log_unit_error(UNIT(m), "What= setting is missing. Refusing.");
- return -ENOEXEC;
- }
+ if (p && !p->what && !UNIT(m)->perpetual)
+ return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC),
+ "What= setting is missing. Refusing.");
if (m->exec_context.pam_name && m->kill_context.kill_mode != KILL_CONTROL_GROUP) {
log_unit_error(UNIT(m), "Unit has PAM enabled. Kill mode must be set to control-group'. Refusing.");
return 0;
}
+static int mount_add_non_exec_dependencies(Mount *m) {
+ int r;
+ assert(m);
+
+ /* Adds in all dependencies directly responsible for ordering the mount, as opposed to dependencies
+ * resulting from the ExecContext and such. */
+
+ r = mount_add_device_dependencies(m);
+ if (r < 0)
+ return r;
+
+ r = mount_add_mount_dependencies(m);
+ if (r < 0)
+ return r;
+
+ r = mount_add_quota_dependencies(m);
+ if (r < 0)
+ return r;
+
+ r = mount_add_default_dependencies(m);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
static int mount_add_extras(Mount *m) {
Unit *u = UNIT(m);
int r;
return r;
}
- r = mount_add_device_dependencies(m);
- if (r < 0)
- return r;
-
- r = mount_add_mount_dependencies(m);
- if (r < 0)
- return r;
-
- r = mount_add_quota_dependencies(m);
- if (r < 0)
- return r;
-
r = unit_patch_contexts(u);
if (r < 0)
return r;
if (r < 0)
return r;
- r = mount_add_default_dependencies(m);
+ r = mount_add_non_exec_dependencies(m);
if (r < 0)
return r;
return 0;
}
-static int mount_load_root_mount(Unit *u) {
+static void mount_load_root_mount(Unit *u) {
assert(u);
if (!unit_has_name(u, SPECIAL_ROOT_MOUNT))
- return 0;
+ return;
u->perpetual = true;
u->default_dependencies = false;
if (!u->description)
u->description = strdup("Root Mount");
-
- return 1;
}
static int mount_load(Unit *u) {
Mount *m = MOUNT(u);
- int r, q, w;
+ int r, q = 0;
assert(u);
assert(u->load_state == UNIT_STUB);
- r = mount_load_root_mount(u);
+ mount_load_root_mount(u);
- if (m->from_proc_self_mountinfo || u->perpetual)
- q = unit_load_fragment_and_dropin_optional(u);
- else
- q = unit_load_fragment_and_dropin(u);
+ bool fragment_optional = m->from_proc_self_mountinfo || u->perpetual;
+ r = unit_load_fragment_and_dropin(u, !fragment_optional);
/* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the
* kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus
* we need to update the state in our unit to track it. After all, consider that we don't allow changing the
* 'slice' field for a unit once it is active. */
if (u->load_state == UNIT_LOADED || m->from_proc_self_mountinfo || u->perpetual)
- w = mount_add_extras(m);
- else
- w = 0;
+ q = mount_add_extras(m);
if (r < 0)
return r;
if (q < 0)
return q;
- if (w < 0)
- return w;
+ if (u->load_state != UNIT_LOADED)
+ return 0;
return mount_verify(m);
}
const char *fstype,
MountProcFlags *ret_flags) {
- MountProcFlags flags = MOUNT_PROC_IS_MOUNTED;
int r;
assert(u);
- assert(flags);
+ assert(ret_flags);
if (!MOUNT(u)->where) {
MOUNT(u)->where = strdup(where);
return -ENOMEM;
}
+ /* In case we have multiple mounts established on the same mount point, let's merge flags set already
+ * for the current unit. Note that the flags field is reset on each iteration of reading
+ * /proc/self/mountinfo, hence we know for sure anything already set here is from the current
+ * iteration and thus worthy of taking into account. */
+ MountProcFlags flags =
+ MOUNT(u)->proc_flags | MOUNT_PROC_IS_MOUNTED;
+
r = update_parameters_proc_self_mountinfo(MOUNT(u), what, options, fstype);
if (r < 0)
return r;
if (r > 0)
flags |= MOUNT_PROC_JUST_CHANGED;
- if (!MOUNT(u)->from_proc_self_mountinfo || FLAGS_SET(MOUNT(u)->proc_flags, MOUNT_PROC_JUST_MOUNTED))
+ /* There are two conditions when we consider a mount point just mounted: when we haven't seen it in
+ * /proc/self/mountinfo before or when MOUNT_MOUNTING is our current state. Why bother with the
+ * latter? Shouldn't that be covered by the former? No, during reload it is not because we might then
+ * encounter a new /proc/self/mountinfo in combination with an old mount unit state (since it stems
+ * from the serialized state), and need to catch up. Since we know that the MOUNT_MOUNTING state is
+ * reached when we wait for the mount to appear we hence can assume that if we are in it, we are
+ * actually seeing it established for the first time. */
+ if (!MOUNT(u)->from_proc_self_mountinfo || MOUNT(u)->state == MOUNT_MOUNTING)
flags |= MOUNT_PROC_JUST_MOUNTED;
MOUNT(u)->from_proc_self_mountinfo = true;
unit_remove_dependencies(u, UNIT_DEPENDENCY_MOUNTINFO_IMPLICIT);
- r = mount_add_extras(MOUNT(u));
+ r = mount_add_non_exec_dependencies(MOUNT(u));
if (r < 0)
return r;
}
"Install\0",
.private_section = "Mount",
+ .can_transient = true,
+ .can_fail = true,
+
.init = mount_init,
.load = mount_load,
.done = mount_done,
.get_timeout = mount_get_timeout,
- .can_transient = true,
-
.enumerate_perpetual = mount_enumerate_perpetual,
.enumerate = mount_enumerate,
.shutdown = mount_shutdown,