Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1494633

[RFC PATCH 2/8] vfs - add path_is_mountpoint() helper

From Ian Kent <raven@themaw.net>
Newsgroups linux.kernel
Subject [RFC PATCH 2/8] vfs - add path_is_mountpoint() helper
Date 2016-10-03 03:00 +0200
Message-ID <snZLP-5xu-1@gated-at.bofh.it> (permalink)
References <snZCa-5us-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Ian Kent <ikent@redhat.com>

d_mountpoint() can only be used reliably to establish if a dentry is
not mounted in any namespace. It isn't aware of the possibility there
may be multiple mounts using a given dentry that may be in a different
namespace.

Add helper functions, path_is_mountpoint() and an rcu version , that
checks if a struct path is a mountpoint for this case.

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/namespace.c     |   43 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |    2 ++
 2 files changed, 45 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index 7bb2cda..ca1faaa 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1153,6 +1153,49 @@ struct vfsmount *mntget(struct vfsmount *mnt)
 }
 EXPORT_SYMBOL(mntget);
 
+static bool __path_is_mountpoint(struct path *path)
+{
+	struct mount *mount;
+	struct vfsmount *mnt;
+	unsigned seq;
+
+	do {
+		seq = read_seqbegin(&mount_lock);
+		mount = __lookup_mnt(path->mnt, path->dentry);
+		mnt = mount ? &mount->mnt : NULL;
+	} 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 0;
+
+	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 0;
+
+	return __path_is_mountpoint(path);
+}
+EXPORT_SYMBOL(path_is_mountpoint_rcu);
+
 struct vfsmount *mnt_clone_internal(struct path *path)
 {
 	struct mount *p;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 901e25d..d588b26 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2117,6 +2117,8 @@ 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);
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH 0/8] Patch series to fix autofs unreliable usage of  d_mountpoint() Ian Kent <raven@themaw.net> - 2016-10-03 02:50 +0200
  [RFC PATCH 3/8] vfs - add path_has_submounts() Ian Kent <raven@themaw.net> - 2016-10-03 02:50 +0200
  [RFC PATCH 1/8] vfs - change d_manage() to take a struct path Ian Kent <raven@themaw.net> - 2016-10-03 02:50 +0200
  [RFC PATCH 2/8] vfs - add path_is_mountpoint() helper Ian Kent <raven@themaw.net> - 2016-10-03 03:00 +0200
  [RFC PATCH 4/8] autofs - change autofs4_expire_wait() to take  struct path Ian Kent <raven@themaw.net> - 2016-10-03 03:00 +0200
  [RFC PATCH 5/8] autofs - change autofs4_wait() to take struct path Ian Kent <raven@themaw.net> - 2016-10-03 03:00 +0200
  [RFC PATCH 6/8] autofs - use path_is_mountpoint() to fix unreliable  d_mountpoint() checks Ian Kent <raven@themaw.net> - 2016-10-03 03:00 +0200
  [RFC PATCH 7/8] autofs - use path_has_submounts() to fix unreliable  have_submount() checks Ian Kent <raven@themaw.net> - 2016-10-03 03:00 +0200

csiph-web