[PATCH][SMB3] Add ftrace support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I plan to add various tracepoints to cifs.ko, but wanted to verify
that the initial patch looks ok (which only adds logging for one
event, write errors), before I start adding various other tracepoints.

Also I need to know ... is the size of log entries a problem? I have
to weight logging just the tree id (and relying on an ioctl or
proc/fs/cifs call to resolve the numeric tree id to a more readable
UNC name ie \\server\share for the mount)?

Generally I want to log these four things
tree id
session id
file id (for everything but open/tree connect/negprot/session setup
where it is not applicable) and/or file name (is logging file name
going to make log entries too big?)
xid (so we can correlate events from one syscall)


>From f190a0c82ce8c95db1c43b7b41115ffc7bb6fb2f Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@xxxxxxxxxxxxx>
Date: Wed, 16 May 2018 16:42:27 -0500
Subject: [PATCH] smb3: Add ftrace tracepoints for improved SMB3 debugging

Although dmesg logs and wireshark network traces can be
helpful, being able to dynamically enable/disable tracepoints
(in this case via the kernel ftrace mechanism) can also be
helpful in more quickly debugging problems, and more
selectively tracing the events related to the bug report.

Add various ftrace tracepoints to cifs.ko for SMB3 events.

Example use:
   trace-cmd record -e cifs
   <run test case>
   trace-cmd show

Various trace events can be filtered. See:
       trace-cmd list | grep cifs
for the current list of cifs tracepoints.

Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
---
 fs/cifs/Makefile  |  7 +++--
 fs/cifs/smb2pdu.c |  6 ++++
 fs/cifs/trace.c   | 18 ++++++++++++
 fs/cifs/trace.h   | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 fs/cifs/trace.c
 create mode 100644 fs/cifs/trace.h

diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index 7e4a1e2f0696..85817991ee68 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -1,11 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0
 #
-# Makefile for Linux CIFS VFS client
+# Makefile for Linux CIFS/SMB2/SMB3 VFS client
 #
+ccflags-y += -I$(src)        # needed for trace events
 obj-$(CONFIG_CIFS) += cifs.o

-cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
-      link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
+cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
+      inode.o link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
       cifs_unicode.o nterr.o cifsencrypt.o \
       readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \
       smb2ops.o smb2maperror.o smb2transport.o \
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 35350057fc23..790d8faf8e1e 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -49,6 +49,7 @@
 #include "cifspdu.h"
 #include "cifs_spnego.h"
 #include "smbdirect.h"
+#include "trace.h"

 /*
  *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -3058,6 +3059,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
                  wdata, flags);

     if (rc) {
+        trace_smb3_write_err(rc, 0 /* no xid */, req->PersistentFileId,
+                     tcon->tid, wdata->offset, wdata->bytes);
         kref_put(&wdata->refcount, release);
         cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
     }
@@ -3124,6 +3127,9 @@ SMB2_write(const unsigned int xid, struct
cifs_io_parms *io_parms,
     rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;

     if (rc) {
+        trace_smb3_write_err(rc, xid, req->PersistentFileId,
+                     io_parms->tcon->tid, io_parms->offset,
+                     io_parms->length);
         cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
         cifs_dbg(VFS, "Send error in write = %d\n", rc);
     } else
diff --git a/fs/cifs/trace.c b/fs/cifs/trace.c
new file mode 100644
index 000000000000..bd4a546feec1
--- /dev/null
+++ b/fs/cifs/trace.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *   Copyright (C) 2018, Microsoft Corporation.
+ *
+ *   Author(s): Steve French <stfrench@xxxxxxxxxxxxx>
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ */
+#define CREATE_TRACE_POINTS
+#include "trace.h"
diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h
new file mode 100644
index 000000000000..1e7b38e2fa15
--- /dev/null
+++ b/fs/cifs/trace.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *   Copyright (C) 2018, Microsoft Corporation.
+ *
+ *   Author(s): Steve French <stfrench@xxxxxxxxxxxxx>
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cifs
+
+#if !defined(_CIFS_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _CIFS_TRACE_H
+
+#include <linux/tracepoint.h>
+
+DECLARE_EVENT_CLASS(smb3_err_class,
+    TP_PROTO(unsigned int xid,
+        __u64    fid,
+        __u32    tid,
+        __u64    offset,
+        __u32    len,
+        int    rc),
+    TP_ARGS(xid, fid, tid, offset, len, rc),
+    TP_STRUCT__entry(
+        __field(unsigned int, xid)
+        __field(__u64, fid)
+        __field(__u32, tid)
+        __field(__u64, offset)
+        __field(__u32, len)
+        __field(int, rc)
+    ),
+    TP_fast_assign(
+        __entry->xid = xid;
+        __entry->fid = fid;
+        __entry->tid = tid;
+        __entry->offset = offset;
+        __entry->len = len;
+        __entry->rc = rc;
+    ),
+    TP_printk("xid=%u fid=%llu tid=%u offset=%llu len=%u rc=%d",
+        __entry->xid, __entry->fid, __entry->tid, __entry->offset,
+        __entry->len, __entry->rc)
+)
+
+#define DEFINE_SMB3_ERR_EVENT(name)             \
+DEFINE_EVENT(smb3_err_class, smb3_##name,       \
+    TP_PROTO(unsigned int xid,        \
+        __u64    fid,            \
+        __u32    tid,            \
+        __u64    offset,            \
+        __u32    len,            \
+        int    rc),            \
+    TP_ARGS(xid, fid, tid, offset, len, rc))
+
+DEFINE_SMB3_ERR_EVENT(write_err);
+
+#endif /* _CIFS_TRACE_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_FILE trace
+#include <trace/define_trace.h>
-- 
2.17.0


-- 
Thanks,

Steve
From f190a0c82ce8c95db1c43b7b41115ffc7bb6fb2f Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@xxxxxxxxxxxxx>
Date: Wed, 16 May 2018 16:42:27 -0500
Subject: [PATCH] smb3: Add ftrace tracepoints for improved SMB3 debugging

Although dmesg errors and wireshark network traces can be
helpful, being able to dynamically enable/disable tracepoints
(in this case via the kernel ftrace mechanism) can also be
helpful in more quickly debugging problems, and more
selectively tracing the events related to the bug report.

Add various ftrace tracepoints to cifs.ko for SMB3 events.

Example use:
   trace-cmd record -e cifs
   <run test case>
   trace-cmd show

Various trace events can be filtered. See:
       trace-cmd list | grep cifs
for the current list of cifs tracepoints.

Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx>
---
 fs/cifs/Makefile  |  7 +++--
 fs/cifs/smb2pdu.c |  6 ++++
 fs/cifs/trace.c   | 18 ++++++++++++
 fs/cifs/trace.h   | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 fs/cifs/trace.c
 create mode 100644 fs/cifs/trace.h

diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index 7e4a1e2f0696..85817991ee68 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -1,11 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0
 #
-# Makefile for Linux CIFS VFS client 
+# Makefile for Linux CIFS/SMB2/SMB3 VFS client
 #
+ccflags-y += -I$(src)		# needed for trace events
 obj-$(CONFIG_CIFS) += cifs.o
 
-cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
-	  link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
+cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
+	  inode.o link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
 	  cifs_unicode.o nterr.o cifsencrypt.o \
 	  readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \
 	  smb2ops.o smb2maperror.o smb2transport.o \
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 35350057fc23..790d8faf8e1e 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -49,6 +49,7 @@
 #include "cifspdu.h"
 #include "cifs_spnego.h"
 #include "smbdirect.h"
+#include "trace.h"
 
 /*
  *  The following table defines the expected "StructureSize" of SMB2 requests
@@ -3058,6 +3059,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
 			     wdata, flags);
 
 	if (rc) {
+		trace_smb3_write_err(rc, 0 /* no xid */, req->PersistentFileId,
+				     tcon->tid, wdata->offset, wdata->bytes);
 		kref_put(&wdata->refcount, release);
 		cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
 	}
