Lines Matching refs:files

252 static int expand_fdtable(struct files_struct *files, unsigned int nr)  in expand_fdtable()  argument
253 __releases(files->file_lock) in expand_fdtable()
254 __acquires(files->file_lock) in expand_fdtable()
258 spin_unlock(&files->file_lock); in expand_fdtable()
264 if (atomic_read(&files->count) > 1) in expand_fdtable()
267 spin_lock(&files->file_lock); in expand_fdtable()
270 cur_fdt = files_fdtable(files); in expand_fdtable()
273 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
274 if (cur_fdt != &files->fdtab) in expand_fdtable()
288 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
289 __releases(files->file_lock) in expand_files()
290 __acquires(files->file_lock) in expand_files()
296 fdt = files_fdtable(files); in expand_files()
302 if (unlikely(files->resize_in_progress)) { in expand_files()
303 spin_unlock(&files->file_lock); in expand_files()
304 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
305 spin_lock(&files->file_lock); in expand_files()
314 files->resize_in_progress = true; in expand_files()
315 error = expand_fdtable(files, nr); in expand_files()
316 files->resize_in_progress = false; in expand_files()
318 wake_up_all(&files->resize_wait); in expand_files()
474 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
481 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
494 filp_close(file, files); in close_files()
506 void put_files_struct(struct files_struct *files) in put_files_struct() argument
508 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
509 struct fdtable *fdt = close_files(files); in put_files_struct()
512 if (fdt != &files->fdtab) in put_files_struct()
514 kmem_cache_free(files_cachep, files); in put_files_struct()
520 struct files_struct * files = tsk->files; in exit_files() local
522 if (files) { in exit_files()
524 tsk->files = NULL; in exit_files()
526 put_files_struct(files); in exit_files()
572 struct files_struct *files = current->files; in alloc_fd() local
577 spin_lock(&files->file_lock); in alloc_fd()
579 fdt = files_fdtable(files); in alloc_fd()
581 if (fd < files->next_fd) in alloc_fd()
582 fd = files->next_fd; in alloc_fd()
596 error = expand_files(files, fd); in alloc_fd()
603 if (start <= files->next_fd) in alloc_fd()
604 files->next_fd = fd + 1; in alloc_fd()
611 spin_unlock(&files->file_lock); in alloc_fd()
626 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
628 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
630 if (fd < files->next_fd) in __put_unused_fd()
631 files->next_fd = fd; in __put_unused_fd()
636 struct files_struct *files = current->files; in put_unused_fd() local
637 spin_lock(&files->file_lock); in put_unused_fd()
638 __put_unused_fd(files, fd); in put_unused_fd()
639 spin_unlock(&files->file_lock); in put_unused_fd()
662 struct files_struct *files = current->files; in fd_install_slowpath() local
665 spin_lock(&files->file_lock); in fd_install_slowpath()
666 fdt = files_fdtable(files); in fd_install_slowpath()
669 spin_unlock(&files->file_lock); in fd_install_slowpath()
682 struct files_struct *files = current->files; in fd_install() local
689 if (unlikely(files->resize_in_progress)) { in fd_install()
696 fdt = rcu_dereference_sched(files->fdt); in fd_install()
715 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd) in file_close_fd_locked() argument
717 struct fdtable *fdt = files_fdtable(files); in file_close_fd_locked()
720 lockdep_assert_held(&files->file_lock); in file_close_fd_locked()
729 __put_unused_fd(files, fd); in file_close_fd_locked()
736 struct files_struct *files = current->files; in close_fd() local
739 spin_lock(&files->file_lock); in close_fd()
740 file = file_close_fd_locked(files, fd); in close_fd()
741 spin_unlock(&files->file_lock); in close_fd()
745 return filp_close(file, files); in close_fd()
776 static inline void __range_close(struct files_struct *files, unsigned int fd, in __range_close() argument
783 spin_lock(&files->file_lock); in __range_close()
784 fdt = files_fdtable(files); in __range_close()
791 file = file_close_fd_locked(files, fd); in __range_close()
793 spin_unlock(&files->file_lock); in __range_close()
794 filp_close(file, files); in __range_close()
796 spin_lock(&files->file_lock); in __range_close()
797 fdt = files_fdtable(files); in __range_close()
799 spin_unlock(&files->file_lock); in __range_close()
801 spin_lock(&files->file_lock); in __range_close()
802 fdt = files_fdtable(files); in __range_close()
805 spin_unlock(&files->file_lock); in __range_close()
823 struct files_struct *cur_fds = me->files, *fds = NULL; in SYSCALL_DEFINE3()
863 me->files = cur_fds; in SYSCALL_DEFINE3()
881 struct files_struct *files = current->files; in file_close_fd() local
884 spin_lock(&files->file_lock); in file_close_fd()
885 file = file_close_fd_locked(files, fd); in file_close_fd()
886 spin_unlock(&files->file_lock); in file_close_fd()
891 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
897 spin_lock(&files->file_lock); in do_close_on_exec()
901 fdt = files_fdtable(files); in do_close_on_exec()
916 __put_unused_fd(files, fd); in do_close_on_exec()
917 spin_unlock(&files->file_lock); in do_close_on_exec()
918 filp_close(file, files); in do_close_on_exec()
920 spin_lock(&files->file_lock); in do_close_on_exec()
924 spin_unlock(&files->file_lock); in do_close_on_exec()
1018 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu() argument
1023 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in __fget_files_rcu()
1072 unlikely(rcu_dereference_raw(files->fdt) != fdt)) { in __fget_files_rcu()
1094 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
1100 file = __fget_files_rcu(files, fd, mask); in __fget_files()
1108 return __fget_files(current->files, fd, mask); in __fget()
1128 if (task->files) in fget_task()
1129 file = __fget_files(task->files, fd, 0); in fget_task()
1138 struct files_struct *files; in fget_task_next() local
1143 files = task->files; in fget_task_next()
1144 if (files) { in fget_task_next()
1146 for (; fd < files_fdtable(files)->max_fds; fd++) { in fget_task_next()
1147 file = __fget_files_rcu(files, fd, 0); in fget_task_next()
1184 struct files_struct *files = current->files; in __fget_light() local
1196 if (likely(atomic_read_acquire(&files->count) == 1)) { in __fget_light()
1197 file = files_lookup_fd_raw(files, fd); in __fget_light()
1202 file = __fget_files(files, fd, mask); in __fget_light()
1279 struct files_struct *files = current->files; in set_close_on_exec() local
1280 spin_lock(&files->file_lock); in set_close_on_exec()
1281 __set_close_on_exec(fd, files_fdtable(files), flag); in set_close_on_exec()
1282 spin_unlock(&files->file_lock); in set_close_on_exec()
1289 res = close_on_exec(fd, current->files); in get_close_on_exec()
1294 static int do_dup2(struct files_struct *files, in do_dup2() argument
1296 __releases(&files->file_lock) in do_dup2()
1327 fdt = files_fdtable(files); in do_dup2()
1335 spin_unlock(&files->file_lock); in do_dup2()
1338 filp_close(tofree, files); in do_dup2()
1343 spin_unlock(&files->file_lock); in do_dup2()
1350 struct files_struct *files = current->files; in replace_fd() local
1358 spin_lock(&files->file_lock); in replace_fd()
1359 err = expand_files(files, fd); in replace_fd()
1362 err = do_dup2(files, file, fd, flags); in replace_fd()
1368 spin_unlock(&files->file_lock); in replace_fd()
1429 struct files_struct *files = current->files; in ksys_dup3() local
1440 spin_lock(&files->file_lock); in ksys_dup3()
1441 err = expand_files(files, newfd); in ksys_dup3()
1442 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1450 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1455 spin_unlock(&files->file_lock); in ksys_dup3()
1467 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1472 f = __fget_files_rcu(files, oldfd, 0); in SYSCALL_DEFINE2()
1512 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1518 if (!files) in iterate_fd()
1520 spin_lock(&files->file_lock); in iterate_fd()
1521 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1523 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1530 spin_unlock(&files->file_lock); in iterate_fd()