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 2/8] vfs - add path_is_mountpoint() helper
Date: Tue, 11 Oct 2016 13:33:58 +0800 [thread overview]
Message-ID: <20161011053358.27645.9729.stgit@pluto.themaw.net> (raw)
In-Reply-To: <20161011053352.27645.83962.stgit@pluto.themaw.net>
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 ff1cd14..5ef9618 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1160,6 +1160,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 09a8c41..deaf08b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2142,6 +2142,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);
next prev parent reply other threads:[~2016-10-11 5:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-11 5:33 [PATCH 1/8] vfs - change d_manage() to take a struct path Ian Kent
2016-10-11 5:33 ` Ian Kent [this message]
2016-10-11 5:34 ` [PATCH 3/8] vfs - add path_has_submounts() Ian Kent
2016-10-11 5:34 ` [PATCH 4/8] autofs - change autofs4_expire_wait() to take struct path Ian Kent
2016-10-11 5:34 ` [PATCH 5/8] autofs - change autofs4_wait() " Ian Kent
2016-10-11 5:34 ` Ian Kent
2016-10-11 5:34 ` [PATCH 6/8] autofs - use path_is_mountpoint() to fix unreliable d_mountpoint() checks Ian Kent
2016-10-27 2:17 ` Al Viro
2016-10-27 2:51 ` Ian Kent
2016-10-27 2:51 ` Ian Kent
2016-10-11 5:34 ` [PATCH 7/8] autofs - use path_has_submounts() to fix unreliable have_submount() checks Ian Kent
2016-10-11 5:34 ` Ian Kent
2016-10-11 5:34 ` [PATCH 8/8] vfs - remove unused have_submounts() function Ian Kent
2016-10-11 5:34 ` Ian Kent
2016-10-11 16:04 ` [PATCH 1/8] vfs - change d_manage() to take a struct path Eric W. Biederman
2016-10-11 16:04 ` Eric W. Biederman
2016-10-11 23:47 ` Ian Kent
2016-10-11 23:47 ` Ian Kent
2016-10-19 19:40 ` Andrew Morton
2016-10-20 23:39 ` Ian Kent
2016-10-20 23:39 ` Ian Kent
2016-10-27 2:11 ` Al Viro
2016-10-27 2:11 ` Al Viro
2016-10-27 2:47 ` Ian Kent
2016-10-27 2:47 ` Ian Kent
2016-10-27 6:50 ` Ian Kent
2016-11-01 2:02 ` 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=20161011053358.27645.9729.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.