Skip to content

Commit 844e5c0

Browse files
committed
smb3 client: add way to show directory leases for improved debugging
When looking at performance issues around directory caching, or debugging directory lease issues, it is helpful to be able to display the current directory leases (as we can e.g. or open files). Create pseudo-file /proc/fs/cifs/open_dirs that displays current directory leases. Here is sample output: cat /proc/fs/cifs/open_dirs Version:1 Format: <tree id> <sess id> <persistent fid> <path> Num entries: 3 0xce4c1c68 0x7176aa54 0xd95ef58e \dira valid file info, valid dirents 0xce4c1c68 0x7176aa54 0xd031e211 \dir5 valid file info, valid dirents 0xce4c1c68 0x7176aa54 0x96533a90 \dir1 valid file info Reviewed-by: Bharath SM <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 28f0982 commit 844e5c0

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

fs/smb/client/cached_dir.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct cached_dirent {
1414
char *name;
1515
int namelen;
1616
loff_t pos;
17-
1817
struct cifs_fattr fattr;
1918
};
2019

fs/smb/client/cifs_debug.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "smbdirect.h"
2727
#endif
2828
#include "cifs_swn.h"
29+
#include "cached_dir.h"
2930

3031
void
3132
cifs_dump_mem(char *label, void *data, int length)
@@ -280,6 +281,54 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
280281
return 0;
281282
}
282283

284+
static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
285+
{
286+
struct list_head *stmp, *tmp, *tmp1;
287+
struct TCP_Server_Info *server;
288+
struct cifs_ses *ses;
289+
struct cifs_tcon *tcon;
290+
struct cached_fids *cfids;
291+
struct cached_fid *cfid;
292+
LIST_HEAD(entry);
293+
294+
seq_puts(m, "# Version:1\n");
295+
seq_puts(m, "# Format:\n");
296+
seq_puts(m, "# <tree id> <sess id> <persistent fid> <path>\n");
297+
298+
spin_lock(&cifs_tcp_ses_lock);
299+
list_for_each(stmp, &cifs_tcp_ses_list) {
300+
server = list_entry(stmp, struct TCP_Server_Info,
301+
tcp_ses_list);
302+
list_for_each(tmp, &server->smb_ses_list) {
303+
ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
304+
list_for_each(tmp1, &ses->tcon_list) {
305+
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
306+
cfids = tcon->cfids;
307+
spin_lock(&cfids->cfid_list_lock); /* check lock ordering */
308+
seq_printf(m, "Num entries: %d\n", cfids->num_entries);
309+
list_for_each_entry(cfid, &cfids->entries, entry) {
310+
seq_printf(m, "0x%x 0x%llx 0x%llx %s",
311+
tcon->tid,
312+
ses->Suid,
313+
cfid->fid.persistent_fid,
314+
cfid->path);
315+
if (cfid->file_all_info_is_valid)
316+
seq_printf(m, "\tvalid file info");
317+
if (cfid->dirents.is_valid)
318+
seq_printf(m, ", valid dirents");
319+
seq_printf(m, "\n");
320+
}
321+
spin_unlock(&cfids->cfid_list_lock);
322+
323+
324+
}
325+
}
326+
}
327+
spin_unlock(&cifs_tcp_ses_lock);
328+
seq_putc(m, '\n');
329+
return 0;
330+
}
331+
283332
static __always_inline const char *compression_alg_str(__le16 alg)
284333
{
285334
switch (alg) {
@@ -863,6 +912,9 @@ cifs_proc_init(void)
863912
proc_create_single("open_files", 0400, proc_fs_cifs,
864913
cifs_debug_files_proc_show);
865914

915+
proc_create_single("open_dirs", 0400, proc_fs_cifs,
916+
cifs_debug_dirs_proc_show);
917+
866918
proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
867919
proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
868920
proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);
@@ -907,6 +959,7 @@ cifs_proc_clean(void)
907959

908960
remove_proc_entry("DebugData", proc_fs_cifs);
909961
remove_proc_entry("open_files", proc_fs_cifs);
962+
remove_proc_entry("open_dirs", proc_fs_cifs);
910963
remove_proc_entry("cifsFYI", proc_fs_cifs);
911964
remove_proc_entry("traceSMB", proc_fs_cifs);
912965
remove_proc_entry("Stats", proc_fs_cifs);

0 commit comments

Comments
 (0)