Blob Blame History Raw
commit 4017afe28d640c535109576bd149bc7e0345f075
Author: Rajesh Ghanekar <rajesh_ghanekar@symantec.com>
Date:   Wed Aug 20 14:00:59 2014 -0400

    nfs-utils: Allow turning off nfsv3 readdir_plus
    
    One of our customer's application only needs file names, not file
    attributes. With directories having 10K+ inodes (assuming buffer cache
    has directory blocks cached having file names, but inode cache is
    limited and hence need eviction of older cached inodes), older inodes
    are evicted periodically. So if they keep on doing readdir(2) from NSF
    client on multiple directories, some directory's files are periodically
    removed from inode cache and hence new readdir(2) on same directory
    requires disk access to bring back inodes again to inode cache.
    
    As READDIRPLUS request fetches attributes also, doing getattr on each
    file on server, it causes unnecessary disk accesses. If READDIRPLUS on
    NFS client is returned with -ENOTSUPP, NFS client uses READDIR request
    which just gets the names of the files in a directory, not attributes,
    hence avoiding disk accesses on server.
    
    There's already a corresponding client-side mount option, but an export
    option reduces the need for configuration across multiple clients.
    
    This flag affects NFSv3 only.  If it turns out it's needed for NFSv4 as
    well then we may have to figure out how to extend the behavior to NFSv4,
    but it's not currently obvious how to do that.
    
    Signed-off-by: Rajesh Ghanekar <rajesh_ghanekar@symantec.com>
    Signed-off-by: Steve Dickson <steved@redhat.com>

diff --git a/support/include/nfs/export.h b/support/include/nfs/export.h
index 1547a87..2f59e6a 100644
--- a/support/include/nfs/export.h
+++ b/support/include/nfs/export.h
@@ -17,7 +17,8 @@
 #define NFSEXP_ALLSQUASH	0x0008
 #define NFSEXP_ASYNC		0x0010
 #define NFSEXP_GATHERED_WRITES	0x0020
-/* 40, 80, 100 unused */
+#define NFSEXP_NOREADDIRPLUS	0x0040
+/* 80, 100 unused */
 #define NFSEXP_NOHIDE		0x0200
 #define NFSEXP_NOSUBTREECHECK	0x0400
 #define NFSEXP_NOAUTHNLM	0x0800
diff --git a/support/nfs/exports.c b/support/nfs/exports.c
index 819d6c4..eb782b9 100644
--- a/support/nfs/exports.c
+++ b/support/nfs/exports.c
@@ -273,6 +273,8 @@ putexportent(struct exportent *ep)
 		"in" : "");
 	fprintf(fp, "%sacl,", (ep->e_flags & NFSEXP_NOACL)?
 		"no_" : "");
+	if (ep->e_flags & NFSEXP_NOREADDIRPLUS)
+		fprintf(fp, "nordirplus,");
 	if (ep->e_flags & NFSEXP_FSID) {
 		fprintf(fp, "fsid=%d,", ep->e_fsid);
 	}
@@ -539,6 +541,8 @@ parseopts(char *cp, struct exportent *ep, int warn, int *had_subtree_opt_ptr)
 			clearflags(NFSEXP_ASYNC, active, ep);
 		else if (!strcmp(opt, "async"))
 			setflags(NFSEXP_ASYNC, active, ep);
+		else if (!strcmp(opt, "nordirplus"))
+			setflags(NFSEXP_NOREADDIRPLUS, active, ep);
 		else if (!strcmp(opt, "nohide"))
 			setflags(NFSEXP_NOHIDE, active, ep);
 		else if (!strcmp(opt, "hide"))
diff --git a/utils/exportfs/exports.man b/utils/exportfs/exports.man
index e8b29df..3d974d9 100644
--- a/utils/exportfs/exports.man
+++ b/utils/exportfs/exports.man
@@ -360,6 +360,11 @@ supported so the same configuration can be made to work on old and new
 kernels alike.
 
 .TP
+.IR nordirplus
+This option will disable READDIRPLUS request handling.  When set,
+READDIRPLUS requests from NFS clients return NFS3ERR_NOTSUPP, and
+clients fall back on READDIR.  This option affects only NFSv3 clients.
+.TP
 .IR refer= path@host[+host][:path@host[+host]]
 A client referencing the export point will be directed to choose from
 the given list an alternative location for the filesystem.