From patchwork Thu Apr 27 19:12:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandhya Bankar X-Patchwork-Id: 9705707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCBFF602BE for ; Sat, 29 Apr 2017 07:45:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B889828671 for ; Sat, 29 Apr 2017 07:45:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB40E28681; Sat, 29 Apr 2017 07:45:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_24_48, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59F9F28671 for ; Sat, 29 Apr 2017 07:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1952464AbdD2HpP (ORCPT ); Sat, 29 Apr 2017 03:45:15 -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 Received: by mail-pf0-f193.google.com with SMTP id v14so20535529pfd.3; Sat, 29 Apr 2017 00:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=C/TvRzm7SpJhi9c1GXQZr42WgdFKkXgD6WM+gLbG/OM=; b=JKnbjJP+BtdwyiA94SfcZL5wekd0BMKAZvLzrzh0XlY9AbuzjnjhNae+8aPQ0BF2id cJvs6mKBKKSSHg7frA3MBiA5pNgDZIlRh8Pc2KOSH/udK5pIwpyimHWVsE83n8sg2iDP Xk+qhjSSeKtBoKkhGTvXJqB80RPKkek5pzLkZxhsaP6Rg7z53Gswh6Wp5HAg0NxHX4Yg eyGOs7bgUpjCJM6hlqUpmsy/axLwz6s+RGQc/48XFqyudNu4nS7sSSkv5vtv/GqFPRWe mLzgihIvHomTogtVds7Y/Jf3dHqMoIIOOIqhynTHqIrdPDZw589WTUaSdxEWo+Fred0y ZtSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=C/TvRzm7SpJhi9c1GXQZr42WgdFKkXgD6WM+gLbG/OM=; b=YwgCyOdsI8R1l9PX8qhZZKeI+U6DbTmg7VwmyxJ8TB0JHjB86sD0wUCwiTCsPhv4Ht z2w2yzQ+NyamaZ+9nBruTnoRQ4LGuBJCjON5BSvvmv++QI7iyJSI+T4B0gvc0bI/dODB UNReCP1duSiY66ZQ76PwnetjcUcb8k8f8VMZbj9I/ScQ9OZaiv9CApZ5dwxEFbr6JDeD jmwp55xHdNfhfZkrY7lWGkQA66NLCEMOS+nijhwYxL+uLJD4Kt5+/hKSdZM5VmQ+2is9 RpS5ZM3w/Wz5KGLH8Ayc6zGFi93J2wk8SPmpBcy6iieSImYGBQXO9R0RpqWeMFcamRbL 7qQA== X-Gm-Message-State: AN3rC/7cUFxRh0fHjg/t4rU4hsK19e6Y43Nz+GKtcDrfr8wfjP4FH/pY nWIvk861ZWJ0PQ== X-Received: by 10.98.112.134 with SMTP id l128mr15939782pfc.161.1493451914126; Sat, 29 Apr 2017 00:45:14 -0700 (PDT) Received: from localhost.localdomain ([223.229.187.11]) by smtp.gmail.com with ESMTPSA id t69sm17919572pfa.81.2017.04.29.00.45.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Apr 2017 00:45:13 -0700 (PDT) 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-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)