[RFC][PATCH 23/27] create_pipe_files(): switch the first allocation to alloc_file_pseudo()

From: Al Viro
Date: Mon Jul 09 2018 - 00:55:46 EST


From: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
---
fs/pipe.c | 41 ++++++++++-------------------------------
1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/fs/pipe.c b/fs/pipe.c
index 4d62c935f675..312af057f03a 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -744,56 +744,35 @@ static struct inode * get_pipe_inode(void)

int create_pipe_files(struct file **res, int flags)
{
- int err;
struct inode *inode = get_pipe_inode();
struct file *f;
- struct path path;

if (!inode)
return -ENFILE;

- err = -ENOMEM;
- path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &empty_name);
- if (!path.dentry)
- goto err_inode;
- path.mnt = mntget(pipe_mnt);
-
- d_instantiate(path.dentry, inode);
-
- f = alloc_file(&path, FMODE_WRITE, &pipefifo_fops);
+ f = alloc_file_pseudo(inode, pipe_mnt, "", FMODE_WRITE, &pipefifo_fops);
if (IS_ERR(f)) {
- err = PTR_ERR(f);
- goto err_dentry;
+ free_pipe_info(inode->i_pipe);
+ iput(inode);
+ return PTR_ERR(f);
}

f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
f->private_data = inode->i_pipe;

- res[0] = alloc_file(&path, FMODE_READ, &pipefifo_fops);
+ res[0] = alloc_file(&f->f_path, FMODE_READ | FMODE_OPENED,
+ &pipefifo_fops);
if (IS_ERR(res[0])) {
- err = PTR_ERR(res[0]);
- goto err_file;
+ put_pipe_info(inode, inode->i_pipe);
+ fput(f);
+ return PTR_ERR(res[0]);
}

- res[0]->f_mode |= FMODE_OPENED;
- f->f_mode |= FMODE_OPENED;
- path_get(&path);
+ path_get(&f->f_path);
res[0]->private_data = inode->i_pipe;
res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK);
res[1] = f;
return 0;
-
-err_file:
- put_filp(f);
-err_dentry:
- free_pipe_info(inode->i_pipe);
- path_put(&path);
- return err;
-
-err_inode:
- free_pipe_info(inode->i_pipe);
- iput(inode);
- return err;
}

static int __do_pipe_flags(int *fd, struct file **files, int flags)
--
2.11.0