Lines Matching full:files

53  * space if any.  This does not copy the file pointers.  Called with the files
71 * clear the extra space. Called with the files spinlock held for write.
164 * The files->file_lock should be held on entry, and will be held on exit.
166 static int expand_fdtable(struct files_struct *files, unsigned int nr) in expand_fdtable() argument
167 __releases(files->file_lock) in expand_fdtable()
168 __acquires(files->file_lock) in expand_fdtable()
172 spin_unlock(&files->file_lock); in expand_fdtable()
178 if (atomic_read(&files->count) > 1) in expand_fdtable()
181 spin_lock(&files->file_lock); in expand_fdtable()
192 cur_fdt = files_fdtable(files); in expand_fdtable()
195 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
196 if (cur_fdt != &files->fdtab) in expand_fdtable()
204 * Expand files.
207 * Return <0 error code on error; 0 when nothing done; 1 when files were
209 * The files->file_lock should be held on entry, and will be held on exit.
211 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
212 __releases(files->file_lock) in expand_files()
213 __acquires(files->file_lock) in expand_files()
219 fdt = files_fdtable(files); in expand_files()
229 if (unlikely(files->resize_in_progress)) { in expand_files()
230 spin_unlock(&files->file_lock); in expand_files()
232 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
233 spin_lock(&files->file_lock); in expand_files()
238 files->resize_in_progress = true; in expand_files()
239 expanded = expand_fdtable(files, nr); in expand_files()
240 files->resize_in_progress = false; in expand_files()
242 wake_up_all(&files->resize_wait); in expand_files()
372 * instantiated in the files array if a sibling thread in dup_fd()
394 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
399 * files structure. in close_files()
401 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
414 filp_close(file, files); in close_files()
426 void put_files_struct(struct files_struct *files) in put_files_struct() argument
428 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
429 struct fdtable *fdt = close_files(files); in put_files_struct()
432 if (fdt != &files->fdtab) in put_files_struct()
434 kmem_cache_free(files_cachep, files); in put_files_struct()
440 struct files_struct * files = tsk->files; in exit_files() local
442 if (files) { in exit_files()
444 tsk->files = NULL; in exit_files()
446 put_files_struct(files); in exit_files()
483 struct files_struct *files = current->files; in alloc_fd() local
488 spin_lock(&files->file_lock); in alloc_fd()
490 fdt = files_fdtable(files); in alloc_fd()
492 if (fd < files->next_fd) in alloc_fd()
493 fd = files->next_fd; in alloc_fd()
499 * N.B. For clone tasks sharing a files structure, this test in alloc_fd()
500 * will limit the total number of files that can be opened. in alloc_fd()
506 error = expand_files(files, fd); in alloc_fd()
517 if (start <= files->next_fd) in alloc_fd()
518 files->next_fd = fd + 1; in alloc_fd()
535 spin_unlock(&files->file_lock); in alloc_fd()
550 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
552 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
554 if (fd < files->next_fd) in __put_unused_fd()
555 files->next_fd = fd; in __put_unused_fd()
560 struct files_struct *files = current->files; in put_unused_fd() local
561 spin_lock(&files->file_lock); in put_unused_fd()
562 __put_unused_fd(files, fd); in put_unused_fd()
563 spin_unlock(&files->file_lock); in put_unused_fd()
571 * The VFS is full of places where we drop the files lock between
586 struct files_struct *files = current->files; in fd_install() local
591 if (unlikely(files->resize_in_progress)) { in fd_install()
593 spin_lock(&files->file_lock); in fd_install()
594 fdt = files_fdtable(files); in fd_install()
597 spin_unlock(&files->file_lock); in fd_install()
602 fdt = rcu_dereference_sched(files->fdt); in fd_install()
612 * @files: file struct to retrieve file from
619 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file() argument
621 struct fdtable *fdt = files_fdtable(files); in pick_file()
631 __put_unused_fd(files, fd); in pick_file()
638 struct files_struct *files = current->files; in close_fd() local
641 spin_lock(&files->file_lock); in close_fd()
642 file = pick_file(files, fd); in close_fd()
643 spin_unlock(&files->file_lock); in close_fd()
647 return filp_close(file, files); in close_fd()
678 static inline void __range_close(struct files_struct *files, unsigned int fd, in __range_close() argument
684 spin_lock(&files->file_lock); in __range_close()
685 n = last_fd(files_fdtable(files)); in __range_close()
689 file = pick_file(files, fd); in __range_close()
691 spin_unlock(&files->file_lock); in __range_close()
692 filp_close(file, files); in __range_close()
694 spin_lock(&files->file_lock); in __range_close()
696 spin_unlock(&files->file_lock); in __range_close()
698 spin_lock(&files->file_lock); in __range_close()
701 spin_unlock(&files->file_lock); in __range_close()
717 struct files_struct *cur_fds = me->files, *fds = NULL; in __close_range()
753 * We're done closing the files we were supposed to. Time to install in __close_range()
757 me->files = cur_fds; in __close_range()
766 * See close_fd_get_file() below, this variant assumes current->files->file_lock
771 return pick_file(current->files, fd); in __close_fd_get_file()
780 struct files_struct *files = current->files; in close_fd_get_file() local
783 spin_lock(&files->file_lock); in close_fd_get_file()
784 file = pick_file(files, fd); in close_fd_get_file()
785 spin_unlock(&files->file_lock); in close_fd_get_file()
790 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
796 spin_lock(&files->file_lock); in do_close_on_exec()
800 fdt = files_fdtable(files); in do_close_on_exec()
815 __put_unused_fd(files, fd); in do_close_on_exec()
816 spin_unlock(&files->file_lock); in do_close_on_exec()
817 filp_close(file, files); in do_close_on_exec()
819 spin_lock(&files->file_lock); in do_close_on_exec()
823 spin_unlock(&files->file_lock); in do_close_on_exec()
826 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu() argument
831 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in __fget_files_rcu()
866 if (unlikely(rcu_dereference_raw(files->fdt) != fdt) || in __fget_files_rcu()
880 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
886 file = __fget_files_rcu(files, fd, mask); in __fget_files()
894 return __fget_files(current->files, fd, mask); in __fget()
914 if (task->files) in fget_task()
915 file = __fget_files(task->files, fd, 0); in fget_task()
924 struct files_struct *files; in task_lookup_fd_rcu() local
928 files = task->files; in task_lookup_fd_rcu()
929 if (files) in task_lookup_fd_rcu()
930 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
939 struct files_struct *files; in task_lookup_next_fd_rcu() local
944 files = task->files; in task_lookup_next_fd_rcu()
945 if (files) { in task_lookup_next_fd_rcu()
946 for (; fd < files_fdtable(files)->max_fds; fd++) { in task_lookup_next_fd_rcu()
947 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
976 struct files_struct *files = current->files; in __fget_light() local
988 if (atomic_read_acquire(&files->count) == 1) { in __fget_light()
989 file = files_lookup_fd_raw(files, fd); in __fget_light()
1052 struct files_struct *files = current->files; in set_close_on_exec() local
1054 spin_lock(&files->file_lock); in set_close_on_exec()
1055 fdt = files_fdtable(files); in set_close_on_exec()
1060 spin_unlock(&files->file_lock); in set_close_on_exec()
1065 struct files_struct *files = current->files; in get_close_on_exec() local
1069 fdt = files_fdtable(files); in get_close_on_exec()
1075 static int do_dup2(struct files_struct *files, in do_dup2() argument
1077 __releases(&files->file_lock) in do_dup2()
1088 * fget() treats larval files as absent. Potentially interesting, in do_dup2()
1096 fdt = files_fdtable(files); in do_dup2()
1108 spin_unlock(&files->file_lock); in do_dup2()
1111 filp_close(tofree, files); in do_dup2()
1116 spin_unlock(&files->file_lock); in do_dup2()
1123 struct files_struct *files = current->files; in replace_fd() local
1131 spin_lock(&files->file_lock); in replace_fd()
1132 err = expand_files(files, fd); in replace_fd()
1135 return do_dup2(files, file, fd, flags); in replace_fd()
1138 spin_unlock(&files->file_lock); in replace_fd()
1207 struct files_struct *files = current->files; in ksys_dup3() local
1218 spin_lock(&files->file_lock); in ksys_dup3()
1219 err = expand_files(files, newfd); in ksys_dup3()
1220 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1228 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1233 spin_unlock(&files->file_lock); in ksys_dup3()
1245 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1249 if (!files_lookup_fd_rcu(files, oldfd)) in SYSCALL_DEFINE2()
1286 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1292 if (!files) in iterate_fd()
1294 spin_lock(&files->file_lock); in iterate_fd()
1295 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1297 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1304 spin_unlock(&files->file_lock); in iterate_fd()