consolidate pipe file creation
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 21 Jul 2012 11:33:25 +0000 (15:33 +0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 29 Jul 2012 17:24:19 +0000 (21:24 +0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/exec.c
fs/pipe.c
include/linux/fs.h
include/linux/pipe_fs_i.h

index da27b91ff1e8cbe87d0fe42aa5d39513e6a9deeb..b800fb87f6ce3c1be4075d44033cb27355cd0d55 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -2069,25 +2069,18 @@ static void wait_for_dump_helpers(struct file *file)
  */
 static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
 {
-       struct file *rp, *wp;
+       struct file *files[2];
        struct fdtable *fdt;
        struct coredump_params *cp = (struct coredump_params *)info->data;
        struct files_struct *cf = current->files;
+       int err = create_pipe_files(files, 0);
+       if (err)
+               return err;
 
-       wp = create_write_pipe(0);
-       if (IS_ERR(wp))
-               return PTR_ERR(wp);
-
-       rp = create_read_pipe(wp, 0);
-       if (IS_ERR(rp)) {
-               free_write_pipe(wp);
-               return PTR_ERR(rp);
-       }
-
-       cp->file = wp;
+       cp->file = files[1];
 
        sys_close(0);
-       fd_install(0, rp);
+       fd_install(0, files[0]);
        spin_lock(&cf->file_lock);
        fdt = files_fdtable(cf);
        __set_open_fd(0, fdt);
index 49c1065256fd10d9d5fdca3cf449b1e56bd58a0a..7523d9d2a9988f4381350688e0b7bbf39e3b30b4 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1016,18 +1016,16 @@ fail_inode:
        return NULL;
 }
 
-struct file *create_write_pipe(int flags)
+int create_pipe_files(struct file **res, int flags)
 {
        int err;
-       struct inode *inode;
+       struct inode *inode = get_pipe_inode();
        struct file *f;
        struct path path;
-       struct qstr name = { .name = "" };
+       static struct qstr name = { .name = "" };
 
-       err = -ENFILE;
-       inode = get_pipe_inode();
        if (!inode)
-               goto err;
+               return -ENFILE;
 
        err = -ENOMEM;
        path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name);
@@ -1041,62 +1039,43 @@ struct file *create_write_pipe(int flags)
        f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops);
        if (!f)
                goto err_dentry;
-       f->f_mapping = inode->i_mapping;
 
        f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
-       f->f_version = 0;
 
-       return f;
+       res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops);
+       if (!res[0])
+               goto err_file;
+
+       path_get(&path);
+       res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK);
+       res[1] = f;
+       return 0;
 
- err_dentry:
+err_file:
+       put_filp(f);
+err_dentry:
        free_pipe_info(inode);
        path_put(&path);
-       return ERR_PTR(err);
+       return err;
 
- err_inode:
+err_inode:
        free_pipe_info(inode);
        iput(inode);
- err:
-       return ERR_PTR(err);
-}
-
-void free_write_pipe(struct file *f)
-{
-       free_pipe_info(f->f_dentry->d_inode);
-       path_put(&f->f_path);
-       put_filp(f);
-}
-
-struct file *create_read_pipe(struct file *wrf, int flags)
-{
-       /* Grab pipe from the writer */
-       struct file *f = alloc_file(&wrf->f_path, FMODE_READ,
-                                   &read_pipefifo_fops);
-       if (!f)
-               return ERR_PTR(-ENFILE);
-
-       path_get(&wrf->f_path);
-       f->f_flags = O_RDONLY | (flags & O_NONBLOCK);
-
-       return f;
+       return err;
 }
 
 int do_pipe_flags(int *fd, int flags)
 {
-       struct file *fw, *fr;
+       struct file *files[2];
        int error;
        int fdw, fdr;
 
        if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT))
                return -EINVAL;
 
-       fw = create_write_pipe(flags);
-       if (IS_ERR(fw))
-               return PTR_ERR(fw);
-       fr = create_read_pipe(fw, flags);
-       error = PTR_ERR(fr);
-       if (IS_ERR(fr))
-               goto err_write_pipe;
+       error = create_pipe_files(files, flags);
+       if (error)
+               return error;
 
        error = get_unused_fd_flags(flags);
        if (error < 0)
@@ -1109,8 +1088,8 @@ int do_pipe_flags(int *fd, int flags)
        fdw = error;
 
        audit_fd_pair(fdr, fdw);
-       fd_install(fdr, fr);
-       fd_install(fdw, fw);
+       fd_install(fdr, files[0]);
+       fd_install(fdw, files[1]);
        fd[0] = fdr;
        fd[1] = fdw;
 
@@ -1119,10 +1098,8 @@ int do_pipe_flags(int *fd, int flags)
  err_fdr:
        put_unused_fd(fdr);
  err_read_pipe:
-       path_put(&fr->f_path);
-       put_filp(fr);
- err_write_pipe:
-       free_write_pipe(fw);
+       fput(files[0]);
+       fput(files[1]);
        return error;
 }
 
index 8fabb037a48db40e8a490fc74c15ce907ad9059a..47823784464837384738cec52a33634e993924af 100644 (file)
@@ -2326,9 +2326,6 @@ static inline void i_readcount_inc(struct inode *inode)
 }
 #endif
 extern int do_pipe_flags(int *, int);
-extern struct file *create_read_pipe(struct file *f, int flags);
-extern struct file *create_write_pipe(int flags);
-extern void free_write_pipe(struct file *);
 
 extern int kernel_read(struct file *, loff_t, char *, unsigned long);
 extern struct file * open_exec(const char *);
index e1ac1ce16fb0b60f07ec961b3ec8f1b7fb0763d0..e16dcb31f0c7c3c3358c52b747b493d96cf92cca 100644 (file)
@@ -162,4 +162,6 @@ void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
 long pipe_fcntl(struct file *, unsigned int, unsigned long arg);
 struct pipe_inode_info *get_pipe_info(struct file *file);
 
+int create_pipe_files(struct file **, int);
+
 #endif
This page took 0.062633 seconds and 5 git commands to generate.