From a70b71978ca38fcd839cf708cae288c442c14141 Mon Sep 17 00:00:00 2001 From: Enzo Matsumiya Date: Tue, 8 Jul 2025 15:54:31 -0300 Subject: smb: client: properly invalidate and reuse cached dirents By properly invalidating cache dir entries allows to determine when we must or not do a remote open of the dir, reducing the number of network calls while the cached dir is still valid. Signed-off-by: Enzo Matsumiya --- fs/smb/client/smb2ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'fs/smb/client/smb2ops.c') diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 02543b0d4473..28e79d2da652 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -2339,6 +2339,14 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, struct TCP_Server_Info *server; int retries = 0, cur_sleep = 1; + pr_err("%s: %s first query\n", __func__, (search_flags & CIFS_SEARCH_CACHED_FID) ? "cached" : "remote"); + if (search_flags & CIFS_SEARCH_CACHED_FID) { + srch_inf->entries_in_buffer = 0; + srch_inf->index_of_last_entry = 2; + + return SMB2_query_directory(xid, tcon, fid->persistent_fid, fid->volatile_fid, 0, srch_inf); + } + replay_again: /* reinitialize for possible replay */ flags = 0; @@ -2463,6 +2471,7 @@ smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *fid, __u16 search_flags, struct cifs_search_info *srch_inf) { + pr_err("%s: %s next query\n", __func__, (search_flags & CIFS_SEARCH_CACHED_FID) ? "cached" : "remote"); return SMB2_query_directory(xid, tcon, fid->persistent_fid, fid->volatile_fid, 0, srch_inf); } -- cgit v1.2.3