Skip to contentSkip to conversation

Directory lseek doesn't invalidate rdir buffer

DISCUSSION Pierre Barre 1 participant 1 message Dec 2, 2025 9P file system

lore
Share & tools
lore
#0 lore raw

Hi,

It seems that xfstests generic/637 fails on my 9P implementation because lseek() on a directory doesn't invalidate the rdir buffer. After seeking, getdents() returns stale cached entries instead of fetching from the new position.

v9fs_dir_operations_dotl uses generic_file_llseek, which updates f_pos but doesn't clear fid->rdir. Then v9fs_dir_readdir_dotl() only calls p9_client_readdir when rdir->tail == rdir->head, otherwise it returns cached data without checking if ctx->pos changed.

Would a custom v9fs_dir_llseek that clears rdir->head and rdir->tail before calling generic_file_llseek be the right fix?

NFS does the following:

static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence)

	[...]
	if (offset != filp->f_pos) {
		filp->f_pos = offset;
		dir_ctx->page_index = 0;
		if (!nfs_readdir_use_cookie(filp)) {
			dir_ctx->dir_cookie = 0;
			dir_ctx->last_cookie = 0;
		} else {
			dir_ctx->dir_cookie = offset;
			dir_ctx->last_cookie = offset;
		}
		dir_ctx->eof = false;
	}
	spin_unlock(&filp->f_lock);
	return offset;
}

Thanks,
Pierre