]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: Apply _netdev option also to device units
authorMichal Koutný <mkoutny@suse.com>
Tue, 24 Jan 2017 16:04:32 +0000 (17:04 +0100)
committerMichal Koutný <mkoutny@suse.com>
Tue, 25 Apr 2017 16:00:36 +0000 (18:00 +0200)
In case the device field of fstab record is an actual device (not an address)
apply same dependencies to the device unit as to the mount unit, i.e.

> After=network-online.target network.target
> Wants=network-online.targe

It makes sense to start the device expecting job only when network is actually
ready (consider e.g. iSCSI devices) since it is device's implicit dependency.

The eventual implementation should better obtain network flag from udev
database and would also take into account device hierarchy (see [1]).
This patch approximates that by taking the `_netdev` option as a hint from the
user both about the filesystem and underlying device. (For local devices with
network filesystems (e.g. ocfs2), this hint leads to unused dependencies.)

[1] https://lists.freedesktop.org/archives/systemd-devel/2014-October/024718.html

src/fstab-generator/fstab-generator.c
src/shared/generator.c
src/shared/generator.h

index 2677a3fb3212b78686efaba623303d315d310ca4..43d3308e95b0eae0672073d93cd69b6f1c41c44c 100644 (file)
@@ -399,6 +399,10 @@ static int add_mount(
         if (r < 0)
                 return r;
 
+        r = generator_write_device_deps(dest, what, where, opts);
+        if (r < 0)
+                return r;
+
         r = write_mount_timeout(f, where, opts);
         if (r < 0)
                 return r;
index 9a069b2f97e1c00ba16964423b831331ea5cbb7d..5f6b1de811ae40592fe34e69f32bc24809af81bc 100644 (file)
@@ -192,6 +192,45 @@ int generator_write_timeouts(
                                     program_invocation_short_name, timeout);
 }
 
+int generator_write_device_deps(
+                const char *dir,
+                const char *what,
+                const char *where,
+                const char *opts) {
+
+        /* fstab records that specify _netdev option should apply the network
+         * ordering on the actual device depending on network connection. If we
+         * are not mounting real device (NFS, CIFS), we rely on _netdev effect
+         * on the mount unit itself. */
+
+        _cleanup_free_ char *node = NULL, *unit = NULL;
+        int r;
+
+        if (!fstab_test_option(opts, "_netdev\0"))
+                return 0;
+
+        node = fstab_node_to_udev_node(what);
+        if (!node)
+                return log_oom();
+
+        /* Nothing to apply dependencies to. */
+        if (!is_device_path(node))
+                return 0;
+
+        r = unit_name_from_path(node, ".device", &unit);
+        if (r < 0)
+                return log_error_errno(r, "Failed to make unit name from path: %m");
+
+        /* See mount_add_default_dependencies for explanation why we create such
+         * dependencies. */
+        return write_drop_in_format(dir, unit, 50, "netdev-dependencies",
+                                    "# Automatically generated by %s\n\n"
+                                    "[Unit]\n"
+                                    "After=" SPECIAL_NETWORK_ONLINE_TARGET " " SPECIAL_NETWORK_TARGET "\n"
+                                    "Wants=" SPECIAL_NETWORK_ONLINE_TARGET "\n",
+                                    program_invocation_short_name);
+}
+
 int generator_write_initrd_root_device_deps(const char *dir, const char *what) {
         _cleanup_free_ char *unit = NULL;
         int r;
index a6017c1b76a1970d78903a79d4ce5190eb9d8786..825d934c8e9977651b977b464407cfb312fa96d2 100644 (file)
@@ -35,6 +35,12 @@ int generator_write_timeouts(
         const char *opts,
         char **filtered);
 
+int generator_write_device_deps(
+                const char *dir,
+                const char *what,
+                const char *where,
+                const char *opts);
+
 int generator_write_initrd_root_device_deps(
         const char *dir,
         const char *what);