aboutsummaryrefslogtreecommitdiffstats
path: root/fs/file_table.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /fs/file_table.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'fs/file_table.c')
-rw-r--r--fs/file_table.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 8eb44042e009..32d12b78bac8 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -13,7 +13,6 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/security.h> 15#include <linux/security.h>
16#include <linux/ima.h>
17#include <linux/eventpoll.h> 16#include <linux/eventpoll.h>
18#include <linux/rcupdate.h> 17#include <linux/rcupdate.h>
19#include <linux/mount.h> 18#include <linux/mount.h>
@@ -22,9 +21,12 @@
22#include <linux/fsnotify.h> 21#include <linux/fsnotify.h>
23#include <linux/sysctl.h> 22#include <linux/sysctl.h>
24#include <linux/percpu_counter.h> 23#include <linux/percpu_counter.h>
24#include <linux/ima.h>
25 25
26#include <asm/atomic.h> 26#include <asm/atomic.h>
27 27
28#include "internal.h"
29
28/* sysctl tunables... */ 30/* sysctl tunables... */
29struct files_stat_struct files_stat = { 31struct files_stat_struct files_stat = {
30 .max_files = NR_FILE 32 .max_files = NR_FILE
@@ -148,8 +150,6 @@ fail:
148 return NULL; 150 return NULL;
149} 151}
150 152
151EXPORT_SYMBOL(get_empty_filp);
152
153/** 153/**
154 * alloc_file - allocate and initialize a 'struct file' 154 * alloc_file - allocate and initialize a 'struct file'
155 * @mnt: the vfsmount on which the file will reside 155 * @mnt: the vfsmount on which the file will reside
@@ -165,8 +165,8 @@ EXPORT_SYMBOL(get_empty_filp);
165 * If all the callers of init_file() are eliminated, its 165 * If all the callers of init_file() are eliminated, its
166 * code should be moved into this function. 166 * code should be moved into this function.
167 */ 167 */
168struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, 168struct file *alloc_file(struct path *path, fmode_t mode,
169 fmode_t mode, const struct file_operations *fop) 169 const struct file_operations *fop)
170{ 170{
171 struct file *file; 171 struct file *file;
172 172
@@ -174,35 +174,8 @@ struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry,
174 if (!file) 174 if (!file)
175 return NULL; 175 return NULL;
176 176
177 init_file(file, mnt, dentry, mode, fop); 177 file->f_path = *path;
178 return file; 178 file->f_mapping = path->dentry->d_inode->i_mapping;
179}
180EXPORT_SYMBOL(alloc_file);
181
182/**
183 * init_file - initialize a 'struct file'
184 * @file: the already allocated 'struct file' to initialized
185 * @mnt: the vfsmount on which the file resides
186 * @dentry: the dentry representing this file
187 * @mode: the mode the file is opened with
188 * @fop: the 'struct file_operations' for this file
189 *
190 * Use this instead of setting the members directly. Doing so
191 * avoids making mistakes like forgetting the mntget() or
192 * forgetting to take a write on the mnt.
193 *
194 * Note: This is a crappy interface. It is here to make
195 * merging with the existing users of get_empty_filp()
196 * who have complex failure logic easier. All users
197 * of this should be moving to alloc_file().
198 */
199int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
200 fmode_t mode, const struct file_operations *fop)
201{
202 int error = 0;
203 file->f_path.dentry = dentry;
204 file->f_path.mnt = mntget(mnt);
205 file->f_mapping = dentry->d_inode->i_mapping;
206 file->f_mode = mode; 179 file->f_mode = mode;
207 file->f_op = fop; 180 file->f_op = fop;
208 181
@@ -212,14 +185,14 @@ int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
212 * visible. We do this for consistency, and so 185 * visible. We do this for consistency, and so
213 * that we can do debugging checks at __fput() 186 * that we can do debugging checks at __fput()
214 */ 187 */
215 if ((mode & FMODE_WRITE) && !special_file(dentry->d_inode->i_mode)) { 188 if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) {
216 file_take_write(file); 189 file_take_write(file);
217 error = mnt_clone_write(mnt); 190 WARN_ON(mnt_clone_write(path->mnt));
218 WARN_ON(error);
219 } 191 }
220 return error; 192 ima_counts_get(file);
193 return file;
221} 194}
222EXPORT_SYMBOL(init_file); 195EXPORT_SYMBOL(alloc_file);
223 196
224void fput(struct file *file) 197void fput(struct file *file)
225{ 198{
@@ -420,7 +393,9 @@ retry:
420 continue; 393 continue;
421 if (!(f->f_mode & FMODE_WRITE)) 394 if (!(f->f_mode & FMODE_WRITE))
422 continue; 395 continue;
396 spin_lock(&f->f_lock);
423 f->f_mode &= ~FMODE_WRITE; 397 f->f_mode &= ~FMODE_WRITE;
398 spin_unlock(&f->f_lock);
424 if (file_check_writeable(f) != 0) 399 if (file_check_writeable(f) != 0)
425 continue; 400 continue;
426 file_release_write(f); 401 file_release_write(f);