aboutsummaryrefslogtreecommitdiffstats
path: root/fs/file_table.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/file_table.c')
-rw-r--r--fs/file_table.c49
1 files changed, 12 insertions, 37 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 4bef4c01ec6f..17a55b81be2d 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -21,9 +21,12 @@
21#include <linux/fsnotify.h> 21#include <linux/fsnotify.h>
22#include <linux/sysctl.h> 22#include <linux/sysctl.h>
23#include <linux/percpu_counter.h> 23#include <linux/percpu_counter.h>
24#include <linux/ima.h>
24 25
25#include <asm/atomic.h> 26#include <asm/atomic.h>
26 27
28#include "internal.h"
29
27/* sysctl tunables... */ 30/* sysctl tunables... */
28struct files_stat_struct files_stat = { 31struct files_stat_struct files_stat = {
29 .max_files = NR_FILE 32 .max_files = NR_FILE
@@ -147,8 +150,6 @@ fail:
147 return NULL; 150 return NULL;
148} 151}
149 152
150EXPORT_SYMBOL(get_empty_filp);
151
152/** 153/**
153 * alloc_file - allocate and initialize a 'struct file' 154 * alloc_file - allocate and initialize a 'struct file'
154 * @mnt: the vfsmount on which the file will reside 155 * @mnt: the vfsmount on which the file will reside
@@ -164,8 +165,8 @@ EXPORT_SYMBOL(get_empty_filp);
164 * If all the callers of init_file() are eliminated, its 165 * If all the callers of init_file() are eliminated, its
165 * code should be moved into this function. 166 * code should be moved into this function.
166 */ 167 */
167struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, 168struct file *alloc_file(struct path *path, fmode_t mode,
168 fmode_t mode, const struct file_operations *fop) 169 const struct file_operations *fop)
169{ 170{
170 struct file *file; 171 struct file *file;
171 172
@@ -173,35 +174,8 @@ struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry,
173 if (!file) 174 if (!file)
174 return NULL; 175 return NULL;
175 176
176 init_file(file, mnt, dentry, mode, fop); 177 file->f_path = *path;
177 return file; 178 file->f_mapping = path->dentry->d_inode->i_mapping;
178}
179EXPORT_SYMBOL(alloc_file);
180
181/**
182 * init_file - initialize a 'struct file'
183 * @file: the already allocated 'struct file' to initialized
184 * @mnt: the vfsmount on which the file resides
185 * @dentry: the dentry representing this file
186 * @mode: the mode the file is opened with
187 * @fop: the 'struct file_operations' for this file
188 *
189 * Use this instead of setting the members directly. Doing so
190 * avoids making mistakes like forgetting the mntget() or
191 * forgetting to take a write on the mnt.
192 *
193 * Note: This is a crappy interface. It is here to make
194 * merging with the existing users of get_empty_filp()
195 * who have complex failure logic easier. All users
196 * of this should be moving to alloc_file().
197 */
198int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
199 fmode_t mode, const struct file_operations *fop)
200{
201 int error = 0;
202 file->f_path.dentry = dentry;
203 file->f_path.mnt = mntget(mnt);
204 file->f_mapping = dentry->d_inode->i_mapping;
205 file->f_mode = mode; 179 file->f_mode = mode;
206 file->f_op = fop; 180 file->f_op = fop;
207 181
@@ -211,14 +185,15 @@ int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
211 * visible. We do this for consistency, and so 185 * visible. We do this for consistency, and so
212 * that we can do debugging checks at __fput() 186 * that we can do debugging checks at __fput()
213 */ 187 */
214 if ((mode & FMODE_WRITE) && !special_file(dentry->d_inode->i_mode)) { 188 if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) {
189 int error = 0;
215 file_take_write(file); 190 file_take_write(file);
216 error = mnt_clone_write(mnt); 191 error = mnt_clone_write(path->mnt);
217 WARN_ON(error); 192 WARN_ON(error);
218 } 193 }
219 return error; 194 ima_counts_get(file);
195 return file;
220} 196}
221EXPORT_SYMBOL(init_file);
222 197
223void fput(struct file *file) 198void fput(struct file *file)
224{ 199{