Skip to content

Commit dde6667

Browse files
bharathsm-mssmfrench
authored andcommitted
smb: client: add drop_dir_cache module parameter to invalidate cached dirents
Add write-only /sys/module/cifs/parameters/drop_dir_cache. Writing a non-zero value iterates all tcons and calls invalidate_all_cached_dirs() to drop cached directory entries. This is useful to force a dirent cache drop across mounts for debugging and testing purpose. Signed-off-by: Bharath SM <bharathsm@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent ac3ad98 commit dde6667

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,44 @@ unsigned int dir_cache_timeout = 30;
121121
module_param(dir_cache_timeout, uint, 0644);
122122
MODULE_PARM_DESC(dir_cache_timeout, "Number of seconds to cache directory contents for which we have a lease. Default: 30 "
123123
"Range: 1 to 65000 seconds, 0 to disable caching dir contents");
124+
125+
/*
126+
* Write-only module parameter to drop all cached directory entries across
127+
* all CIFS mounts. Echo a non-zero value to trigger.
128+
*/
129+
static void cifs_drop_all_dir_caches(void)
130+
{
131+
struct TCP_Server_Info *server;
132+
struct cifs_ses *ses;
133+
struct cifs_tcon *tcon;
134+
135+
spin_lock(&cifs_tcp_ses_lock);
136+
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
137+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
138+
if (cifs_ses_exiting(ses))
139+
continue;
140+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list)
141+
invalidate_all_cached_dirs(tcon);
142+
}
143+
}
144+
spin_unlock(&cifs_tcp_ses_lock);
145+
}
146+
147+
static int cifs_param_set_drop_dir_cache(const char *val, const struct kernel_param *kp)
148+
{
149+
bool bv;
150+
int rc = kstrtobool(val, &bv);
151+
152+
if (rc)
153+
return rc;
154+
if (bv)
155+
cifs_drop_all_dir_caches();
156+
return 0;
157+
}
158+
159+
module_param_call(drop_dir_cache, cifs_param_set_drop_dir_cache, NULL, NULL, 0200);
160+
MODULE_PARM_DESC(drop_dir_cache, "Write 1 to drop all cached directory entries across all CIFS mounts");
161+
124162
#ifdef CONFIG_CIFS_STATS2
125163
unsigned int slow_rsp_threshold = 1;
126164
module_param(slow_rsp_threshold, uint, 0644);

0 commit comments

Comments
 (0)