[systemd-devel] [PATCH V2] mount: fix network mounts

harald at redhat.com harald at redhat.com
Fri Mar 8 08:17:39 PST 2013


From: Harald Hoyer <harald at redhat.com>

Now works as expected for me.

$ mount 192.168.2.2:/Public /mnt/test
$ systemctl status mnt-test.mount
mnt-test.mount - /mnt/test
	  Loaded: loaded (/proc/self/mountinfo)
	  Active: active (mounted) since Fr 2013-03-08 16:24:38 CET; 11s ago
	   Where: /mnt/test
	    What: 192.168.2.2:/Public

Mär 08 16:24:38 lenovo systemd[1]: mnt-test.mount changed dead -> mounted

$ systemctl stop remote-fs.target

$ systemctl status mnt-test.mount
mnt-test.mount - /mnt/test
	  Loaded: loaded (/proc/self/mountinfo)
	  Active: inactive (dead) since Fr 2013-03-08 16:24:57 CET; 1s ago
	   Where: /mnt/test
	 Process: 4968 ExecUnmount=/bin/umount /mnt/test (code=exited, status=0/SUCCESS)

Mär 08 16:24:57 lenovo systemd[1]: Installed new job mnt-test.mount/stop as 744
Mär 08 16:24:57 lenovo systemd[1]: Unmounting /mnt/test...
Mär 08 16:24:57 lenovo systemd[1]: About to execute /bin/umount /mnt/test
Mär 08 16:24:57 lenovo systemd[1]: Forked /bin/umount as 4968
Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed mounted -> unmounting
Mär 08 16:24:57 lenovo systemd[1]: Child 4968 belongs to mnt-test.mount
Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount mount process exited, code=exited status=0
Mär 08 16:24:57 lenovo systemd[1]: mnt-test.mount changed unmounting -> dead
Mär 08 16:24:57 lenovo systemd[1]: Job mnt-test.mount/stop finished, result=done
Mär 08 16:24:57 lenovo systemd[1]: Unmounted /mnt/test.
---
 src/core/mount.c                      | 18 +++++++++++++++---
 src/fstab-generator/fstab-generator.c |  4 ++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/core/mount.c b/src/core/mount.c
index 419cf27..0a8e197 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -441,28 +441,38 @@ static int mount_add_default_dependencies(Mount *m) {
         int r;
         MountParameters *p;
         const char *after;
+        const char *before;
 
         assert(m);
 
         if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM)
                 return 0;
 
-        p = get_mount_parameters_fragment(m);
+        p = get_mount_parameters(m);
+
         if (!p)
                 return 0;
 
         if (path_equal(m->where, "/"))
                 return 0;
 
-        if (mount_is_network(p))
+        if (mount_is_network(p)) {
                 after = SPECIAL_REMOTE_FS_PRE_TARGET;
-        else
+                before = SPECIAL_REMOTE_FS_TARGET;
+        }
+        else {
                 after = SPECIAL_LOCAL_FS_PRE_TARGET;
+                before = SPECIAL_LOCAL_FS_TARGET;
+        }
 
         r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, after, NULL, true);
         if (r < 0)
                 return r;
 
+        r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_PART_OF, UNIT_BEFORE, before, NULL, true);
+        if (r < 0)
+                return r;
+
         r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
         if (r < 0)
                 return r;
@@ -1516,7 +1526,9 @@ static int mount_add_one(
                 if (u->load_state == UNIT_ERROR) {
                         u->load_state = UNIT_LOADED;
                         u->load_error = 0;
+                }
 
+                if (u->load_state == UNIT_LOADED) {
                         /* Load in the extras later on, after we
                          * finished initialization of the unit */
                         load_extras = true;
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 910bbc1..00f85e9 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -275,6 +275,10 @@ static int add_mount(const char *what, const char *where, const char *type, cons
                         post);
 
         fprintf(f,
+                "PartOf=%s\n",
+                post);
+
+        fprintf(f,
                 "\n"
                 "[Mount]\n"
                 "What=%s\n"
-- 
1.8.1



More information about the systemd-devel mailing list