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