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, 33 insertions, 16 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 32d12b78bac8..2fc3b3c08911 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -194,14 +194,6 @@ struct file *alloc_file(struct path *path, fmode_t mode,
194} 194}
195EXPORT_SYMBOL(alloc_file); 195EXPORT_SYMBOL(alloc_file);
196 196
197void fput(struct file *file)
198{
199 if (atomic_long_dec_and_test(&file->f_count))
200 __fput(file);
201}
202
203EXPORT_SYMBOL(fput);
204
205/** 197/**
206 * drop_file_write_access - give up ability to write to a file 198 * drop_file_write_access - give up ability to write to a file
207 * @file: the file to which we will stop writing 199 * @file: the file to which we will stop writing
@@ -227,10 +219,9 @@ void drop_file_write_access(struct file *file)
227} 219}
228EXPORT_SYMBOL_GPL(drop_file_write_access); 220EXPORT_SYMBOL_GPL(drop_file_write_access);
229 221
230/* __fput is called from task context when aio completion releases the last 222/* the real guts of fput() - releasing the last reference to file
231 * last use of a struct file *. Do not use otherwise.
232 */ 223 */
233void __fput(struct file *file) 224static void __fput(struct file *file)
234{ 225{
235 struct dentry *dentry = file->f_path.dentry; 226 struct dentry *dentry = file->f_path.dentry;
236 struct vfsmount *mnt = file->f_path.mnt; 227 struct vfsmount *mnt = file->f_path.mnt;
@@ -239,6 +230,15 @@ void __fput(struct file *file)
239 might_sleep(); 230 might_sleep();
240 231
241 fsnotify_close(file); 232 fsnotify_close(file);
233
234 /*
235 * fsnotify_create_event may have taken one or more references on this
236 * file. If it did so it left one reference for us to drop to make sure
237 * its calls to fput could not prematurely destroy the file.
238 */
239 if (atomic_long_read(&file->f_count))
240 return fput(file);
241
242 /* 242 /*
243 * The function eventpoll_release() should be the first called 243 * The function eventpoll_release() should be the first called
244 * in the file cleanup chain. 244 * in the file cleanup chain.
@@ -268,6 +268,14 @@ void __fput(struct file *file)
268 mntput(mnt); 268 mntput(mnt);
269} 269}
270 270
271void fput(struct file *file)
272{
273 if (atomic_long_dec_and_test(&file->f_count))
274 __fput(file);
275}
276
277EXPORT_SYMBOL(fput);
278
271struct file *fget(unsigned int fd) 279struct file *fget(unsigned int fd)
272{ 280{
273 struct file *file; 281 struct file *file;
@@ -290,11 +298,20 @@ struct file *fget(unsigned int fd)
290EXPORT_SYMBOL(fget); 298EXPORT_SYMBOL(fget);
291 299
292/* 300/*
293 * Lightweight file lookup - no refcnt increment if fd table isn't shared. 301 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
294 * You can use this only if it is guranteed that the current task already 302 *
295 * holds a refcnt to that file. That check has to be done at fget() only 303 * You can use this instead of fget if you satisfy all of the following
296 * and a flag is returned to be passed to the corresponding fput_light(). 304 * conditions:
297 * There must not be a cloning between an fget_light/fput_light pair. 305 * 1) You must call fput_light before exiting the syscall and returning control
306 * to userspace (i.e. you cannot remember the returned struct file * after
307 * returning to userspace).
308 * 2) You must not call filp_close on the returned struct file * in between
309 * calls to fget_light and fput_light.
310 * 3) You must not clone the current task in between the calls to fget_light
311 * and fput_light.
312 *
313 * The fput_needed flag returned by fget_light should be passed to the
314 * corresponding fput_light.
298 */ 315 */
299struct file *fget_light(unsigned int fd, int *fput_needed) 316struct file *fget_light(unsigned int fd, int *fput_needed)
300{ 317{