summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_umount.c
diff options
context:
space:
mode:
authorNeilBrown2017-06-05 04:32:58 +0200
committerKarel Zak2017-06-06 11:41:05 +0200
commitce6e269447ce86b0c303ec2febbf4264d318c713 (patch)
tree5a530d98a7f5b97cf8e26914f88aa13211fc9ab4 /libmount/src/context_umount.c
parentMerge branch 'fdformat-done1' of https://github.com/jwilk-forks/util-linux (diff)
downloadkernel-qcow2-util-linux-ce6e269447ce86b0c303ec2febbf4264d318c713.tar.gz
kernel-qcow2-util-linux-ce6e269447ce86b0c303ec2febbf4264d318c713.tar.xz
kernel-qcow2-util-linux-ce6e269447ce86b0c303ec2febbf4264d318c713.zip
umount: never 'stat' the path when "-c" is given.
It is currently not possible to reliably and automatically unmount an NFS filesystem. If the server is not available, the umount command will hang. The hang can be avoided by using "-l" or "-f", but neither of these are appropriate for automatic use such as by an automounter (e.g automountd or systemd). "-l" will unmount even if the filesystem is in use, which an automounter generally doesn't want. If the filesystem is in use, then the umount should fail. "-f" can cause the filesystem to abort pending transactions which might break filesystem semantics. This can be useful in the hands of a sysadmin, but not when used by an automatic tool. umount has another option, "-c" aka "--no-canonicalize" which avoids some "stat" calls. Currently this doesn't avoid all calls to canonicalize_path() as mnt_context_prepare_umount() -> lookup_umount_fs() -> mnt_context_find_umount_fs() -> mnt_context_get_mtab_for_target() -> mnt_resolve_path() -> canonicalize_path_and_cache() -> canonicalize_path() leads to that function being called. The "-c" option could be taken to mean "I know what I'm doing, this really is the path to a mount point, I just want you to unmount it". Given that, it seems suitable to extend this to avoid all 'stat' calls on the mountpoint. It is already appropriate for any automount program to pass "-c" to "umount", so they can be changed to do so at any time. With the patch below, "-c" will result in the mountpoint never being "stat"ed, so umount won't hang on an inaccessible server. This isn't quite sufficient, for NFS at least, as the usage of libmount in umount.nfs still calls 'stat' on the mount point. "-c" isn't passed to the umount helper, but it is reasonable for such helpers to assume "-c" because "umount" will have canonicalized the path when that is appropriate. So, this patch treats "-c" much like "-l" and "-f" when deciding whether it is safe to 'stat' the path. Signed-off-by: NeilBrown <neilb@suse.com>
Diffstat (limited to 'libmount/src/context_umount.c')
-rw-r--r--libmount/src/context_umount.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index e663a703c..693891def 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -77,6 +77,7 @@ int mnt_context_find_umount_fs(struct libmnt_context *cxt,
* it's usable only for canonicalized stuff (e.g. kernel mountinfo).
*/
if (!mnt_context_mtab_writable(cxt) && *tgt == '/' &&
+ !mnt_context_is_nocanonicalize(cxt) &&
!mnt_context_is_force(cxt) && !mnt_context_is_lazy(cxt))
rc = mnt_context_get_mtab_for_target(cxt, &mtab, tgt);
else
@@ -245,6 +246,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
&& !mnt_context_mtab_writable(cxt)
&& !mnt_context_is_force(cxt)
&& !mnt_context_is_lazy(cxt)
+ && !mnt_context_is_nocanonicalize(cxt)
&& !mnt_context_is_loopdel(cxt)
&& mnt_stat_mountpoint(tgt, &st) == 0 && S_ISDIR(st.st_mode)
&& !has_utab_entry(cxt, tgt)) {