Get empty filp

Retired DISLab
김건우 (토론 | 기여) 사용자의 2014년 4월 30일 (수) 02:37 버전
(비교) ← 이전 판 | 현재 판 (비교) | 다음 판 → (비교)
이동: 둘러보기, 찾기

http://lxr.free-electrons.com/source/fs/file_table.c#L104

 94 /* Find an unused file structure and return a pointer to it.
 95  * Returns an error pointer if some error happend e.g. we over file
 96  * structures limit, run out of memory or operation is not permitted.
 97  *
 98  * Be very careful using this.  You are responsible for
 99  * getting write access to any mount that you might assign
100  * to this filp, if it is opened for write.  If this is not
101  * done, you will imbalance int the mount's writer count
102  * and a warning at __fput() time.
103  */
104 struct file *get_empty_filp(void)
105 {
106         const struct cred *cred = current_cred();
107         static long old_max;
108         struct file *f;
109         int error;
110 
111         /*
112          * Privileged users can go above max_files
113          */
114         if (get_nr_files() >= files_stat.max_files && !capable(CAP_SYS_ADMIN)) {
115                 /*
116                  * percpu_counters are inaccurate.  Do an expensive check before
117                  * we go and fail.
118                  */
119                 if (percpu_counter_sum_positive(&nr_files) >= files_stat.max_files)
120                         goto over;
121         }
122 
123         f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL);
124         if (unlikely(!f))
125                 return ERR_PTR(-ENOMEM);
126 
127         percpu_counter_inc(&nr_files);
128         f->f_cred = get_cred(cred);
129         error = security_file_alloc(f);
130         if (unlikely(error)) {
131                 file_free(f);
132                 return ERR_PTR(error);
133         }
134 
135         atomic_long_set(&f->f_count, 1);
136         rwlock_init(&f->f_owner.lock);
137         spin_lock_init(&f->f_lock);
138         mutex_init(&f->f_pos_lock);
139         eventpoll_init_file(f);
140         /* f->f_version: 0 */
141         return f;
142 
143 over:
144         /* Ran out of filps - report that */
145         if (get_nr_files() > old_max) {
146                 pr_info("VFS: file-max limit %lu reached\n", get_max_files());
147                 old_max = get_nr_files();
148         }
149         return ERR_PTR(-ENFILE);
150 }
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기