Add a new inode operation i_op->dentry_open(). This is for stacked filesystems that want to return a struct file from a different filesystem.
Unified · Split
| @@ -67,6 +67,7 @@ prototypes: · 66 unmodified lines | ||
| 67 | 67 | struct file *, unsigned open_flag, |
| 68 | 68 | umode_t create_mode, int *opened); |
| 69 | 69 | int (*tmpfile) (struct inode *, struct dentry *, umode_t); |
| 70 | + int (*dentry_open)(struct dentry *, struct file *, const struct cred *); | |
| 70 | 71 | |
| 71 | 72 | locking rules: |
| 72 | 73 | all may block |
| @@ -96,6 +97,7 @@ fiemap: no · 23 unmodified lines | ||
| 96 | 97 | update_time: no |
| 97 | 98 | atomic_open: yes |
| 98 | 99 | tmpfile: no |
| 100 | +dentry_open: no | |
| 99 | 101 | |
| 100 | 102 | Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on |
| 101 | 103 | victim. |
| @@ -364,6 +364,7 @@ struct inode_operations { · 363 unmodified lines | ||
| 364 | 364 | int (*atomic_open)(struct inode *, struct dentry *, struct file *, |
| 365 | 365 | unsigned open_flag, umode_t create_mode, int *opened); |
| 366 | 366 | int (*tmpfile) (struct inode *, struct dentry *, umode_t); |
| 367 | + int (*dentry_open)(struct dentry *, struct file *, const struct cred *); | |
| 367 | 368 | }; |
| 368 | 369 | |
| 369 | 370 | Again, all methods are called without any locks being held, unless |
| @@ -696,6 +697,12 @@ struct address_space_operations { · 326 unmodified lines | ||
| 696 | 697 | but instead uses bmap to find out where the blocks in the file |
| 697 | 698 | are and uses those addresses directly. |
| 698 | 699 | |
| 700 | + dentry_open: *WARNING: probably going away soon, do not use!* This is an | |
| 701 | + alternative to f_op->open(), the difference is that this method may open | |
| 702 | + a file not necessarily originating from the same filesystem as the one | |
| 703 | + i_op->open() was called on. It may be useful for stacking filesystems | |
| 704 | + which want to allow native I/O directly on underlying files. | |
| 705 | + | |
| 699 | 706 | |
| 700 | 707 | invalidatepage: If a page has PagePrivate set, then invalidatepage |
| 701 | 708 | will be called when part or all of the page is to be removed |
| @@ -3064,9 +3064,12 @@ finish_open_created: · 3063 unmodified lines | ||
| 3064 | 3064 | error = may_open(&nd->path, acc_mode, open_flag); |
| 3065 | 3065 | if (error) |
| 3066 | 3066 | goto out; |
| 3067 | − file->f_path.mnt = nd->path.mnt; | |
| 3068 | − error = finish_open(file, nd->path.dentry, NULL, opened); | |
| 3069 | − if (error) { | |
| 3067 | + | |
| 3068 | + BUG_ON(*opened & FILE_OPENED); /* once it's opened, it's opened */ | |
| 3069 | + error = vfs_open(&nd->path, file, current_cred()); | |
| 3070 | + if (!error) { | |
| 3071 | + *opened |= FILE_OPENED; | |
| 3072 | + } else { | |
| 3070 | 3073 | if (error == -EOPENSTALE) |
| 3071 | 3074 | goto stale_open; |
| 3072 | 3075 | goto out; |
| @@ -823,8 +823,7 @@ struct file *dentry_open(const struct path *path, int flags, · 822 unmodified lines | ||
| 823 | 823 | f = get_empty_filp(); |
| 824 | 824 | if (!IS_ERR(f)) { |
| 825 | 825 | f->f_flags = flags; |
| 826 | − f->f_path = *path; | |
| 827 | − error = do_dentry_open(f, NULL, cred); | |
| 826 | + error = vfs_open(path, f, cred); | |
| 828 | 827 | if (!error) { |
| 829 | 828 | /* from now on we need fput() to dispose of f */ |
| 830 | 829 | error = open_check_o_direct(f); |
| @@ -841,6 +840,26 @@ struct file *dentry_open(const struct path *path, int flags, · 10 unmodified lines | ||
| 841 | 840 | } |
| 842 | 841 | EXPORT_SYMBOL(dentry_open); |
| 843 | 842 | |
| 843 | +/** | |
| 844 | + * vfs_open - open the file at the given path | |
| 845 | + * @path: path to open | |
| 846 | + * @filp: newly allocated file with f_flag initialized | |
| 847 | + * @cred: credentials to use | |
| 848 | + */ | |
| 849 | +int vfs_open(const struct path *path, struct file *filp, | |
| 850 | + const struct cred *cred) | |
| 851 | +{ | |
| 852 | + struct inode *inode = path->dentry->d_inode; | |
| 853 | + | |
| 854 | + if (inode->i_op->dentry_open) | |
| 855 | + return inode->i_op->dentry_open(path->dentry, filp, cred); | |
| 856 | + else { | |
| 857 | + filp->f_path = *path; | |
| 858 | + return do_dentry_open(filp, NULL, cred); | |
| 859 | + } | |
| 860 | +} | |
| 861 | +EXPORT_SYMBOL(vfs_open); | |
| 862 | + | |
| 844 | 863 | static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) |
| 845 | 864 | { |
| 846 | 865 | int lookup_flags = 0; |
| @@ -1528,6 +1528,9 @@ struct inode_operations { · 1527 unmodified lines | ||
| 1528 | 1528 | umode_t create_mode, int *opened); |
| 1529 | 1529 | int (*tmpfile) (struct inode *, struct dentry *, umode_t); |
| 1530 | 1530 | int (*set_acl)(struct inode *, struct posix_acl *, int); |
| 1531 | + | |
| 1532 | + /* WARNING: probably going away soon, do not use! */ | |
| 1533 | + int (*dentry_open)(struct dentry *, struct file *, const struct cred *); | |
| 1531 | 1534 | } ____cacheline_aligned; |
| 1532 | 1535 | |
| 1533 | 1536 | ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
| @@ -2040,6 +2043,7 @@ extern struct file *file_open_name(struct filename *, int, umode_t); · 506 unmodified lines | ||
| 2040 | 2043 | extern struct file *filp_open(const char *, int, umode_t); |
| 2041 | 2044 | extern struct file *file_open_root(struct dentry *, struct vfsmount *, |
| 2042 | 2045 | const char *, int); |
| 2046 | +extern int vfs_open(const struct path *, struct file *, const struct cred *); | |
| 2043 | 2047 | extern struct file * dentry_open(const struct path *, int, const struct cred *); |
| 2044 | 2048 | extern int filp_close(struct file *, fl_owner_t id); |
| 2045 | 2049 | |