namei: add follow_up_bind()
Subsystems (2)
cover namei: add follow_up_bind()
Hi everyone,
Back when we fixed TIOCGPTPEER again in
commit a319b01d9095 ("devpts: resolve devpts bind-mounts")
we discovered [1] that the code for bind-mount resolution we needed to add in devpts_mtnget() was already duplicated in nfsd code. So we briefly discussed [2] adding a helper to namei.{c,h} that would resolve bind-mounts. The bind-mount resolution code is replicated in at least two places:
- fs/nfsd/vfs.c:follow_to_parent()
- fs/devpts/inode.c:devpts_mntget()
This series adds:
- follow_up_bind() to namei.{c,h}
- switches fs/nfsd/vfs.c:follow_to_parent() to use follow_up_bind()
- switches fs/devpts/inode.c:devpts_mntget() to use follow_up_bind()
I just wanted to wait until the devpts patches I sent would make it into mainline. Seems to me that this helper might be worth having around. Not just because it avoids (granted rather trivial) code duplication but also because it makes the concept of resolving a bind-mount up to the origin mountpoint of the vfs's mount obvious (which at least to me wasn't obivous before).
[1]: https://lkml.org/lkml/2018/3/11/219
[2]: https://lkml.org/lkml/2018/3/12/486
Thanks!
Christian
Christian Brauner (3):
namei: add follow_up_bind()
devpts: use follow_up_bind() helper
nfsd: use follow_up_bind() helper
fs/devpts/inode.c | 4 +--- fs/namei.c | 10 ++++++++++ fs/nfsd/vfs.c | 4 ++-- include/linux/namei.h | 1 + 4 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/3 namei: add follow_up_bind()
This adds a new helper for resolving bind-mounts.
--- fs/namei.c | 10 ++++++++++ include/linux/namei.h | 1 + 2 files changed, 11 insertions(+)
fs/namei.c +10 -0
@@ -1085,6 +1085,16 @@ int follow_up(struct path *path) }EXPORT_SYMBOL (follow_up); +/* +* follow_up_bind - Resolve bind-mounts to mountpoint of path's vfsmount +*/ +inline void follow_up_bind (struct path *path) +{ +while (path->mnt->mnt_root == path->dentry &&follow_up (path)) + ; +} +EXPORT_SYMBOL (follow_up_bind); +/* * Perform an automount * - return -EISDIR to tell follow_managed() to stop and return the path we
include/linux/namei.h +1 -0
@@ -87,6 +87,7 @@ extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, intextern int follow_down_one (struct path *);extern int follow_down (struct path *);extern int follow_up (struct path *); +extern void follow_up_bind (struct path *path);extern struct dentry *lock_rename (struct dentry *,struct dentry *);extern void unlock_rename (struct dentry *,struct dentry *);
Signature · 1 line
2.15.1
PATCH 2/3 devpts: use follow_up_bind() helper
In reply to Christian Brauner--- fs/devpts/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/devpts/inode.c +1 -3
@@ -181,9 +181,7 @@ struct vfsmount *devpts_mntget(struct file *filp, struct pts_fs_info *fsi)/* Walk upward while the start point is a bind mount of * a single file. */ -while (path.mnt->mnt_root == path.dentry) -if (follow_up (&path) ==0 ) -break ; +follow_up_bind (&path);/* devpts_ptmx_path() finds a devpts fs or returns an error. */ if ((path.mnt->mnt_sb->s_magic != DEVPTS_SUPER_MAGIC) ||
Signature · 1 line
2.15.1
PATCH 3/3 nfsd: use follow_up_bind() helper
In reply to Christian Brauner--- fs/nfsd/vfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +2 -2
@@ -141,8 +141,8 @@ static void follow_to_parent(struct path *path) {struct dentry *dp; -while (path->dentry == path->mnt->mnt_root &&follow_up (path)) - ; +follow_up_bind (path); + dp =dget_parent (path->dentry);dput (path->dentry); path->dentry = dp;
Signature · 1 line
2.15.1