@@ -3124,6 +3127,9 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 	rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
 
 	if (rc) {
+		trace_smb3_write_err(rc, xid, req->PersistentFileId,
+				     io_parms->tcon->tid, io_parms->offset,
+				     io_parms->length);
 		cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
 		cifs_dbg(VFS, "Send error in write = %d\n", rc);
 	} else
diff --git a/fs/cifs/trace.c b/fs/cifs/trace.c
new file mode 100644
index 000000000000..bd4a546feec1
--- /dev/null
+++ b/fs/cifs/trace.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *   Copyright (C) 2018, Microsoft Corporation.
+ *
+ *   Author(s): Steve French <stfrench@xxxxxxxxxxxxx>
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ */
+#define CREATE_TRACE_POINTS
+#include "trace.h"
diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h
new file mode 100644
index 000000000000..1e7b38e2fa15
--- /dev/null
+++ b/fs/cifs/trace.h
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *   Copyright (C) 2018, Microsoft Corporation.
+ *
+ *   Author(s): Steve French <stfrench@xxxxxxxxxxxxx>
+ *
+ *   This program is free software;  you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM cifs
+
+#if !defined(_CIFS_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _CIFS_TRACE_H
+
+#include <linux/tracepoint.h>
+
+DECLARE_EVENT_CLASS(smb3_err_class,
+	TP_PROTO(unsigned int xid,
+		__u64	fid,
+		__u32	tid,
+		__u64	offset,
+		__u32	len,
+		int	rc),
+	TP_ARGS(xid, fid, tid, offset, len, rc),
+	TP_STRUCT__entry(
+		__field(unsigned int, xid)
+		__field(__u64, fid)
+		__field(__u32, tid)
+		__field(__u64, offset)
+		__field(__u32, len)
+		__field(int, rc)
+	),
+	TP_fast_assign(
+		__entry->xid = xid;
+		__entry->fid = fid;
+		__entry->tid = tid;
+		__entry->offset = offset;
+		__entry->len = len;
+		__entry->rc = rc;
+	),
+	TP_printk("xid=%u fid=%llu tid=%u offset=%llu len=%u rc=%d",
+		__entry->xid, __entry->fid, __entry->tid, __entry->offset,
+		__entry->len, __entry->rc)
+)
+
+#define DEFINE_SMB3_ERR_EVENT(name)             \
+DEFINE_EVENT(smb3_err_class, smb3_##name,       \
+	TP_PROTO(unsigned int xid,		\
+		__u64	fid,			\
+		__u32	tid,			\
+		__u64	offset,			\
+		__u32	len,			\
+		int	rc),			\
+	TP_ARGS(xid, fid, tid, offset, len, rc))
+
+DEFINE_SMB3_ERR_EVENT(write_err);
+
+#endif /* _CIFS_TRACE_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_FILE trace
+#include <trace/define_trace.h>
-- 
2.17.0


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux