[systemd-devel] [PATCH 2/2] mount: fix network umounts of manual remote-fs mounts

harald at redhat.com harald at redhat.com
Tue Mar 12 11:41:59 PDT 2013


From: Harald Hoyer <harald at redhat.com>

Revert 6bde0b3, which pulls in remote-fs-pre.target and with this
i.e. NetworkManager-wait-online.service.

Solve the remote-fs problem with using "PartOf".

remote-fs.target is part of multi-user.target, and therefore active by
default. By using UNIT_PART_OF from remote fs mount units to
remote-fs.target, we ensure, that the mount units are unmounted as soon
as remote-fs.target is stopped.

$ 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                      |  6 +++++-
 src/fstab-generator/fstab-generator.c | 15 +++++++++++----
 units/remote-fs.target                |  2 --
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/core/mount.c b/src/core/mount.c
index 895aa25..1100ed6 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -455,8 +455,12 @@ static int mount_add_default_dependencies(Mount *m) {
         if (path_equal(m->where, "/"))
                 return 0;
 
-        if (mount_is_network(p))
+        if (mount_is_network(p)) {
                 after = SPECIAL_REMOTE_FS_PRE_TARGET;
+                r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_PART_OF, SPECIAL_REMOTE_FS_TARGET, NULL, true);
+                if (r < 0)
+                        return r;
+        }
         else
                 after = SPECIAL_LOCAL_FS_PRE_TARGET;
 
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index b4fb134..6b2673e 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -201,7 +201,7 @@ static bool mount_in_initrd(struct mntent *me) {
 
 static int add_mount(const char *what, const char *where, const char *type, const char *opts,
                      int passno, bool noauto, bool nofail, bool automount, bool isbind,
-                     const char *pre, const char *post, const char *source) {
+                     const char *pre, const char *post, const char *partof, const char *source) {
         char _cleanup_free_
                 *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL,
                 *automount_name = NULL, *automount_unit = NULL;
@@ -267,6 +267,12 @@ static int add_mount(const char *what, const char *where, const char *type, cons
                         "Before=%s\n",
                         post);
 
+        if (partof) {
+                fprintf(f,
+                        "PartOf=%s\n",
+                        partof);
+        }
+
         fprintf(f,
                 "\n"
                 "[Mount]\n"
@@ -422,7 +428,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
                         k = add_swap(what, me);
                 else {
                         bool noauto, nofail, automount, isbind;
-                        const char *pre, *post;
+                        const char *pre, *post, *partof = NULL;
 
                         noauto = !!hasmntopt(me, "noauto");
                         nofail = !!hasmntopt(me, "nofail");
@@ -436,6 +442,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
                                 pre = NULL;
                         } else if (mount_is_network(me)) {
                                 post = SPECIAL_REMOTE_FS_TARGET;
+                                partof = SPECIAL_REMOTE_FS_TARGET;
                                 pre = SPECIAL_REMOTE_FS_PRE_TARGET;
                         } else {
                                 post = SPECIAL_LOCAL_FS_TARGET;
@@ -444,7 +451,7 @@ static int parse_fstab(const char *prefix, bool initrd) {
 
                         k = add_mount(what, where, me->mnt_type, me->mnt_opts,
                                      me->mnt_passno, noauto, nofail, automount,
-                                     isbind, pre, post, fstab_path);
+                                     isbind, pre, post, partof, fstab_path);
                 }
 
                 if (k < 0)
@@ -525,7 +532,7 @@ static int parse_new_root_from_proc_cmdline(void) {
 
         log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
         r = add_mount(what, "/sysroot", type, opts, 0, false, false, false,
-                      false, NULL, SPECIAL_ROOT_FS_TARGET, "/proc/cmdline");
+                      false, NULL, SPECIAL_ROOT_FS_TARGET, NULL, "/proc/cmdline");
 
         return (r < 0) ? r : 0;
 }
diff --git a/units/remote-fs.target b/units/remote-fs.target
index b11074f..9e68878 100644
--- a/units/remote-fs.target
+++ b/units/remote-fs.target
@@ -8,8 +8,6 @@
 [Unit]
 Description=Remote File Systems
 Documentation=man:systemd.special(7)
-Wants=remote-fs-pre.target
-After=remote-fs-pre.target
 
 [Install]
 WantedBy=multi-user.target
-- 
1.8.1



More information about the systemd-devel mailing list