mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Kent <raven@themaw.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: autofs mailing list <autofs@vger.kernel.org>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Omar Sandoval <osandov@osandov.com>,
	Al Viro <viro@ZenIV.linux.org.uk>
Subject: [PATCH 1/7] vfs - merge path_is_mountpoint() and path_is_mountpoint_rcu()
Date: Mon, 28 Nov 2016 10:11:48 +0800	[thread overview]
Message-ID: <148029910861.27779.4517883721395202453.stgit@pluto.themaw.net> (raw)

From: Ian Kent <ikent@redhat.com>

Forgetting that the rcu lock allows nesting I added a superfluous rcu
version of path_is_mountpoint().

Merge it and the rcu version, make the common case (d_mountpoint()
returning true) inline and change the path parameter to a const.

Also move the function definition to include/linux/mount.h as it
seems a more sensible place for it.

Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Omar Sandoval <osandov@osandov.com>
---
 fs/autofs4/root.c     |   11 +++--------
 fs/namespace.c        |   41 ++++++++++++++---------------------------
 include/linux/fs.h    |    2 --
 include/linux/mount.h |   11 +++++++++++
 4 files changed, 28 insertions(+), 37 deletions(-)

diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index c4df881..dd2ea5d 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -437,13 +437,8 @@ static int autofs4_d_manage(struct path *path, bool rcu_walk)
 
 	/* The daemon never waits. */
 	if (autofs4_oz_mode(sbi)) {
-		if (rcu_walk) {
-			if (!path_is_mountpoint_rcu(path))
-				return -EISDIR;
-		} else {
-			if (!path_is_mountpoint(path))
-				return -EISDIR;
-		}
+		if (!path_is_mountpoint(path))
+			return -EISDIR;
 		return 0;
 	}
 
@@ -471,7 +466,7 @@ static int autofs4_d_manage(struct path *path, bool rcu_walk)
 
 		if (ino->flags & AUTOFS_INF_WANT_EXPIRE)
 			return 0;
-		if (path_is_mountpoint_rcu(path))
+		if (path_is_mountpoint(path))
 			return 0;
 		inode = d_inode_rcu(dentry);
 		if (inode && S_ISLNK(inode->i_mode))
diff --git a/fs/namespace.c b/fs/namespace.c
index 79473ee..da1cd87 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1160,12 +1160,23 @@ struct vfsmount *mntget(struct vfsmount *mnt)
 }
 EXPORT_SYMBOL(mntget);
 
-static bool __path_is_mountpoint(struct path *path)
+/* __path_is_mountpoint() - Check if path is a mount in the current
+ *                          namespace.
+ *
+ *  d_mountpoint() can only be used reliably to establish if a dentry is
+ *  not mounted in any namespace and that common case is handled inline.
+ *  d_mountpoint() isn't aware of the possibility there may be multiple
+ *  mounts using a given dentry in a different namespace. This function
+ *  checks if the passed in path is a mountpoint rather than the dentry
+ *  alone.
+ */
+bool __path_is_mountpoint(const struct path *path)
 {
 	struct mount *mount;
 	struct vfsmount *mnt;
 	unsigned seq;
 
+	rcu_read_lock();
 	do {
 		seq = read_seqbegin(&mount_lock);
 		mount = __lookup_mnt(path->mnt, path->dentry);
@@ -1173,35 +1184,11 @@ static bool __path_is_mountpoint(struct path *path)
 	} while (mnt &&
 		 !(mnt->mnt_flags & MNT_SYNC_UMOUNT) &&
 		 read_seqretry(&mount_lock, seq));
-
-	return mnt != NULL;
-}
-
-/* Check if path is a mount in current namespace */
-bool path_is_mountpoint(struct path *path)
-{
-	bool res;
-
-	if (!d_mountpoint(path->dentry))
-		return false;
-
-	rcu_read_lock();
-	res = __path_is_mountpoint(path);
 	rcu_read_unlock();
 
-	return res;
-}
-EXPORT_SYMBOL(path_is_mountpoint);
-
-/* Check if path is a mount in current namespace */
-bool path_is_mountpoint_rcu(struct path *path)
-{
-	if (!d_mountpoint(path->dentry))
-		return false;
-
-	return __path_is_mountpoint(path);
+	return mnt != NULL;
 }
-EXPORT_SYMBOL(path_is_mountpoint_rcu);
+EXPORT_SYMBOL(__path_is_mountpoint);
 
 struct vfsmount *mnt_clone_internal(struct path *path)
 {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 03a5a39..83de8b6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2095,8 +2095,6 @@ extern int vfs_ustat(dev_t, struct kstatfs *);
 extern int freeze_super(struct super_block *super);
 extern int thaw_super(struct super_block *super);
 extern bool our_mnt(struct vfsmount *mnt);
-extern bool path_is_mountpoint(struct path *);
-extern bool path_is_mountpoint_rcu(struct path *);
 
 extern int current_umask(void);
 
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 1172cce..42dc62b 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -15,6 +15,8 @@
 #include <linux/spinlock.h>
 #include <linux/seqlock.h>
 #include <linux/atomic.h>
+#include <linux/path.h>
+#include <linux/dcache.h>
 
 struct super_block;
 struct vfsmount;
@@ -98,4 +100,13 @@ extern dev_t name_to_dev_t(const char *name);
 
 extern unsigned int sysctl_mount_max;
 
+extern bool __path_is_mountpoint(const struct path *path);
+static inline bool path_is_mountpoint(const struct path *path)
+{
+	if (!d_mountpoint(path->dentry))
+		return 0;
+
+	return __path_is_mountpoint(path);
+}
+
 #endif /* _LINUX_MOUNT_H */

             reply	other threads:[~2016-11-28  2:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-28  2:11 Ian Kent [this message]
2016-11-28  2:11 ` [PATCH 2/7] autofs - make struct path const in autofs4_dir_open() Ian Kent
2016-11-28  2:11 ` [PATCH 3/7] autofs - change struct path to const in autofs4_expire_wait() and autofs4_wait() Ian Kent
2016-11-28  2:12 ` [PATCH 4/7] vfs - change struct path to const in d_manage() Ian Kent
2016-11-28  2:12 ` [PATCH 5/7] vfs - constify path parameter of path_has_submounts() Ian Kent
2016-11-28  2:12 ` [PATCH 6/7] autofs - dont hold spin lock over direct mount expire Ian Kent
2016-11-28  2:12 ` [PATCH 7/7] vfs - make may_umount_tree() mount propogation aware Ian Kent
2016-11-30 22:22 ` [PATCH 1/7] vfs - merge path_is_mountpoint() and path_is_mountpoint_rcu() Andrew Morton
2016-12-01  0:13   ` Ian Kent
2016-12-03  5:13 ` Al Viro
2016-12-03 23:29   ` Al Viro
2016-12-04  2:18     ` Ian Kent
2016-12-05  2:50       ` Ian Kent
2016-12-04  2:07   ` Ian Kent
2016-12-06  9:37   ` Ian Kent
2016-12-07 21:30     ` Eric W. Biederman
2016-12-08  3:29       ` Ian Kent
2016-12-08  4:28         ` Eric W. Biederman
2016-12-08  6:18           ` Ian Kent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=148029910861.27779.4517883721395202453.stgit@pluto.themaw.net \
    --to=raven@themaw.net \
    --cc=akpm@linux-foundation.org \
    --cc=autofs@vger.kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=osandov@osandov.com \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®