a52f674
From 91f1a3f512e1b046267bce7c472c06962f3d9db6 Mon Sep 17 00:00:00 2001
794d16c
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
794d16c
Date: Sat, 5 Oct 2013 13:09:43 -0400
794d16c
Subject: [PATCH] core: do not add "what" to RequiresMountsFor for network
794d16c
 mounts
794d16c
794d16c
For cifs mount like //server/share, we would get
794d16c
RequiresMountsFor=/server/share, which probably isn't
794d16c
harmful, but quite confusing.
794d16c
794d16c
Unfortunately a bunch of static functions had to be moved
794d16c
up, but patch is really one line.
794d16c
---
794d16c
 src/core/mount.c | 137 ++++++++++++++++++++++++++++---------------------------
794d16c
 1 file changed, 70 insertions(+), 67 deletions(-)
794d16c
794d16c
diff --git a/src/core/mount.c b/src/core/mount.c
794d16c
index db055f0..70cd372 100644
794d16c
--- a/src/core/mount.c
794d16c
+++ b/src/core/mount.c
794d16c
@@ -59,6 +59,72 @@ static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
794d16c
         [MOUNT_FAILED] = UNIT_FAILED
794d16c
 };
794d16c
 
794d16c
+static char* mount_test_option(const char *haystack, const char *needle) {
794d16c
+        struct mntent me = { .mnt_opts = (char*) haystack };
794d16c
+
794d16c
+        assert(needle);
794d16c
+
794d16c
+        /* Like glibc's hasmntopt(), but works on a string, not a
794d16c
+         * struct mntent */
794d16c
+
794d16c
+        if (!haystack)
794d16c
+                return NULL;
794d16c
+
794d16c
+        return hasmntopt(&me, needle);
794d16c
+}
794d16c
+
794d16c
+static bool mount_is_network(MountParameters *p) {
794d16c
+        assert(p);
794d16c
+
794d16c
+        if (mount_test_option(p->options, "_netdev"))
794d16c
+                return true;
794d16c
+
794d16c
+        if (p->fstype && fstype_is_network(p->fstype))
794d16c
+                return true;
794d16c
+
794d16c
+        return false;
794d16c
+}
794d16c
+
794d16c
+static bool mount_is_bind(MountParameters *p) {
794d16c
+        assert(p);
794d16c
+
794d16c
+        if (mount_test_option(p->options, "bind"))
794d16c
+                return true;
794d16c
+
794d16c
+        if (p->fstype && streq(p->fstype, "bind"))
794d16c
+                return true;
794d16c
+
794d16c
+        if (mount_test_option(p->options, "rbind"))
794d16c
+                return true;
794d16c
+
794d16c
+        if (p->fstype && streq(p->fstype, "rbind"))
794d16c
+                return true;
794d16c
+
794d16c
+        return false;
794d16c
+}
794d16c
+
794d16c
+static bool mount_is_auto(MountParameters *p) {
794d16c
+        assert(p);
794d16c
+
794d16c
+        return !mount_test_option(p->options, "noauto");
794d16c
+}
794d16c
+
794d16c
+static bool needs_quota(MountParameters *p) {
794d16c
+        assert(p);
794d16c
+
794d16c
+        if (mount_is_network(p))
794d16c
+                return false;
794d16c
+
794d16c
+        if (mount_is_bind(p))
794d16c
+                return false;
794d16c
+
794d16c
+        return mount_test_option(p->options, "usrquota") ||
794d16c
+                mount_test_option(p->options, "grpquota") ||
794d16c
+                mount_test_option(p->options, "quota") ||
794d16c
+                mount_test_option(p->options, "usrjquota") ||
794d16c
+                mount_test_option(p->options, "grpjquota");
794d16c
+}
794d16c
+
794d16c
 static void mount_init(Unit *u) {
794d16c
         Mount *m = MOUNT(u);
794d16c
 
794d16c
@@ -182,7 +248,10 @@ static int mount_add_mount_links(Mount *m) {
794d16c
          * for the source path (if this is a bind mount) to be
794d16c
          * available. */
794d16c
         pm = get_mount_parameters_fragment(m);
794d16c
-        if (pm && pm->what && path_is_absolute(pm->what)) {
794d16c
+        if (pm && pm->what &&
794d16c
+            path_is_absolute(pm->what) &&
794d16c
+            !mount_is_network(pm)) {
794d16c
+
794d16c
                 r = unit_require_mounts_for(UNIT(m), pm->what);
794d16c
                 if (r < 0)
794d16c
                         return r;
794d16c
@@ -214,72 +283,6 @@ static int mount_add_mount_links(Mount *m) {
794d16c
         return 0;
794d16c
 }
794d16c
 
794d16c
-static char* mount_test_option(const char *haystack, const char *needle) {
794d16c
-        struct mntent me = { .mnt_opts = (char*) haystack };
794d16c
-
794d16c
-        assert(needle);
794d16c
-
794d16c
-        /* Like glibc's hasmntopt(), but works on a string, not a
794d16c
-         * struct mntent */
794d16c
-
794d16c
-        if (!haystack)
794d16c
-                return NULL;
794d16c
-
794d16c
-        return hasmntopt(&me, needle);
794d16c
-}
794d16c
-
794d16c
-static bool mount_is_network(MountParameters *p) {
794d16c
-        assert(p);
794d16c
-
794d16c
-        if (mount_test_option(p->options, "_netdev"))
794d16c
-                return true;
794d16c
-
794d16c
-        if (p->fstype && fstype_is_network(p->fstype))
794d16c
-                return true;
794d16c
-
794d16c
-        return false;
794d16c
-}
794d16c
-
794d16c
-static bool mount_is_bind(MountParameters *p) {
794d16c
-        assert(p);
794d16c
-
794d16c
-        if (mount_test_option(p->options, "bind"))
794d16c
-                return true;
794d16c
-
794d16c
-        if (p->fstype && streq(p->fstype, "bind"))
794d16c
-                return true;
794d16c
-
794d16c
-        if (mount_test_option(p->options, "rbind"))
794d16c
-                return true;
794d16c
-
794d16c
-        if (p->fstype && streq(p->fstype, "rbind"))
794d16c
-                return true;
794d16c
-
794d16c
-        return false;
794d16c
-}
794d16c
-
794d16c
-static bool mount_is_auto(MountParameters *p) {
794d16c
-        assert(p);
794d16c
-
794d16c
-        return !mount_test_option(p->options, "noauto");
794d16c
-}
794d16c
-
794d16c
-static bool needs_quota(MountParameters *p) {
794d16c
-        assert(p);
794d16c
-
794d16c
-        if (mount_is_network(p))
794d16c
-                return false;
794d16c
-
794d16c
-        if (mount_is_bind(p))
794d16c
-                return false;
794d16c
-
794d16c
-        return mount_test_option(p->options, "usrquota") ||
794d16c
-                mount_test_option(p->options, "grpquota") ||
794d16c
-                mount_test_option(p->options, "quota") ||
794d16c
-                mount_test_option(p->options, "usrjquota") ||
794d16c
-                mount_test_option(p->options, "grpjquota");
794d16c
-}
794d16c
-
794d16c
 static int mount_add_device_links(Mount *m) {
794d16c
         MountParameters *p;
794d16c
         bool device_wants_mount = false;