[systemd-commits] 6 commits - src/core src/fstab-generator TODO units/initrd-fs.target units/initrd-root-fs.target units/local-fs.target units/remote-fs.target

Tom Gundersen tomegun at kemper.freedesktop.org
Wed Sep 11 05:47:00 PDT 2013


 TODO                                  |    2 
 src/core/mount.c                      |   38 +++++++-
 src/core/swap.c                       |   18 +++-
 src/fstab-generator/fstab-generator.c |  145 ++--------------------------------
 units/initrd-fs.target                |    2 
 units/initrd-root-fs.target           |    2 
 units/local-fs.target                 |    2 
 units/remote-fs.target                |    2 
 8 files changed, 65 insertions(+), 146 deletions(-)

New commits:
commit 64347fc2b983f33e7efb0fd2bb44e133fb9f30f4
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Aug 21 22:48:56 2013 +0800

    swap: handle nofail/noauto in core

diff --git a/src/core/swap.c b/src/core/swap.c
index f0e19ad..57d15eb 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -197,6 +197,7 @@ static int swap_add_device_links(Swap *s) {
 }
 
 static int swap_add_default_dependencies(Swap *s) {
+        bool nofail = false, noauto = false;
         int r;
 
         assert(s);
@@ -211,6 +212,20 @@ static int swap_add_default_dependencies(Swap *s) {
         if (r < 0)
                 return r;
 
+        if (s->from_fragment) {
+                SwapParameters *p = &s->parameters_fragment;
+
+                nofail = p->nofail;
+                noauto = p->noauto;
+        }
+
+        if (!noauto) {
+                r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, (nofail ? UNIT_WANTED_BY : UNIT_REQUIRED_BY),
+                                                      SPECIAL_SWAP_TARGET, NULL, true);
+                if (r < 0)
+                        return r;
+        }
+
         return 0;
 }
 
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index e780018..6ebe8aa 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -38,22 +38,6 @@
 static const char *arg_dest = "/tmp";
 static bool arg_enabled = true;
 
-static int device_name(const char *path, char **unit) {
-        char *p;
-
-        assert(path);
-
-        if (!is_device_path(path))
-                return 0;
-
-        p = unit_name_from_path(path, ".device");
-        if (!p)
-                return log_oom();
-
-        *unit = p;
-        return 1;
-}
-
 static int mount_find_pri(struct mntent *me, int *ret) {
         char *end, *pri;
         unsigned long r;
@@ -82,7 +66,6 @@ static int mount_find_pri(struct mntent *me, int *ret) {
 static int add_swap(const char *what, struct mntent *me) {
         _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        bool noauto, nofail;
         int r, pri = -1;
 
         assert(what);
@@ -94,9 +77,6 @@ static int add_swap(const char *what, struct mntent *me) {
                 return pri;
         }
 
-        noauto = !!hasmntopt(me, "noauto");
-        nofail = !!hasmntopt(me, "nofail");
-
         name = unit_name_from_path(what, ".swap");
         if (!name)
                 return log_oom();
@@ -114,14 +94,10 @@ static int add_swap(const char *what, struct mntent *me) {
                 return -errno;
         }
 
-        fputs("# Automatically generated by systemd-fstab-generator\n\n"
-              "[Unit]\n"
-              "SourcePath=/etc/fstab\n", f);
-
-        if (!noauto && !nofail)
-                fputs("Before=" SPECIAL_SWAP_TARGET "\n", f);
-
         fprintf(f,
+                "# Automatically generated by systemd-fstab-generator\n\n"
+                "[Unit]\n"
+                "SourcePath=/etc/fstab\n"
                 "\n"
                 "[Swap]\n"
                 "What=%s\n",
@@ -138,35 +114,6 @@ static int add_swap(const char *what, struct mntent *me) {
                 return -errno;
         }
 
-        if (!noauto) {
-                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", 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;
-                }
-
-                r = device_name(what, &device);
-                if (r < 0)
-                        return r;
-
-                if (r > 0) {
-                        free(lnk);
-                        lnk = strjoin(arg_dest, "/", device, ".wants/", 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;
-                        }
-                }
-        }
-
         return 0;
 }
 

commit 88ac30a1979365a926bc85a9cd7150da85823077
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Aug 19 12:34:13 2013 +0800

    mount: filesystems mounted in the initrd should not conflict with umount.target in the real root
    
    These mounts should be kept around and unmounted in the shutdown ramfs.
    
    Currently, we will still attempt to umount these in the final kill spree, but
    we should consider avoiding that too. Also, the should_umount function should
    be generalised and put into util.c or something like that, but we are still
    discussing precisely how.

diff --git a/src/core/mount.c b/src/core/mount.c
index d436a84..5c18d4e 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -447,6 +447,21 @@ static int mount_add_quota_links(Mount *m) {
         return 0;
 }
 
+static bool should_umount(Mount *m) {
+        MountParameters *p;
+
+        if (path_equal(m->where, "/") ||
+            path_equal(m->where, "/usr"))
+                return false;
+
+        p = get_mount_parameters(m);
+        if (p && mount_test_option(p->options, "x-initrd.mount") &&
+            !in_initrd())
+                return false;
+
+        return true;
+}
+
 static int mount_add_default_dependencies(Mount *m) {
         const char *after, *after2, *online;
         MountParameters *p;
@@ -491,9 +506,11 @@ static int mount_add_default_dependencies(Mount *m) {
                         return r;
         }
 
-        r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, 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)
+                        return r;
+        }
 
         return 0;
 }
