[systemd-devel] [PATCH 2/3] mount: move the last of the default dependency handling to core
Tom Gundersen
teg at jklm.no
Fri Sep 13 03:55:47 PDT 2013
With this also Before, RequiredBy and WantedBy is handled by core. It is
dependent on the decoupling of the automount units from the mount options.
---
src/core/mount.c | 53 +++++++++++++++++++--
src/fstab-generator/fstab-generator.c | 88 ++++++++---------------------------
2 files changed, 69 insertions(+), 72 deletions(-)
diff --git a/src/core/mount.c b/src/core/mount.c
index 5c18d4e..fb239d9 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -338,6 +338,19 @@ static bool mount_is_bind(MountParameters *p) {
return false;
}
+static bool mount_is_automount(MountParameters *p) {
+ assert (p);
+
+ return !!mount_test_option(p->options, "x-systemd.automount") ||
+ !!mount_test_option(p->options, "comment=systemd.automount");
+}
+
+static bool mount_is_fail(MountParameters *p) {
+ assert(p);
+
+ return !mount_test_option(p->options, "nofail");
+}
+
static bool mount_is_auto(MountParameters *p) {
assert(p);
@@ -463,7 +476,7 @@ static bool should_umount(Mount *m) {
}
static int mount_add_default_dependencies(Mount *m) {
- const char *after, *after2, *online;
+ const char *after, *after2 = NULL, *online = NULL, *before, *before2 = NULL;
MountParameters *p;
int r;
@@ -486,8 +499,16 @@ static int mount_add_default_dependencies(Mount *m) {
online = SPECIAL_NETWORK_ONLINE_TARGET;
} else {
after = SPECIAL_LOCAL_FS_PRE_TARGET;
- after2 = NULL;
- online = NULL;
+ }
+
+ if (in_initrd()) {
+ before = SPECIAL_INITRD_FS_TARGET;
+ before2 = SPECIAL_INITRD_ROOT_FS_TARGET;
+ } else {
+ if(mount_is_network(p))
+ before = SPECIAL_REMOTE_FS_TARGET;
+ else
+ before = SPECIAL_LOCAL_FS_TARGET;
}
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, NULL, true);
@@ -506,6 +527,32 @@ static int mount_add_default_dependencies(Mount *m) {
return r;
}
+ if (mount_is_auto(p)) {
+ if (mount_is_fail(p) && !mount_is_automount(p)) {
+ r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_REQUIRED_BY, UNIT_BEFORE,
+ before, NULL, true);
+ if (r < 0)
+ return r;
+
+ if (before2) {
+ r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_REQUIRED_BY, UNIT_BEFORE,
+ before2, NULL, true);
+ if (r < 0)
+ return r;
+ }
+ } else {
+ r = unit_add_dependency_by_name(UNIT(m), UNIT_WANTED_BY, before, NULL, true);
+ if (r < 0)
+ return r;
+
+ if (before2) {
+ r = unit_add_dependency_by_name(UNIT(m), UNIT_WANTED_BY, before2, NULL, true);
+ if (r < 0)
+ return r;
+ }
+ }
+ }
+
if (should_umount(m)) {
r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
if (r < 0)
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 02052ea..85051f5 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -117,33 +117,28 @@ static int add_swap(const char *what, struct mntent *me) {
return 0;
}
-static bool mount_is_network(struct mntent *me) {
+static bool mount_is_automount(struct mntent *me) {
assert(me);
- return
- hasmntopt(me, "_netdev") ||
- fstype_is_network(me->mnt_type);
+ return hasmntopt(me, "x-systemd.automount") ||
+ hasmntopt(me, "comment=systemd.automount");
}
static bool mount_in_initrd(struct mntent *me) {
assert(me);
- return
- hasmntopt(me, "x-initrd.mount") ||
- streq(me->mnt_dir, "/usr");
+ return hasmntopt(me, "x-initrd.mount") ||
+ streq(me->mnt_dir, "/usr");
}
static int add_mount(
+ const char *source,
const char *what,
const char *where,
const char *type,
const char *opts,
int passno,
- bool noauto,
- bool nofail,
- bool automount,
- const char *post,
- const char *source) {
+ bool automount) {
_cleanup_free_ char
*name = NULL, *unit = NULL, *lnk = NULL, *device = NULL,
*automount_name = NULL, *automount_unit = NULL;
@@ -185,23 +180,16 @@ static int add_mount(
}
fprintf(f,
- "# Automatically generated by systemd-fstab-generator\n\n"
- "[Unit]\n"
- "SourcePath=%s\n",
- source);
-
- if (post && !noauto && !nofail && !automount)
- fprintf(f,
- "Before=%s\n",
- post);
-
- fprintf(f,
+ "# Automatically generated by systemd-fstab-generator\n\n"
+ "[Unit]\n"
+ "SourcePath=%s\n"
"\n"
"[Mount]\n"
"What=%s\n"
"Where=%s\n"
"Type=%s\n"
"FsckPassNo=%i\n",
+ source,
what,
where,
type,
@@ -219,20 +207,6 @@ static int add_mount(
return -errno;
}
- if (!noauto) {
- if (post) {
- lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
- if (!lnk)
- return log_oom();
-
- mkdir_parents_label(lnk, 0755);
- if (symlink(unit, lnk) < 0) {
- log_error("Failed to create symlink %s: %m", lnk);
- return -errno;
- }
- }
- }
-
if (automount && !path_equal(where, "/")) {
automount_name = unit_name_from_path(where, ".automount");
if (!automount_name)
@@ -269,7 +243,7 @@ static int add_mount(
return 0;
}
-static int parse_fstab(const char *prefix, bool initrd) {
+static int parse_fstab(const char *prefix) {
_cleanup_free_ char *fstab_path = NULL;
FILE *f;
int r = 0;
@@ -292,7 +266,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
_cleanup_free_ char *where = NULL, *what = NULL;
int k;
- if (initrd && !mount_in_initrd(me))
+ if (prefix && !mount_in_initrd(me))
continue;
what = fstab_node_to_udev_node(me->mnt_fsname);
@@ -310,28 +284,8 @@ static int parse_fstab(const char *prefix, bool initrd) {
if (streq(me->mnt_type, "swap"))
k = add_swap(what, me);
else {
- bool noauto, nofail, automount;
- const char *post;
-
- noauto = !!hasmntopt(me, "noauto");
- nofail = !!hasmntopt(me, "nofail");
- automount =
- hasmntopt(me, "comment=systemd.automount") ||
- hasmntopt(me, "x-systemd.automount");
-
- if (initrd) {
- post = SPECIAL_INITRD_FS_TARGET;
- } else if (mount_in_initrd(me)) {
- post = SPECIAL_INITRD_ROOT_FS_TARGET;
- } else if (mount_is_network(me)) {
- post = SPECIAL_REMOTE_FS_TARGET;
- } else {
- post = SPECIAL_LOCAL_FS_TARGET;
- }
-
- k = add_mount(what, where, me->mnt_type, me->mnt_opts,
- me->mnt_passno, noauto, nofail, automount,
- post, fstab_path);
+ k = add_mount(fstab_path, what, where, me->mnt_type, me->mnt_opts,
+ me->mnt_passno, mount_is_automount(me));
}
if (k < 0)
@@ -348,7 +302,6 @@ static int parse_new_root_from_proc_cmdline(void) {
char *w, *state;
int r;
size_t l;
- bool noauto, nofail;
r = read_one_line_file("/proc/cmdline", &line);
if (r < 0) {
@@ -404,9 +357,6 @@ static int parse_new_root_from_proc_cmdline(void) {
}
}
- noauto = !!strstr(opts, "noauto");
- nofail = !!strstr(opts, "nofail");
-
if (!what) {
log_debug("Could not find a root= entry on the kernel commandline.");
return 0;
@@ -418,8 +368,8 @@ static int parse_new_root_from_proc_cmdline(void) {
}
log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
- r = add_mount(what, "/sysroot", type, opts, 0, noauto, nofail, false,
- SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
+
+ r = add_mount("/proc/cmdline", what, "/sysroot", type, opts, 0, false);
return (r < 0) ? r : 0;
}
@@ -499,10 +449,10 @@ int main(int argc, char *argv[]) {
if (!arg_enabled)
return (r < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
- k = parse_fstab(NULL, false);
+ k = parse_fstab(NULL);
if (in_initrd())
- l = parse_fstab("/sysroot", true);
+ l = parse_fstab("/sysroot");
return (r < 0) || (k < 0) || (l < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}
--
1.8.4
More information about the systemd-devel
mailing list