Skip to content

Commit 14e7316

Browse files
kinglongmeeamschuma-ntap
authored andcommitted
nfs: fix redundant readdir request after get eof
When a directory contains 17 files (except . and ..), nfs client sends a redundant readdir request after get eof. A simple reproduce, At NFS server, create a directory with 17 files under exported directory. # mkdir test # cd test # for i in {0..16} ; do touch $i; done At NFS client, no matter mounting through nfsv3 or nfsv4, does ls (or ll) at the created test directory. A tshark output likes following (for nfsv4), # tshark -i eth0 tcp port 2049 -Tfields -e ip.src -e ip.dst -e nfs -e nfs.cookie4 srcip dstip SEQUENCE, PUTFH, READDIR 0 dstip srcip SEQUENCE PUTFH READDIR 909539109313539306,2108391201987888856,2305312124304486544,2566335452463141496,2978225129081509984,4263037479923412583,4304697173036510679,4666703455469210097,4759208201298769007,4776701232145978803,5338408478512081262,5949498658935544804,5971526429894832903,6294060338267709855,6528840566229532529,8600463293536422524,9223372036854775807 srcip dstip srcip dstip SEQUENCE, PUTFH, READDIR 9223372036854775807 dstip srcip SEQUENCE PUTFH READDIR The READDIR with cookie 9223372036854775807(0x7FFFFFFFFFFFFFFF) is redundant. Reviewed-by: Benjamin Coddington <[email protected]> Signed-off-by: Kinglong Mee <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 08b45fc commit 14e7316

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

fs/nfs/dir.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,17 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
10891089
for (i = desc->cache_entry_index; i < array->size; i++) {
10901090
struct nfs_cache_array_entry *ent;
10911091

1092+
/*
1093+
* nfs_readdir_handle_cache_misses return force clear at
1094+
* (cache_misses > NFS_READDIR_CACHE_MISS_THRESHOLD) for
1095+
* readdir heuristic, NFS_READDIR_CACHE_MISS_THRESHOLD + 1
1096+
* entries need be emitted here.
1097+
*/
1098+
if (first_emit && i > NFS_READDIR_CACHE_MISS_THRESHOLD + 2) {
1099+
desc->eob = true;
1100+
break;
1101+
}
1102+
10921103
ent = &array->array[i];
10931104
if (!dir_emit(desc->ctx, ent->name, ent->name_len,
10941105
nfs_compat_user_ino64(ent->ino), ent->d_type)) {
@@ -1107,10 +1118,6 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
11071118
desc->ctx->pos = desc->dir_cookie;
11081119
else
11091120
desc->ctx->pos++;
1110-
if (first_emit && i > NFS_READDIR_CACHE_MISS_THRESHOLD + 1) {
1111-
desc->eob = true;
1112-
break;
1113-
}
11141121
}
11151122
if (array->folio_is_eof)
11161123
desc->eof = !desc->eob;

0 commit comments

Comments
 (0)