]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: Avoid triggering autofs in lookup_umount_fs_by_statfs
authorFabian Vogt <fvogt@suse.de>
Wed, 1 Apr 2020 11:15:13 +0000 (13:15 +0200)
committerFabian Vogt <fvogt@suse.de>
Wed, 1 Apr 2020 11:34:43 +0000 (13:34 +0200)
Currently, umount /foo results in a statfs("/foo") call, which triggers
autofs. This can create another mountpoint on /foo, which is then unmounted
later instead of the actual /foo at the time umount was called.

This is especially an issue for umount -R /bar, which just fails with
-EBUSY as the accidental mountpoint is never accounted for and so it tries
to umount /bar before /bar/someautofs.

Replace the direct statfs call with open(path, O_PATH) + fstatfs, which sees
the autofs mount directly, without triggering it.

libmount/src/context_umount.c

index 733e9194db85f5936f467afa213a12679dda181e..e3547d3564530c1f79847727e8aab22a9d76d78e 100644 (file)
@@ -287,9 +287,13 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg
        if (!type) {
                struct statfs vfs;
 
-               DBG(CXT, ul_debugobj(cxt, "  trying statfs()"));
-               if (statfs(tgt, &vfs) == 0)
+               DBG(CXT, ul_debugobj(cxt, "  trying fstatfs()"));
+               /* O_PATH avoids triggering automount points. */
+               int pathfd = open(tgt, O_PATH);
+               if (pathfd >= 0 && fstatfs(pathfd, &vfs) == 0) {
                        type = mnt_statfs_get_fstype(&vfs);
+                       close(pathfd);
+               }
                if (type) {
                        int rc = mnt_fs_set_fstype(cxt->fs, type);
                        if (rc)