Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1633264
| From | Sandhya Bankar <bankarsandhya512@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 09/13] vfs: Rewrite close_files() |
| Date | 2017-04-29 09:50 +0200 |
| Message-ID | <tBviG-3qf-19@gated-at.bofh.it> (permalink) |
| References | <tBuZk-3il-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Use the IDR iteration functionality instead of the open_fds bitmap to
call filp_close() for each open file. Also make close_files() return
void, because it no longer uses the fdtable.
Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
---
fs/file.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/fs/file.c b/fs/file.c
index 8d67968..8cd77c5 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -373,37 +373,21 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
return NULL;
}
-static struct fdtable *close_files(struct files_struct * files)
+static void close_files(struct files_struct * files)
{
/*
- * It is safe to dereference the fd table without RCU or
- * ->file_lock because this is the last reference to the
- * files structure.
+ * No need for RCU or ->file_lock protection because
+ * this is the last reference to the files structure.
*/
- struct fdtable *fdt = rcu_dereference_raw(files->fdt);
- unsigned int i, j = 0;
+ struct file *file;
+ int fd;
- for (;;) {
- unsigned long set;
- i = j * BITS_PER_LONG;
- if (i >= fdt->max_fds)
- break;
- set = fdt->open_fds[j++];
- while (set) {
- if (set & 1) {
- struct file *file;
- file = idr_remove(&files->fd_idr, i);
- if (file) {
- filp_close(file, files);
- cond_resched_rcu_qs();
- }
- }
- i++;
- set >>= 1;
- }
+ idr_for_each_entry(&files->fd_idr, file, fd) {
+ filp_close(file, files);
+ cond_resched_rcu_qs();
}
- return fdt;
+ idr_destroy(&files->fd_idr);
}
struct files_struct *get_files_struct(struct task_struct *task)
@@ -422,7 +406,8 @@ struct files_struct *get_files_struct(struct task_struct *task)
void put_files_struct(struct files_struct *files)
{
if (atomic_dec_and_test(&files->count)) {
- struct fdtable *fdt = close_files(files);
+ struct fdtable *fdt = rcu_dereference_raw(files->fdt);
+ close_files(files);
/* free the arrays if they are not embedded */
if (fdt != &files->fdtab)
--
1.8.3.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/13] vfs: Convert file allocation code to use the IDR Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:30 +0200 [PATCH 02/13] idr: Add idr_for_each_entry_tagged() Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:40 +0200 [PATCH 03/13] idr, radix-tree: Add get_tag_batch function Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 08/13] vfs: Use idr_tag_get() in fd_is_open(). Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 04/13] idr, radix-tree: Implement copy_preload Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 07/13] vfs: Remove full_fds_bits from fd allocation code path. Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 09/13] vfs: Rewrite close_files() Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 05/13] vfs: Replace array of file pointers with an IDR Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 06/13] vfs: Remove next_fd from fd alloc code path. Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 10/13] vfs: Replace close_on_exec bitmap with an IDR tag Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 09:50 +0200 [PATCH 13/13] vfs: Delete struct fdtable Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 10:00 +0200 [PATCH 12/13] vfs: Convert select to use idr_get_tag_batch() Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 10:00 +0200 [PATCH 11/13] vfs: Add init_task.h include Sandhya Bankar <bankarsandhya512@gmail.com> - 2017-04-29 10:00 +0200
csiph-web