From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1952613AbdD2HpX (ORCPT ); Sat, 29 Apr 2017 03:45:23 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35979 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1951218AbdD2HpO (ORCPT ); Sat, 29 Apr 2017 03:45:14 -0400 Date: Fri, 28 Apr 2017 00:42:05 +0530 From: Sandhya Bankar To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, mawmilcox@microsoft.com, keescook@chromium.org, adobriyan@gmail.com, re.emese@gmail.com, riel@surriel.com Subject: [PATCH 09/13] vfs: Rewrite close_files() Message-ID: <7453be343ca52991abe1820d834d2877ce1d7023.1493315290.git.bankarsandhya512@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Matthew Wilcox --- 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