Return-Path: 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 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: Sender: linux-nfs-owner@vger.kernel.org List-ID: 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); -- 2.5.5