Skip to contentSkip to conversation

umount of unreachable NFS without -f [maybe PATCH]

PATCH Stanislav Brabec 2 participants 4 messages Sep 2, 2014 – Sep 3, 2014 Util-Linux package

lore
Share & tools
lore
#0 lore raw

I just analyzed causes of hang while calling umount without -f on an unreachable NFS.

The first hang happens on in lookup_umount_fs():

stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

I don't exactly know, what its removal causes, but I tried it.

I entered into next hang in mnt_resolve_path() inside has_utab_entry(). We cannot prevent this hang in all cases, but preventing it in a standard situation is pretty straightforward: Try to match provided target name before trying to canonicalize.

Now my umount without -f works well at least in the case, when the mount point is recorded in the utab.

If it is not recorded in utab, it still hangs later in lookup_umount_fs() on:

if (statfs(tgt, &vfs) == 0)

Well, we can prevent even this hang, but it would be at cost of parsing mtab. I read your git comments and I see, that the whole purpose of the code is preventing of parsing of the generated mtab/mountinfo.

Would be parsing of fstab a safe way without paying this cost?

Here is my patch, which prevented at least part of these hangs. What do you think about it?

libmount/src/context_umount.c +8 -2
Index: util-linux-2.25/libmount/src/context_umount.c
===================================================================
@@ -216,6 +255,14 @@ static int has_utab_entry(struct libmnt_
 
 	/* paths in utab are canonicalized */
 	cache = mnt_context_get_cache(cxt);
+
+	/* first search for target as it is - mnt_resolve_path() can fail on unreachable NFS */
+	mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+
+	while (mnt_table_next_fs(cxt->utab, &itr, &fs) == 0) {
+		if (mnt_fs_streq_target(fs, target))
+			return 1;
+	}
 	cn = mnt_resolve_path(target, cache);
 	mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
 
@@ -232,7 +279,6 @@ static int has_utab_entry(struct libmnt_
 static int lookup_umount_fs(struct libmnt_context *cxt)
 {
 	const char *tgt;
-	struct stat st;
 	struct libmnt_fs *fs = NULL;
 	int rc = 0;
 
@@ -262,7 +308,6 @@ static int lookup_umount_fs(struct libmn
 	    && !mnt_context_mtab_writable(cxt)
 	    && !mnt_context_is_force(cxt)
 	    && !mnt_context_is_lazy(cxt)
-	    && stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)
 	    && !has_utab_entry(cxt, tgt)) {
 
 		const char *type = mnt_fs_get_fstype(cxt->fs);
Signature · 10 lines
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: [email protected]
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
maintainer
#1 lore raw
Quoted 20 lines · Stanislav Brabec

I just analyzed causes of hang while calling umount without -f on an unreachable NFS.

The first hang happens on in lookup_umount_fs():

stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

I don't exactly know, what its removal causes, but I tried it.

I entered into next hang in mnt_resolve_path() inside has_utab_entry(). We cannot prevent this hang in all cases, but preventing it in a standard situation is pretty straightforward: Try to match provided target name before trying to canonicalize.

Now my umount without -f works well at least in the case, when the mount point is recorded in the utab.

If it is not recorded in utab, it still hangs later in lookup_umount_fs() on:

Quoted 7 lines

if (statfs(tgt, &vfs) == 0)

Well, we can prevent even this hang, but it would be at cost of parsing mtab. I read your git comments and I see, that the whole purpose of the code is preventing of parsing of the generated mtab/mountinfo.

Would be parsing of fstab a safe way without paying this cost?

How often do you have NFS mounts without entry within utab? I think it's pretty unusual (I guess you have mount.nfs linked with libmount).

The change in has_utab_entry() is definitely good idea, but I'm not sure about the rest. Maybe it would be enough to call has_utab_entry() before

    stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

then it will be good enough for almost all NFS mounts (with utab entries).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
maintainer
#3 lore raw
In reply to Stanislav Brabec
Quoted 8 lines · Stanislav Brabec

I just analyzed causes of hang while calling umount without -f on an unreachable NFS.

The first hang happens on in lookup_umount_fs():

stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

I don't exactly know, what its removal causes, but I tried it.

The stat() is there to detect situations when someone calls

umount /dev/sda1

then you don't want to call statfs() to get fs type, because the device is not a mountpoint. Note that statfs() works with arbitrary file, so we have to be careful...

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
In reply to Karel Zak
Quoted 23 lines · Karel Zak
Quoted 22 lines · Stanislav Brabec

I just analyzed causes of hang while calling umount without -f on an unreachable NFS.

The first hang happens on in lookup_umount_fs():

stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

I don't exactly know, what its removal causes, but I tried it.

I entered into next hang in mnt_resolve_path() inside has_utab_entry(). We cannot prevent this hang in all cases, but preventing it in a standard situation is pretty straightforward: Try to match provided target name before trying to canonicalize.

Now my umount without -f works well at least in the case, when the mount point is recorded in the utab.

If it is not recorded in utab, it still hangs later in lookup_umount_fs() on:

if (statfs(tgt, &vfs) == 0)

Quoted 8 lines
Quoted 5 lines

Well, we can prevent even this hang, but it would be at cost of parsing mtab. I read your git comments and I see, that the whole purpose of the code is preventing of parsing of the generated mtab/mountinfo.

Would be parsing of fstab a safe way without paying this cost?

How often do you have NFS mounts without entry within utab? I think it's pretty unusual (I guess you have mount.nfs linked with libmount).

I did it somehow. Guessing that it could have something with my experiments, killing hanging umount with signal 11 etc.

Quoted 9 lines

The change in has_utab_entry() is definitely good idea, but I'm not sure about the rest. Maybe it would be enough to call has_utab_entry() before

    stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)

then it will be good enough for almost all NFS mounts (with utab entries).

Yes, I just verified that it helps as well.

But I found just another stat() call further in
mnt_context_find_umount_fs():
if (stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)) {
before cache lookups.

And next there is:
cn_tgt = mnt_resolve_path(tgt, cache);
which will probably hang as well.

I can imagine that we will not uses stat() here, but I cannot imagine, how to set filter correctly without canonicalization.

I am just curious why one of my umount attempts of unresponsive NFS succeeded yesterday...

Signature · 10 lines
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: [email protected]
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76