Skip to content

Commit cfe1f87

Browse files
bcodding-rhTrond Myklebust
authored andcommitted
NFS: Extend rdirplus mount option with "force|none"
There are certain users that wish to force the NFS client to choose READDIRPLUS over READDIR for a particular mount. Update the "rdirplus" mount option to optionally accept values. For "rdirplus=force", the NFS client will always attempt to use READDDIRPLUS. The setting of "rdirplus=none" is aliased to the existing "nordirplus". Signed-off-by: Benjamin Coddington <[email protected]> Link: https://lore.kernel.org/r/c4cf0de4c8be0930b91bc74bee310d289781cd3b.1741885071.git.bcodding@redhat.com Signed-off-by: Trond Myklebust <[email protected]>
1 parent 2d6a194 commit cfe1f87

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

fs/nfs/dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ static bool nfs_use_readdirplus(struct inode *dir, struct dir_context *ctx,
666666
{
667667
if (!nfs_server_capable(dir, NFS_CAP_READDIRPLUS))
668668
return false;
669+
if (NFS_SERVER(dir)->flags & NFS_MOUNT_FORCE_RDIRPLUS)
670+
return true;
669671
if (ctx->pos == 0 ||
670672
cache_hits + cache_misses > NFS_READDIR_CACHE_USAGE_THRESHOLD)
671673
return true;

fs/nfs/fs_context.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ enum nfs_param {
7272
Opt_posix,
7373
Opt_proto,
7474
Opt_rdirplus,
75+
Opt_rdirplus_none,
76+
Opt_rdirplus_force,
7577
Opt_rdma,
7678
Opt_resvport,
7779
Opt_retrans,
@@ -174,7 +176,8 @@ static const struct fs_parameter_spec nfs_fs_parameters[] = {
174176
fsparam_u32 ("port", Opt_port),
175177
fsparam_flag_no("posix", Opt_posix),
176178
fsparam_string("proto", Opt_proto),
177-
fsparam_flag_no("rdirplus", Opt_rdirplus),
179+
fsparam_flag_no("rdirplus", Opt_rdirplus), // rdirplus|nordirplus
180+
fsparam_string("rdirplus", Opt_rdirplus), // rdirplus=...
178181
fsparam_flag ("rdma", Opt_rdma),
179182
fsparam_flag_no("resvport", Opt_resvport),
180183
fsparam_u32 ("retrans", Opt_retrans),
@@ -288,6 +291,12 @@ static const struct constant_table nfs_xprtsec_policies[] = {
288291
{}
289292
};
290293

294+
static const struct constant_table nfs_rdirplus_tokens[] = {
295+
{ "none", Opt_rdirplus_none },
296+
{ "force", Opt_rdirplus_force },
297+
{}
298+
};
299+
291300
/*
292301
* Sanity-check a server address provided by the mount command.
293302
*
@@ -636,10 +645,25 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
636645
ctx->flags &= ~NFS_MOUNT_NOACL;
637646
break;
638647
case Opt_rdirplus:
639-
if (result.negated)
648+
if (result.negated) {
649+
ctx->flags &= ~NFS_MOUNT_FORCE_RDIRPLUS;
640650
ctx->flags |= NFS_MOUNT_NORDIRPLUS;
641-
else
642-
ctx->flags &= ~NFS_MOUNT_NORDIRPLUS;
651+
} else if (!param->string) {
652+
ctx->flags &= ~(NFS_MOUNT_NORDIRPLUS | NFS_MOUNT_FORCE_RDIRPLUS);
653+
} else {
654+
switch (lookup_constant(nfs_rdirplus_tokens, param->string, -1)) {
655+
case Opt_rdirplus_none:
656+
ctx->flags &= ~NFS_MOUNT_FORCE_RDIRPLUS;
657+
ctx->flags |= NFS_MOUNT_NORDIRPLUS;
658+
break;
659+
case Opt_rdirplus_force:
660+
ctx->flags &= ~NFS_MOUNT_NORDIRPLUS;
661+
ctx->flags |= NFS_MOUNT_FORCE_RDIRPLUS;
662+
break;
663+
default:
664+
goto out_invalid_value;
665+
}
666+
}
643667
break;
644668
case Opt_sharecache:
645669
if (result.negated)

fs/nfs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
454454
{ NFS_MOUNT_NONLM, ",nolock", "" },
455455
{ NFS_MOUNT_NOACL, ",noacl", "" },
456456
{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
457+
{ NFS_MOUNT_FORCE_RDIRPLUS, ",rdirplus=force", "" },
457458
{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
458459
{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
459460
{ 0, NULL, NULL }

include/linux/nfs_fs_sb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ struct nfs_server {
167167
#define NFS_MOUNT_TRUNK_DISCOVERY 0x04000000
168168
#define NFS_MOUNT_SHUTDOWN 0x08000000
169169
#define NFS_MOUNT_NO_ALIGNWRITE 0x10000000
170+
#define NFS_MOUNT_FORCE_RDIRPLUS 0x20000000
170171

171172
unsigned int fattr_valid; /* Valid attributes */
172173
unsigned int caps; /* server capabilities */

0 commit comments

Comments
 (0)