@@ -1553,8 +1570,7 @@ static int mount_add_one(
                 if (r < 0)
                         goto fail;
 
-                if (!path_equal(where, "/") &&
-                    !path_equal(where, "/usr")) {
+                if (should_umount(MOUNT(u))) {
                         r = unit_add_dependency_by_name(u, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
                         if (r < 0)
                                 goto fail;

commit 5073f89f102d98c27c4f3aefb5643b50a5301d10
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Aug 19 17:45:24 2013 +0800

    mount: move device links handling from generator
    
    This makes mount units work like swap units: when the backing device appears
    the mount unit will be started.
    
    v2: the device should want the mount unconditionally, not only for DefaultDependencies=yes

diff --git a/src/core/mount.c b/src/core/mount.c
index c7d29b0..d436a84 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -338,6 +338,12 @@ static bool mount_is_bind(MountParameters *p) {
         return false;
 }
 
+static bool mount_is_auto(MountParameters *p) {
+        assert(p);
+
+        return !mount_test_option(p->options, "noauto");
+}
+
 static bool needs_quota(MountParameters *p) {
         assert(p);
 
@@ -356,6 +362,7 @@ static bool needs_quota(MountParameters *p) {
 
 static int mount_add_device_links(Mount *m) {
         MountParameters *p;
+        bool device_wants_mount = false;
         int r;
 
         assert(m);
@@ -376,7 +383,10 @@ static int mount_add_device_links(Mount *m) {
         if (path_equal(m->where, "/"))
                 return 0;
 
-        r = unit_add_node_link(UNIT(m), p->what, false);
+        if (mount_is_auto(p) && UNIT(m)->manager->running_as == SYSTEMD_SYSTEM)
+                device_wants_mount = true;
+
+        r = unit_add_node_link(UNIT(m), p->what, device_wants_mount);
         if (r < 0)
                 return r;
 
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 6f352d1..e780018 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -170,16 +170,6 @@ static int add_swap(const char *what, struct mntent *me) {
         return 0;
 }
 
-static bool mount_is_bind(struct mntent *me) {
-        assert(me);
-
-        return
-                hasmntopt(me, "bind") ||
-                streq(me->mnt_type, "bind") ||
-                hasmntopt(me, "rbind") ||
-                streq(me->mnt_type, "rbind");
-}
-
 static bool mount_is_network(struct mntent *me) {
         assert(me);
 
@@ -205,14 +195,12 @@ static int add_mount(
                 bool noauto,
                 bool nofail,
                 bool automount,
-                bool isbind,
                 const char *post,
                 const char *source) {
         _cleanup_free_ char
                 *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL,
                 *automount_name = NULL, *automount_unit = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        int r;
 
         assert(what);
         assert(where);
@@ -296,27 +284,6 @@ static int add_mount(
                                 return -errno;
                         }
                 }
-
-                if (!isbind &&
-                    !path_equal(where, "/")) {
-
-                        r = device_name(what, &device);
-                        if (r < 0)
-                                return r;
-
-                        if (r > 0) {
-                                free(lnk);
-                                lnk = strjoin(arg_dest, "/", device, ".wants/", 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, "/")) {
@@ -413,7 +380,7 @@ 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, isbind;
+                        bool noauto, nofail, automount;
                         const char *post;
 
                         noauto = !!hasmntopt(me, "noauto");
@@ -421,7 +388,6 @@ static int parse_fstab(const char *prefix, bool initrd) {
                         automount =
                                   hasmntopt(me, "comment=systemd.automount") ||
                                   hasmntopt(me, "x-systemd.automount");
-                        isbind = mount_is_bind(me);
 
                         if (initrd) {
                                 post = SPECIAL_INITRD_FS_TARGET;
@@ -435,7 +401,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
 
                         k = add_mount(what, where, me->mnt_type, me->mnt_opts,
                                       me->mnt_passno, noauto, nofail, automount,
-                                      isbind, post, fstab_path);
+                                      post, fstab_path);
                 }
 
                 if (k < 0)
@@ -523,7 +489,7 @@ 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,
-                      false, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
+                      SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
 
         return (r < 0) ? r : 0;
 }

commit b56a422a919ec5a12f8fa7f9dfc63f7d88c6a077
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Aug 21 22:47:26 2013 +0800

    swap: backing device should unconditionally want swap unit
    
    There is no need to restrict this to only the 'nofail' case. In the '!nofail'
    case the unit is already wanted by swap.target, so this is not a functional change.

diff --git a/src/core/swap.c b/src/core/swap.c
index 825503f..f0e19ad 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -187,8 +187,7 @@ static int swap_add_device_links(Swap *s) {
                 return 0;
 
         if (is_device_path(s->what))
-                return unit_add_node_link(UNIT(s), s->what,
-                                          !p->noauto && p->nofail &&
+                return unit_add_node_link(UNIT(s), s->what, !p->noauto &&
                                           UNIT(s)->manager->running_as == SYSTEMD_SYSTEM);
         else
                 /* File based swap devices need to be ordered after

commit 80c3b720bf3abbcc9427507d540e286c4ceb3e94
Author: Tom Gundersen <teg at jklm.no>
Date:   Mon Aug 19 09:20:52 2013 +0800

    fstab-generator: use DefaultDependencies=yes
    
    This removes some redundancy between the generator and the core mount handling.

diff --git a/TODO b/TODO
index 59e0f97..b1006bf 100644
--- a/TODO
+++ b/TODO
@@ -220,8 +220,6 @@ Features:
   /etc should always override /run+/usr and also any symlink
   destination.
 
-* remove duplicate default deps logic from fstab-generator vs. mount.c
-
 * when isolating, try to figure out a way how we implicitly can order
   all units we stop before the isolating unit...
 
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 2a779bb..6f352d1 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -116,10 +116,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
         fputs("# Automatically generated by systemd-fstab-generator\n\n"
               "[Unit]\n"
-              "SourcePath=/etc/fstab\n"
-              "DefaultDependencies=no\n"
-              "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
-              "Before=" SPECIAL_UMOUNT_TARGET "\n", f);
+              "SourcePath=/etc/fstab\n", f);
 
         if (!noauto && !nofail)
                 fputs("Before=" SPECIAL_SWAP_TARGET "\n", f);
@@ -209,9 +206,6 @@ static int add_mount(
                 bool nofail,
                 bool automount,
                 bool isbind,
-                const char *pre,
-                const char *pre2,
-                const char *online,
                 const char *post,
                 const char *source) {
         _cleanup_free_ char
@@ -258,33 +252,9 @@ static int add_mount(
         fprintf(f,
               "# Automatically generated by systemd-fstab-generator\n\n"
               "[Unit]\n"
-              "SourcePath=%s\n"
-              "DefaultDependencies=no\n",
+              "SourcePath=%s\n",
               source);
 
-        if (!path_equal(where, "/")) {
-                if (pre)
-                        fprintf(f,
-                                "After=%s\n",
-                                pre);
-
-                if (pre2)
-                        fprintf(f,
-                                "After=%s\n",
-                                pre2);
-
-                if (online)
-                        fprintf(f,
-                                "After=%s\n"
-                                "Wants=%s\n",
-                                online,
-                                online);
-
-                fprintf(f,
-                        "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
-                        "Before=" SPECIAL_UMOUNT_TARGET "\n");
-        }
-
         if (post && !noauto && !nofail && !automount)
                 fprintf(f,
                         "Before=%s\n",
@@ -368,10 +338,7 @@ static int add_mount(
                 fprintf(f,
                         "# Automatically generated by systemd-fstab-generator\n\n"
                         "[Unit]\n"
-                        "SourcePath=%s\n"
-                        "DefaultDependencies=no\n"
-                        "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
-                        "Before=" SPECIAL_UMOUNT_TARGET "\n",
+                        "SourcePath=%s\n",
                         source);
 
                 if (post)
@@ -447,7 +414,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
                         k = add_swap(what, me);
                 else {
                         bool noauto, nofail, automount, isbind;
-                        const char *pre, *pre2, *post, *online;
+                        const char *post;
 
                         noauto = !!hasmntopt(me, "noauto");
                         nofail = !!hasmntopt(me, "nofail");
@@ -457,25 +424,18 @@ static int parse_fstab(const char *prefix, bool initrd) {
                         isbind = mount_is_bind(me);
 
                         if (initrd) {
-                                pre = pre2 = online = NULL;
                                 post = SPECIAL_INITRD_FS_TARGET;
                         } else if (mount_in_initrd(me)) {
-                                pre = pre2 = online = NULL;
                                 post = SPECIAL_INITRD_ROOT_FS_TARGET;
                         } else if (mount_is_network(me)) {
-                                pre = SPECIAL_REMOTE_FS_PRE_TARGET;
-                                pre2 = SPECIAL_NETWORK_TARGET;
-                                online = SPECIAL_NETWORK_ONLINE_TARGET;
                                 post = SPECIAL_REMOTE_FS_TARGET;
                         } else {
-                                pre = SPECIAL_LOCAL_FS_PRE_TARGET;
-                                pre2 = online = NULL;
                                 post = SPECIAL_LOCAL_FS_TARGET;
                         }
 
                         k = add_mount(what, where, me->mnt_type, me->mnt_opts,
                                       me->mnt_passno, noauto, nofail, automount,
-                                      isbind, pre, pre2, online, post, fstab_path);
+                                      isbind, post, fstab_path);
                 }
 
                 if (k < 0)
@@ -563,7 +523,7 @@ 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,
-                      false, NULL, NULL, NULL, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
+                      false, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline");
 
         return (r < 0) ? r : 0;
 }

commit 40f862e3aee1a7712a4867b807e6ab96173bd9cb
Author: Tom Gundersen <teg at jklm.no>
Date:   Thu Aug 22 10:09:39 2013 +0800

    filesystem targets: disable default dependencies
    
    This means we can use default dependencies on mount units without having to get them automatically
    ordered before the filesystem targets.
    
    Reported-by: Thomas Baechler <thomas at archlinux.org>

diff --git a/units/initrd-fs.target b/units/initrd-fs.target
index 7578b88..866f0d0 100644
--- a/units/initrd-fs.target
+++ b/units/initrd-fs.target
@@ -12,3 +12,5 @@ OnFailure=emergency.target
 OnFailureIsolate=yes
 ConditionPathExists=/etc/initrd-release
 After=initrd-parse-etc.service
+DefaultDependencies=no
+Conflicts=shutdown.target
diff --git a/units/initrd-root-fs.target b/units/initrd-root-fs.target
index cd189f0..d0b9863 100644
--- a/units/initrd-root-fs.target
+++ b/units/initrd-root-fs.target
@@ -11,3 +11,5 @@ Documentation=man:systemd.special(7)
 ConditionPathExists=/etc/initrd-release
 OnFailure=emergency.target
 OnFailureIsolate=yes
+DefaultDependencies=no
+Conflicts=shutdown.target
diff --git a/units/local-fs.target b/units/local-fs.target
index 18c3d74..8f06ed6 100644
--- a/units/local-fs.target
+++ b/units/local-fs.target
@@ -9,5 +9,7 @@
 Description=Local File Systems
 Documentation=man:systemd.special(7)
 After=local-fs-pre.target
+DefaultDependencies=no
+Conflicts=shutdown.target
 OnFailure=emergency.target
 OnFailureIsolate=no
diff --git a/units/remote-fs.target b/units/remote-fs.target
index 09213e8..43ffa5c 100644
--- a/units/remote-fs.target
+++ b/units/remote-fs.target
@@ -9,6 +9,8 @@
 Description=Remote File Systems
 Documentation=man:systemd.special(7)
 After=remote-fs-pre.target
+DefaultDependencies=no
+Conflicts=shutdown.target
 
 [Install]
 WantedBy=multi-user.target



More information about the systemd-commits mailing list