fstab-generator: fix automount option and don't start associated mount unit at boot
authorFranck Bui <fbui@suse.com>
Tue, 1 Dec 2015 17:01:44 +0000 (18:01 +0100)
committerFranck Bui <fbui@suse.com>
Fri, 4 Mar 2016 21:09:08 +0000 (22:09 +0100)
Without this patch applied the mount unit with 'automount' option was still
pulled by local-fs.target and thus was activated during the boot process which
defeats the purpose of the 'automount' option:

   $ grep /mnt /etc/fstab
   /dev/vdb1 /mnt ext2 defaults,x-systemd.automount 0 0

   $ reboot
   ...

   $ mount | grep mnt
   systemd-1 on /mnt type autofs (rw,relatime,fd=34,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
   /dev/vdb1 on /mnt type ext2 (rw,relatime)

   $ systemctl status mnt.mount | grep Active
      Active: active (mounted) since Thu 2016-03-03 21:36:22 CET; 42s ago

With the patch applied:

   $ reboot
   ...

   $ mount | grep mnt
   systemd-1 on /mnt type autofs (rw,relatime,fd=22,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)

   $ systemctl status mnt.mount | grep Active
      Active: inactive (dead)

   $ ls /mnt
   lost+found

   $ systemctl status mnt.mount | grep Active
      Active: active (mounted) since Thu 2016-03-03 21:47:32 CET; 4s ago

src/core/mount.c
src/fstab-generator/fstab-generator.c

index 93d2bd5..c0026e0 100644 (file)
@@ -104,6 +104,14 @@ static bool mount_is_auto(const MountParameters *p) {
         return !fstab_test_option(p->options, "noauto\0");
 }
 
+static bool mount_is_automount(const MountParameters *p) {
+        assert(p);
+
+        return fstab_test_option(p->options,
+                                 "comment=systemd.automount\0"
+                                 "x-systemd.automount\0");
+}
+
 static bool needs_quota(const MountParameters *p) {
         assert(p);
 
@@ -328,7 +336,8 @@ static int mount_add_device_links(Mount *m) {
         if (path_equal(m->where, "/"))
                 return 0;
 
-        if (mount_is_auto(p) && UNIT(m)->manager->running_as == MANAGER_SYSTEM)
+        if (mount_is_auto(p) && !mount_is_automount(p) &&
+            UNIT(m)->manager->running_as == MANAGER_SYSTEM)
                 device_wants_mount = true;
 
         r = unit_add_node_link(UNIT(m), p->what, device_wants_mount, m->from_fragment ? UNIT_BINDS_TO : UNIT_REQUIRES);
index 97a4876..6f576b5 100644 (file)
@@ -336,8 +336,8 @@ static int add_mount(
         if (r < 0)
                 return log_error_errno(r, "Failed to write unit file %s: %m", unit);
 
-        if (!noauto) {
-                lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
+        if (!noauto && !automount) {
+                lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", name, NULL);
                 if (!lnk)
                         return log_oom();