diff mbox series

smb3: allow more detailed protocol info on open files on the Linux client for debugging

Message ID CAH2r5muD1Qx=mGvw6UHGrs8Kt_2Sq_wx+guTwQLRVmV1LLSExg@mail.gmail.com (mailing list archive)
State New, archived
Headers show
Series smb3: allow more detailed protocol info on open files on the Linux client for debugging | expand

Commit Message

Steve French Oct. 22, 2018, 4:43 a.m. UTC
In order to debug complex problems it is often helpful to
have detailed information on the client and server view
of the open file information.  Add the ability for root to
view the list of smb3 open files and dump the persistent
handle and other info so that it can be more easily
correlated with server logs.

Sample output:
Display debugging information for open files

treeid: 0x8dce084 \\localhost\test
Persistent fid: 0xaddde0a9 name: rofile flags 0x8000 count 1 pid: 7860
uid: 1000 mid 0x30
Persistent fid: 0xd634fe34 name: smallfile flags 0x8000 count 1 pid:
7858 uid: 1000 mid 0x24
Persistent fid: 0xc90bfdc9 name: smallfile flags 0x8000 count 1 pid:
7857 uid: 1000 mid 0x1a

treeid: 0x34b9815b \\localhost\scratch
Persistent fid: 0x86a6e394 name: f71 flags 0x8000 count 1 pid: 7861
uid: 1000 mid 0x20

Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/cifs_debug.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/cifsglob.h   |  3 +++
 fs/cifs/smb2ops.c    |  3 +++
 fs/cifs/smb2pdu.c    |  3 +++
 4 files changed, 59 insertions(+)

         memcpy(buf, &rsp->CreationTime, 32);

Comments

Aurélien Aptel Oct. 22, 2018, 8:57 a.m. UTC | #1
As I said in the other thread I think we should try a different
approach. A new machine-readable proc file + user space tool.
diff mbox series

Patch

From 325054f9f07d842cae41681c53165de878675509 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Sun, 21 Oct 2018 23:36:39 -0500
Subject: [PATCH] smb3: allow more detailed protocol info on open files for
 debugging

In order to debug complex problems it is often helpful to
have detailed information on the client and server view
of the open file information.  Add the ability for root to
view the list of smb3 open files and dump the persistent
handle and other info so that it can be more easily
correlated with server logs.

Sample output:
Display debugging information for open files

treeid: 0x8dce084 \\localhost\test
Persistent fid: 0xaddde0a9 name: rofile flags 0x8000 count 1 pid: 7860 uid: 1000 mid 0x30
Persistent fid: 0xd634fe34 name: smallfile flags 0x8000 count 1 pid: 7858 uid: 1000 mid 0x24
Persistent fid: 0xc90bfdc9 name: smallfile flags 0x8000 count 1 pid: 7857 uid: 1000 mid 0x1a

treeid: 0x34b9815b \\localhost\scratch
Persistent fid: 0x86a6e394 name: f71 flags 0x8000 count 1 pid: 7861 uid: 1000 mid 0x20

Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/cifs_debug.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/cifsglob.h   |  3 +++
 fs/cifs/smb2ops.c    |  3 +++
 fs/cifs/smb2pdu.c    |  3 +++
 4 files changed, 59 insertions(+)

diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 3e812428ac8d..2c76fe38b073 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -145,6 +145,52 @@  cifs_dump_iface(struct seq_file *m, struct cifs_server_iface *iface)
 		seq_printf(m, "\t\tIPv6: %pI6\n", &ipv6->sin6_addr);
 }
 
