8 #include <linux/string.h>
9 #include <linux/slab.h>
13 #include <linux/module.h>
16 #include <linux/eventpoll.h>
19 #include <linux/capability.h>
22 #include <linux/sysctl.h>
54 static inline void file_free(
struct file *
f)
56 percpu_counter_dec(&nr_files);
64 static long get_nr_files(
void)
66 return percpu_counter_read_positive(&nr_files);
81 #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
83 void __user *
buffer,
size_t *lenp, loff_t *ppos)
85 files_stat.
nr_files = get_nr_files();
90 void __user *
buffer,
size_t *lenp, loff_t *ppos)
120 if (percpu_counter_sum_positive(&nr_files) >= files_stat.
max_files)
124 f = kmem_cache_zalloc(filp_cachep,
GFP_KERNEL);
128 percpu_counter_inc(&nr_files);
129 f->
f_cred = get_cred(cred);
134 atomic_long_set(&f->
f_count, 1);
137 eventpoll_init_file(f);
143 if (get_nr_files() > old_max) {
145 old_max = get_nr_files();
191 file_take_write(file);
195 i_readcount_inc(path->
dentry->d_inode);
208 static void drop_file_write_access(
struct file *
file)
214 put_write_access(inode);
218 if (file_check_writeable(file) != 0)
221 file_release_write(file);
226 static void __fput(
struct file *file)
228 struct dentry *dentry = file->
f_path.dentry;
230 struct inode *inode = dentry->
d_inode;
234 fsnotify_close(file);
239 eventpoll_release(file);
243 if (file->
f_op && file->
f_op->fasync)
244 file->
f_op->fasync(-1, file, 0);
247 if (file->
f_op && file->
f_op->release)
248 file->
f_op->release(inode, file);
257 i_readcount_dec(inode);
259 drop_file_write_access(file);
272 spin_lock_irq(&delayed_fput_lock);
273 list_splice_init(&delayed_fput_list, &
head);
274 spin_unlock_irq(&delayed_fput_lock);
275 while (!list_empty(&
head)) {
306 if (atomic_long_dec_and_test(&file->
f_count)) {
312 list_add(&file->
f_u.
fu_list, &delayed_fput_list);
314 spin_unlock_irqrestore(&delayed_fput_lock, flags);
332 if (atomic_long_dec_and_test(&file->
f_count)) {
344 if (atomic_long_dec_and_test(&file->
f_count)) {
351 static inline int file_list_cpu(
struct file *file)
354 return file->f_sb_list_cpu;
361 static inline void __file_sb_list_add(
struct file *file,
struct super_block *
sb)
367 file->f_sb_list_cpu =
cpu;
386 __file_sb_list_add(file, sb);
412 #define do_file_list_for_each_entry(__sb, __file) \
415 for_each_possible_cpu(i) { \
416 struct list_head *list; \
417 list = per_cpu_ptr((__sb)->s_files, i); \
418 list_for_each_entry((__file), list, f_u.fu_list)
420 #define while_file_list_for_each_entry \
426 #define do_file_list_for_each_entry(__sb, __file) \
428 struct list_head *list; \
429 list = &(sb)->s_files; \
430 list_for_each_entry((__file), list, f_u.fu_list)
432 #define while_file_list_for_each_entry \
459 if (file_check_writeable(f) != 0)
461 file_release_write(f);
479 n = (mempages * (
PAGE_SIZE / 1024)) / 10;
483 percpu_counter_init(&nr_files, 0);