aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2016-05-10 19:16:37 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2016-05-10 23:55:01 -0400
commit54d5ca871e72f2bb172ec9323497f01cd5091ec7 (patch)
tree1fc2a5f3017793f70f32c88bc9fdbd8107ca7a99
parent44549e8f5eea4e0a41b487b63e616cb089922b99 (diff)
vfs: add vfs_select_inode() helper
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Cc: <stable@vger.kernel.org> # v4.2+
-rw-r--r--fs/open.c12
-rw-r--r--include/linux/dcache.h12
2 files changed, 16 insertions, 8 deletions
diff --git a/fs/open.c b/fs/open.c
index 17cb6b1dab75..081d3d6df74b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -840,16 +840,12 @@ EXPORT_SYMBOL(file_path);
840int vfs_open(const struct path *path, struct file *file, 840int vfs_open(const struct path *path, struct file *file,
841 const struct cred *cred) 841 const struct cred *cred)
842{ 842{
843 struct dentry *dentry = path->dentry; 843 struct inode *inode = vfs_select_inode(path->dentry, file->f_flags);
844 struct inode *inode = dentry->d_inode;
845 844
846 file->f_path = *path; 845 if (IS_ERR(inode))
847 if (dentry->d_flags & DCACHE_OP_SELECT_INODE) { 846 return PTR_ERR(inode);
848 inode = dentry->d_op->d_select_inode(dentry, file->f_flags);
849 if (IS_ERR(inode))
850 return PTR_ERR(inode);
851 }
852 847
848 file->f_path = *path;
853 return do_dentry_open(file, inode, NULL, cred); 849 return do_dentry_open(file, inode, NULL, cred);
854} 850}
855 851
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 4bb4de8d95ea..7e9422cb5989 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -565,4 +565,16 @@ static inline struct dentry *d_real(struct dentry *dentry)
565 return dentry; 565 return dentry;
566} 566}
567 567
568static inline struct inode *vfs_select_inode(struct dentry *dentry,
569 unsigned open_flags)
570{
571 struct inode *inode = d_inode(dentry);
572
573 if (inode && unlikely(dentry->d_flags & DCACHE_OP_SELECT_INODE))
574 inode = dentry->d_op->d_select_inode(dentry, open_flags);
575
576 return inode;
577}
578
579
568#endif /* __LINUX_DCACHE_H */ 580#endif /* __LINUX_DCACHE_H */