1 From b0c34c08a36aafbbb2240d384935343feefb68f3 Mon Sep 17 00:00:00 2001
2 From: Miklos Szeredi <mszeredi@suse.cz>
3 Date: Thu, 30 Aug 2012 16:13:49 +0200
4 Subject: [PATCH 01/13] vfs: add i_op->dentry_open()
5 Patch-mainline: not yet
7 Add a new inode operation i_op->dentry_open(). This is for stacked filesystems
8 that want to return a struct file from a different filesystem.
10 Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
12 Documentation/filesystems/Locking | 2 ++
13 Documentation/filesystems/vfs.txt | 7 +++++++
14 fs/namei.c | 9 ++++++---
15 fs/open.c | 23 +++++++++++++++++++++--
16 include/linux/fs.h | 2 ++
17 5 files changed, 38 insertions(+), 5 deletions(-)
19 --- a/Documentation/filesystems/Locking
20 +++ b/Documentation/filesystems/Locking
21 @@ -66,6 +66,7 @@ d_manage: no no yes (ref-walk) maybe
22 struct file *, unsigned open_flag,
23 umode_t create_mode, int *opened);
24 int (*tmpfile) (struct inode *, struct dentry *, umode_t);
25 + int (*dentry_open)(struct dentry *, struct file *, const struct cred *);
29 @@ -93,6 +94,7 @@ removexattr: yes
35 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on
37 --- a/Documentation/filesystems/vfs.txt
38 +++ b/Documentation/filesystems/vfs.txt
39 @@ -362,6 +362,7 @@ struct inode_operations {
40 int (*atomic_open)(struct inode *, struct dentry *, struct file *,
41 unsigned open_flag, umode_t create_mode, int *opened);
42 int (*tmpfile) (struct inode *, struct dentry *, umode_t);
43 + int (*dentry_open)(struct dentry *, struct file *, const struct cred *);
46 Again, all methods are called without any locks being held, unless
47 @@ -681,6 +682,12 @@ struct address_space_operations {
48 but instead uses bmap to find out where the blocks in the file
49 are and uses those addresses directly.
51 + dentry_open: this is an alternative to f_op->open(), the difference is that
52 + this method may open a file not necessarily originating from the same
53 + filesystem as the one i_op->open() was called on. It may be
54 + useful for stacking filesystems which want to allow native I/O directly
55 + on underlying files.
58 invalidatepage: If a page has PagePrivate set, then invalidatepage
59 will be called when part or all of the page is to be removed
62 @@ -2915,9 +2915,12 @@ static int do_last(struct nameidata *nd,
63 error = may_open(&nd->path, acc_mode, open_flag);
66 - file->f_path.mnt = nd->path.mnt;
67 - error = finish_open(file, nd->path.dentry, NULL, opened);
70 + BUG_ON(*opened & FILE_OPENED); /* once it's opened, it's opened */
71 + error = vfs_open(&nd->path, file, current_cred());
73 + *opened |= FILE_OPENED;
75 if (error == -EOPENSTALE)
80 @@ -800,8 +800,7 @@ struct file *dentry_open(const struct pa
85 - error = do_dentry_open(f, NULL, cred);
86 + error = vfs_open(path, f, cred);
88 /* from now on we need fput() to dispose of f */
89 error = open_check_o_direct(f);
90 @@ -818,6 +817,26 @@ struct file *dentry_open(const struct pa
92 EXPORT_SYMBOL(dentry_open);
95 + * vfs_open - open the file at the given path
96 + * @path: path to open
97 + * @filp: newly allocated file with f_flag initialized
98 + * @cred: credentials to use
100 +int vfs_open(const struct path *path, struct file *filp,
101 + const struct cred *cred)
103 + struct inode *inode = path->dentry->d_inode;
105 + if (inode->i_op->dentry_open)
106 + return inode->i_op->dentry_open(path->dentry, filp, cred);
108 + filp->f_path = *path;
109 + return do_dentry_open(filp, NULL, cred);
112 +EXPORT_SYMBOL(vfs_open);
114 static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op)
116 int lookup_flags = 0;
117 --- a/include/linux/fs.h
118 +++ b/include/linux/fs.h
119 @@ -1585,6 +1585,7 @@ struct inode_operations {
120 struct file *, unsigned open_flag,
121 umode_t create_mode, int *opened);
122 int (*tmpfile) (struct inode *, struct dentry *, umode_t);
123 + int (*dentry_open)(struct dentry *, struct file *, const struct cred *);
124 } ____cacheline_aligned;
126 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
127 @@ -2019,6 +2020,7 @@ extern struct file *file_open_name(struc
128 extern struct file *filp_open(const char *, int, umode_t);
129 extern struct file *file_open_root(struct dentry *, struct vfsmount *,
131 +extern int vfs_open(const struct path *, struct file *, const struct cred *);
132 extern struct file * dentry_open(const struct path *, int, const struct cred *);
133 extern int filp_close(struct file *, fl_owner_t id);