Skip to contentSkip to conversation

NFS: restore directory index when resuming readdir

PATCH New Avi Weiss 1 participant 1 message Oct 19

Subsystems (2)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 NFS: restore directory index when resuming readdir

nfs_readdir() restores the cached folio index and cookie when resuming directory iteration, but leaves current_index at zero. In 32-bit index mode, nfs_readdir_search_for_cookie() then reports a folio-relative offset instead of the absolute entry position.

Restore current_index from the saved logical folio index before searching the cache.

This solution relies on the current behavior of nfs_readdir_seek_next_array(), where folio_index advances by one and current_index advances by nfs_readdir_array_maxentries() for each full, nonterminal folio.

Fixes f648022faa68e ("NFS: Convert readdir page cache to use a cookie based index")

---
I tried a couple other ways of recovering current_index like tracking it with a new variable in nfs_open_dir_context and deriving it from ctx->pos but the first option ended up expanding the change-set drastically and the 2nd option had an issue of freshness after directory changes.

I was able to reproduce both the failure and confirm the fix is valid locally.

 fs/nfs/dir.c | 2 ++
 1 file changed, 2 insertions(+)
fs/nfs/dir.c +2 -0
index 49394123bd09..a1ad04b2f307 100644
@@ -1253,6 +1253,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
 	spin_lock(&file->f_lock);
 	desc->dir_cookie = dir_ctx->dir_cookie;
 	desc->folio_index = dir_ctx->page_index;
+	desc->current_index = (loff_t)desc->folio_index *
+			      nfs_readdir_array_maxentries();
 	desc->last_cookie = dir_ctx->last_cookie;
 	desc->attr_gencount = dir_ctx->attr_gencount;
 	desc->eof = dir_ctx->eof;

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.43.0