+static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
+{
+	struct list_head *stmp, *tmp, *tmp1, *tmp2;
+	struct TCP_Server_Info *server;
+	struct cifs_ses *ses;
+	struct cifs_tcon *tcon;
+	struct cifsFileInfo *cfile;
+
+	seq_puts(m, "Display debugging information for open files\n");
+	spin_lock(&cifs_tcp_ses_lock);
+	list_for_each(stmp, &cifs_tcp_ses_list) {
+		server = list_entry(stmp, struct TCP_Server_Info,
+				    tcp_ses_list);
+		list_for_each(tmp, &server->smb_ses_list) {
+			ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
+			list_for_each(tmp1, &ses->tcon_list) {
+				tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
+				seq_printf(m, "\ntreeid: 0x%x %s\n", tcon->tid, tcon->treeName);
+				spin_lock(&tcon->open_file_lock);
+				list_for_each(tmp2, &tcon->openFileList) {
+					cfile = list_entry(tmp2, struct cifsFileInfo,
+						     tlist);
+					seq_printf(m,
+						"Persistent fid: 0x%llx name: %s flags 0x%x count %d pid: %d uid: %d",
+						cfile->fid.persistent_fid,
+						cfile->dentry->d_name.name,
+						cfile->f_flags,
+						cfile->count,
+						cfile->pid,
+						from_kuid(&init_user_ns,
+						cfile->uid));
+#ifdef CONFIG_CIFS_DEBUG2
+					seq_printf(m, " mid 0x%llx\n", cfile->fid.mid);
+#else
+					seq_printf(m, "\n");
+#endif /* CIFS_DEBUG2 */
+				}
+				spin_unlock(&tcon->open_file_lock);
+			}
+		}
+	}
+	spin_unlock(&cifs_tcp_ses_lock);
+	seq_putc(m, '\n');
+	return 0;
+}
+
 static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
 {
 	struct list_head *tmp1, *tmp2, *tmp3;
@@ -565,6 +611,9 @@  cifs_proc_init(void)
 	proc_create_single("DebugData", 0, proc_fs_cifs,
 			cifs_debug_data_proc_show);
 
+	proc_create_single("open_files", 0400, proc_fs_cifs,
+			cifs_debug_files_proc_show);
+
 	proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_fops);
 	proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_fops);
 	proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_fops);
@@ -601,6 +650,7 @@  cifs_proc_clean(void)
 		return;
 
 	remove_proc_entry("DebugData", proc_fs_cifs);
+	remove_proc_entry("open_files", proc_fs_cifs);
 	remove_proc_entry("cifsFYI", proc_fs_cifs);
 	remove_proc_entry("traceSMB", proc_fs_cifs);
 	remove_proc_entry("Stats", proc_fs_cifs);
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index ed1e0fcb69e3..d7c0443d47a4 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1125,6 +1125,9 @@  struct cifs_fid {
 	__u8 create_guid[16];
 	struct cifs_pending_open *pending_open;
 	unsigned int epoch;
+#ifdef CONFIG_CIFS_DEBUG2
+	__u64 mid;
+#endif /* CIFS_DEBUG2 */
 	bool purge_cache;
 };
 
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index f85fc5aa2710..61cfd7028a9e 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -1078,6 +1078,9 @@  smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
 
 	cfile->fid.persistent_fid = fid->persistent_fid;
 	cfile->fid.volatile_fid = fid->volatile_fid;
+#ifdef CONFIG_CIFS_DEBUG2
+	cfile->fid.mid = fid->mid;
+#endif /* CIFS_DEBUG2 */
 	server->ops->set_oplock_level(cinode, oplock, fid->epoch,
 				      &fid->purge_cache);
 	cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 5a08c8f6a322..b83bc3f03a23 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2306,6 +2306,9 @@  SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 	atomic_inc(&tcon->num_remote_opens);
 	oparms->fid->persistent_fid = rsp->PersistentFileId;
 	oparms->fid->volatile_fid = rsp->VolatileFileId;
+#ifdef CONFIG_CIFS_DEBUG2
+	oparms->fid->mid = le64_to_cpu(rsp->sync_hdr.MessageId);
+#endif /* CIFS_DEBUG2 */
 
 	if (buf) {
 		memcpy(buf, &rsp->CreationTime, 32);
-- 
2.17.1