diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-07-21 07:33:25 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-07-29 13:24:19 -0400 |
commit | e4fad8e5d220e3dfb1050eee752ee5058f29a232 (patch) | |
tree | b56356fda1d1f4f47e1da63aa24080db999dafc1 /fs | |
parent | b5bcdda32736b94a7d178d156d80a69f536ad468 (diff) |
consolidate pipe file creation
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/exec.c | 19 | ||||
-rw-r--r-- | fs/pipe.c | 75 |
2 files changed, 32 insertions, 62 deletions
@@ -2069,25 +2069,18 @@ static void wait_for_dump_helpers(struct file *file) | |||
2069 | */ | 2069 | */ |
2070 | static int umh_pipe_setup(struct subprocess_info *info, struct cred *new) | 2070 | static int umh_pipe_setup(struct subprocess_info *info, struct cred *new) |
2071 | { | 2071 | { |
2072 | struct file *rp, *wp; | 2072 | struct file *files[2]; |
2073 | struct fdtable *fdt; | 2073 | struct fdtable *fdt; |
2074 | struct coredump_params *cp = (struct coredump_params *)info->data; | 2074 | struct coredump_params *cp = (struct coredump_params *)info->data; |
2075 | struct files_struct *cf = current->files; | 2075 | struct files_struct *cf = current->files; |
2076 | int err = create_pipe_files(files, 0); | ||
2077 | if (err) | ||
2078 | return err; | ||
2076 | 2079 | ||
2077 | wp = create_write_pipe(0); | 2080 | cp->file = files[1]; |
2078 | if (IS_ERR(wp)) | ||
2079 | return PTR_ERR(wp); | ||
2080 | |||
2081 | rp = create_read_pipe(wp, 0); | ||
2082 | if (IS_ERR(rp)) { | ||
2083 | free_write_pipe(wp); | ||
2084 | return PTR_ERR(rp); | ||
2085 | } | ||
2086 | |||
2087 | cp->file = wp; | ||
2088 | 2081 | ||
2089 | sys_close(0); | 2082 | sys_close(0); |
2090 | fd_install(0, rp); | 2083 | fd_install(0, files[0]); |
2091 | spin_lock(&cf->file_lock); | 2084 | spin_lock(&cf->file_lock); |
2092 | fdt = files_fdtable(cf); | 2085 | fdt = files_fdtable(cf); |
2093 | __set_open_fd(0, fdt); | 2086 | __set_open_fd(0, fdt); |
@@ -1016,18 +1016,16 @@ fail_inode: | |||
1016 | return NULL; | 1016 | return NULL; |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | struct file *create_write_pipe(int flags) | 1019 | int create_pipe_files(struct file **res, int flags) |
1020 | { | 1020 | { |
1021 | int err; | 1021 | int err; |
1022 | struct inode *inode; | 1022 | struct inode *inode = get_pipe_inode(); |
1023 | struct file *f; | 1023 | struct file *f; |
1024 | struct path path; | 1024 | struct path path; |
1025 | struct qstr name = { .name = "" }; | 1025 | static struct qstr name = { .name = "" }; |
1026 | 1026 | ||
1027 | err = -ENFILE; | ||
1028 | inode = get_pipe_inode(); | ||
1029 | if (!inode) | 1027 | if (!inode) |
1030 | goto err; | 1028 | return -ENFILE; |
1031 | 1029 | ||
1032 | err = -ENOMEM; | 1030 | err = -ENOMEM; |
1033 | path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name); | 1031 | path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name); |
@@ -1041,62 +1039,43 @@ struct file *create_write_pipe(int flags) | |||
1041 | f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops); | 1039 | f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops); |
1042 | if (!f) | 1040 | if (!f) |
1043 | goto err_dentry; | 1041 | goto err_dentry; |
1044 | f->f_mapping = inode->i_mapping; | ||
1045 | 1042 | ||
1046 | f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); | 1043 | f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT)); |
1047 | f->f_version = 0; | ||
1048 | 1044 | ||
1049 | return f; | 1045 | res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops); |
1046 | if (!res[0]) | ||
1047 | goto err_file; | ||
1048 | |||
1049 | path_get(&path); | ||
1050 | res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK); | ||
1051 | res[1] = f; | ||
1052 | return 0; | ||
1050 | 1053 | ||
1051 | err_dentry: | 1054 | err_file: |
1055 | put_filp(f); | ||
1056 | err_dentry: | ||
1052 | free_pipe_info(inode); | 1057 | free_pipe_info(inode); |
1053 | path_put(&path); | 1058 | path_put(&path); |
1054 | return ERR_PTR(err); | 1059 | return err; |
1055 | 1060 | ||
1056 | err_inode: | 1061 | err_inode: |
1057 | free_pipe_info(inode); | 1062 | free_pipe_info(inode); |
1058 | iput(inode); | 1063 | iput(inode); |
1059 | err: | 1064 | return err; |
1060 | return ERR_PTR(err); | ||
1061 | } | ||
1062 | |||
1063 | void free_write_pipe(struct file *f) | ||
1064 | { | ||
1065 | free_pipe_info(f->f_dentry->d_inode); | ||
1066 | path_put(&f->f_path); | ||
1067 | put_filp(f); | ||
1068 | } | ||
1069 | |||
1070 | struct file *create_read_pipe(struct file *wrf, int flags) | ||
1071 | { | ||
1072 | /* Grab pipe from the writer */ | ||
1073 | struct file *f = alloc_file(&wrf->f_path, FMODE_READ, | ||
1074 | &read_pipefifo_fops); | ||
1075 | if (!f) | ||
1076 | return ERR_PTR(-ENFILE); | ||
1077 | |||
1078 | path_get(&wrf->f_path); | ||
1079 | f->f_flags = O_RDONLY | (flags & O_NONBLOCK); | ||
1080 | |||
1081 | return f; | ||
1082 | } | 1065 | } |
1083 | 1066 | ||
1084 | int do_pipe_flags(int *fd, int flags) | 1067 | int do_pipe_flags(int *fd, int flags) |
1085 | { | 1068 | { |
1086 | struct file *fw, *fr; | 1069 | struct file *files[2]; |
1087 | int error; | 1070 | int error; |
1088 | int fdw, fdr; | 1071 | int fdw, fdr; |
1089 | 1072 | ||
1090 | if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT)) | 1073 | if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT)) |
1091 | return -EINVAL; | 1074 | return -EINVAL; |
1092 | 1075 | ||
1093 | fw = create_write_pipe(flags); | 1076 | error = create_pipe_files(files, flags); |
1094 | if (IS_ERR(fw)) | 1077 | if (error) |
1095 | return PTR_ERR(fw); | 1078 | return error; |
1096 | fr = create_read_pipe(fw, flags); | ||
1097 | error = PTR_ERR(fr); | ||
1098 | if (IS_ERR(fr)) | ||
1099 | goto err_write_pipe; | ||
1100 | 1079 | ||
1101 | error = get_unused_fd_flags(flags); | 1080 | error = get_unused_fd_flags(flags); |
1102 | if (error < 0) | 1081 | if (error < 0) |
@@ -1109,8 +1088,8 @@ int do_pipe_flags(int *fd, int flags) | |||
1109 | fdw = error; | 1088 | fdw = error; |
1110 | 1089 | ||
1111 | audit_fd_pair(fdr, fdw); | 1090 | audit_fd_pair(fdr, fdw); |
1112 | fd_install(fdr, fr); | 1091 | fd_install(fdr, files[0]); |
1113 | fd_install(fdw, fw); | 1092 | fd_install(fdw, files[1]); |
1114 | fd[0] = fdr; | 1093 | fd[0] = fdr; |
1115 | fd[1] = fdw; | 1094 | fd[1] = fdw; |
1116 | 1095 | ||
@@ -1119,10 +1098,8 @@ int do_pipe_flags(int *fd, int flags) | |||
1119 | err_fdr: | 1098 | err_fdr: |
1120 | put_unused_fd(fdr); | 1099 | put_unused_fd(fdr); |
1121 | err_read_pipe: | 1100 | err_read_pipe: |
1122 | path_put(&fr->f_path); | 1101 | fput(files[0]); |
1123 | put_filp(fr); | 1102 | fput(files[1]); |
1124 | err_write_pipe: | ||
1125 | free_write_pipe(fw); | ||
1126 | return error; | 1103 | return error; |
1127 | } | 1104 | } |
1128 | 1105 | ||