diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-06-17 14:15:10 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-07-12 10:04:28 -0400 |
commit | 183266f26f45a47958afb5c9aa1b3d4651e2eb8c (patch) | |
tree | c420683235aab835020701a456a62cd786a02c68 | |
parent | 152b6372c90630ef6787334e84cdddbcf8beb241 (diff) |
new helper: alloc_file_clone()
alloc_file_clone(old_file, mode, ops): create a new struct file with
->f_path equal to that of old_file. pipe converted.
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/file_table.c | 11 | ||||
-rw-r--r-- | fs/pipe.c | 6 | ||||
-rw-r--r-- | include/linux/file.h | 2 |
3 files changed, 15 insertions, 4 deletions
diff --git a/fs/file_table.c b/fs/file_table.c index 6b3723909342..78b067ddb386 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -211,6 +211,17 @@ struct file *alloc_file_pseudo(struct inode *inode, struct vfsmount *mnt, } EXPORT_SYMBOL(alloc_file_pseudo); +struct file *alloc_file_clone(struct file *base, int flags, + const struct file_operations *fops) +{ + struct file *f = alloc_file(&base->f_path, flags, fops); + if (!IS_ERR(f)) { + path_get(&f->f_path); + f->f_mapping = base->f_mapping; + } + return f; +} + /* the real guts of fput() - releasing the last reference to file */ static void __fput(struct file *file) diff --git a/fs/pipe.c b/fs/pipe.c index 9701bd3458d1..5f50070774bc 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -761,15 +761,13 @@ int create_pipe_files(struct file **res, int flags) f->private_data = inode->i_pipe; - res[0] = alloc_file(&f->f_path, O_RDONLY | (flags & O_NONBLOCK), - &pipefifo_fops); + res[0] = alloc_file_clone(f, O_RDONLY | (flags & O_NONBLOCK), + &pipefifo_fops); if (IS_ERR(res[0])) { put_pipe_info(inode, inode->i_pipe); fput(f); return PTR_ERR(res[0]); } - - path_get(&f->f_path); res[0]->private_data = inode->i_pipe; res[1] = f; return 0; diff --git a/include/linux/file.h b/include/linux/file.h index 5b25388f2f79..60914843c737 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -23,6 +23,8 @@ extern struct file *alloc_file(const struct path *, int flags, const struct file_operations *fop); extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *, const char *, int flags, const struct file_operations *); +extern struct file *alloc_file_clone(struct file *, int flags, + const struct file_operations *); static inline void fput_light(struct file *file, int fput_needed) { |