From patchwork Wed Dec 7 13:37:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 9464515 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 F122F6022E for ; Wed, 7 Dec 2016 13:37:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D591A283F3 for ; Wed, 7 Dec 2016 13:37:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA5A728499; Wed, 7 Dec 2016 13:37:13 +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=-6.9 required=2.0 tests=BAYES_00,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 5F005283F3 for ; Wed, 7 Dec 2016 13:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932311AbcLGNhF (ORCPT ); Wed, 7 Dec 2016 08:37:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55510 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206AbcLGNhE (ORCPT ); Wed, 7 Dec 2016 08:37:04 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C46D4C054929; Wed, 7 Dec 2016 13:37:03 +0000 (UTC) Received: from bcodding.csb (vpn-63-30.rdu2.redhat.com [10.10.63.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uB7Db3kZ013414; Wed, 7 Dec 2016 08:37:03 -0500 Received: by bcodding.csb (Postfix, from userid 24008) id 928D810C3110; Wed, 7 Dec 2016 08:37:02 -0500 (EST) From: Benjamin Coddington To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH] NFS: Serialize nfs_readdir() Date: Wed, 7 Dec 2016 08:37:02 -0500 Message-Id: References: In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 07 Dec 2016 13:37:03 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Optimizations to NFS to choose between READDIR and READDIRPLUS don't expect concurrent users of nfs_readdir(), and can cause the pagecache to repeatedly be invalidated unnecessarily for this case. Fix this by serializing nfs_readdir() on the directory's rwsem. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 53e6d6a4bc9c..8321252a4c8d 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -900,6 +900,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) { struct dentry *dentry = file_dentry(file); struct inode *inode = d_inode(dentry); + struct nfs_inode *nfsi = NFS_I(inode); nfs_readdir_descriptor_t my_desc, *desc = &my_desc; struct nfs_open_dir_context *dir_ctx = file->private_data; @@ -917,6 +918,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) */ memset(desc, 0, sizeof(*desc)); + down_write(&nfsi->rwsem); desc->file = file; desc->ctx = ctx; desc->dir_cookie = &dir_ctx->dir_cookie; @@ -958,6 +960,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) break; } while (!desc->eof); out: + up_write(&nfsi->rwsem); if (res > 0) res = 0; dfprintk(FILE, "NFS: readdir(%pD2) returns %d\n", file, res);