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