diff mbox series

[v2] scsi: add debugfs directories

Message ID 20190101174352.15237-1-dgilbert@interlog.com (mailing list archive)
State Superseded
Headers show
Series [v2] scsi: add debugfs directories | expand

Commit Message

Douglas Gilbert Jan. 1, 2019, 5:43 p.m. UTC
Add a top level "scsi" directory in debugfs (usually at 
/sys/kernel/debugfs/scsi) with two subdirectories: "uld" and "lld".
The idea is to place mid-level related 'knobs' in the "scsi"
directory, and for the ULDs to make subsirectories like
"scsi/uld/sd" and "scsi/uld/st" as required. LLDs could follow a
similar pattern.

Changes since v1:
  - tweak Makefile to keep kbuild test robot happier

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---

My intention is to add a /sys/kernel/debugfs/scsi/uld/sg
directory containing at least a pseudo file called debug to have
the same actions as /proc/scsi/sg/debug , as part of my v4
patchset.

 drivers/scsi/Makefile       |  2 +-
 drivers/scsi/scsi.c         | 23 +++++++++++++++++++++++
 drivers/scsi/scsi_debugfs.c |  6 ++++++
 drivers/scsi/scsi_debugfs.h |  8 ++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)

Comments

John Garry Jan. 4, 2019, 9:50 a.m. UTC | #1
On 01/01/2019 17:43, Douglas Gilbert wrote:
> Add a top level "scsi" directory in debugfs (usually at
> /sys/kernel/debugfs/scsi) with two subdirectories: "uld" and "lld".
> The idea is to place mid-level related 'knobs' in the "scsi"
> directory, and for the ULDs to make subsirectories like
> "scsi/uld/sd" and "scsi/uld/st" as required. LLDs could follow a
> similar pattern.
>
> Changes since v1:
>   - tweak Makefile to keep kbuild test robot happier
>
> Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
> ---
>
> My intention is to add a /sys/kernel/debugfs/scsi/uld/sg
> directory containing at least a pseudo file called debug to have
> the same actions as /proc/scsi/sg/debug , as part of my v4
> patchset.
>
>  drivers/scsi/Makefile       |  2 +-
>  drivers/scsi/scsi.c         | 23 +++++++++++++++++++++++
>  drivers/scsi/scsi_debugfs.c |  6 ++++++
>  drivers/scsi/scsi_debugfs.h |  8 ++++++++
>  4 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
> index fcb41ae329c4..49835e2e5f2d 100644
> --- a/drivers/scsi/Makefile
> +++ b/drivers/scsi/Makefile
> @@ -163,7 +163,7 @@ scsi_mod-y			+= scsi_scan.o scsi_sysfs.o scsi_devinfo.o
>  scsi_mod-$(CONFIG_SCSI_NETLINK)	+= scsi_netlink.o
>  scsi_mod-$(CONFIG_SYSCTL)	+= scsi_sysctl.o
>  scsi_mod-$(CONFIG_SCSI_PROC_FS)	+= scsi_proc.o
> -scsi_mod-$(CONFIG_BLK_DEBUG_FS)	+= scsi_debugfs.o
> +scsi_mod-$(CONFIG_DEBUG_FS)	+= scsi_debugfs.o
>  scsi_mod-y			+= scsi_trace.o scsi_logging.o
>  scsi_mod-$(CONFIG_PM)		+= scsi_pm.o
>  scsi_mod-$(CONFIG_SCSI_DH)	+= scsi_dh.o
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index fc1356d101b0..01d4d0686699 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -68,6 +68,7 @@
>
>  #include "scsi_priv.h"
>  #include "scsi_logging.h"
> +#include "scsi_debugfs.h"
>
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/scsi.h>
> @@ -812,9 +813,27 @@ static int __init init_scsi(void)
>
>  	scsi_netlink_init();
>
> +#ifdef CONFIG_DEBUG_FS
> +	scsi_debugfs_root = debugfs_create_dir("scsi", NULL);
> +	if (!scsi_debugfs_root)
> +		goto cleanup_netlink;
> +	scsi_debugfs_uld = debugfs_create_dir("uld", scsi_debugfs_root);
> +	if (!scsi_debugfs_uld)
> +		goto cleanup_debugfs;
> +	scsi_debugfs_lld = debugfs_create_dir("lld", scsi_debugfs_root);
> +	if (!scsi_debugfs_lld)
> +		goto cleanup_debugfs;
> +#endif
> +
>  	printk(KERN_NOTICE "SCSI subsystem initialized\n");
>  	return 0;
>
> +#ifdef CONFIG_DEBUG_FS
> +cleanup_debugfs:
> +	debugfs_remove_recursive(scsi_debugfs_root);
> +cleanup_netlink:
> +	scsi_netlink_exit();
> +#endif
>  cleanup_sysctl:
>  	scsi_exit_sysctl();
>  cleanup_hosts:
> @@ -832,6 +851,10 @@ static int __init init_scsi(void)
>
>  static void __exit exit_scsi(void)
>  {
> +
> +#ifdef CONFIG_DEBUG_FS
> +	debugfs_remove_recursive(scsi_debugfs_root);
> +#endif
>  	scsi_netlink_exit();
>  	scsi_sysfs_unregister();
>  	scsi_exit_sysctl();
> diff --git a/drivers/scsi/scsi_debugfs.c b/drivers/scsi/scsi_debugfs.c
> index c5a8756384bc..b06eee3a134e 100644
> --- a/drivers/scsi/scsi_debugfs.c
> +++ b/drivers/scsi/scsi_debugfs.c
> @@ -4,6 +4,12 @@
>  #include <scsi/scsi_dbg.h>
>  #include "scsi_debugfs.h"
>
> +#ifdef CONFIG_DEBUG_FS
> +struct dentry *scsi_debugfs_root;
> +struct dentry *scsi_debugfs_uld;
> +struct dentry *scsi_debugfs_lld;
> +#endif
> +
>  #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name
>  static const char *const scsi_cmd_flags[] = {
>  	SCSI_CMD_FLAG_NAME(TAGGED),
> diff --git a/drivers/scsi/scsi_debugfs.h b/drivers/scsi/scsi_debugfs.h
> index 951b043e82d0..b1a8de6eaf07 100644
> --- a/drivers/scsi/scsi_debugfs.h
> +++ b/drivers/scsi/scsi_debugfs.h
> @@ -1,4 +1,12 @@
> +#include <linux/debugfs.h>
> +
>  struct request;
>  struct seq_file;
>
> +#ifdef CONFIG_DEBUG_FS
> +extern struct dentry *scsi_debugfs_root;
> +extern struct dentry *scsi_debugfs_uld;
> +extern struct dentry *scsi_debugfs_lld;

Hi Doug,

If this is to be used by low-level drivers, should we export this symbol?

Martin just accepted our "[PATCH 0/8] hisi_sas: debugfs support" 
patchset, and we could prob move the root to this lld folder.

Thanks,
John

> +#endif



> +
>  void scsi_show_rq(struct seq_file *m, struct request *rq);
>
diff mbox series

Patch

diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index fcb41ae329c4..49835e2e5f2d 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -163,7 +163,7 @@  scsi_mod-y			+= scsi_scan.o scsi_sysfs.o scsi_devinfo.o
 scsi_mod-$(CONFIG_SCSI_NETLINK)	+= scsi_netlink.o
 scsi_mod-$(CONFIG_SYSCTL)	+= scsi_sysctl.o
 scsi_mod-$(CONFIG_SCSI_PROC_FS)	+= scsi_proc.o
-scsi_mod-$(CONFIG_BLK_DEBUG_FS)	+= scsi_debugfs.o
+scsi_mod-$(CONFIG_DEBUG_FS)	+= scsi_debugfs.o
 scsi_mod-y			+= scsi_trace.o scsi_logging.o
 scsi_mod-$(CONFIG_PM)		+= scsi_pm.o
 scsi_mod-$(CONFIG_SCSI_DH)	+= scsi_dh.o
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index fc1356d101b0..01d4d0686699 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -68,6 +68,7 @@ 
 
 #include "scsi_priv.h"
 #include "scsi_logging.h"
+#include "scsi_debugfs.h"
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/scsi.h>
@@ -812,9 +813,27 @@  static int __init init_scsi(void)
 
 	scsi_netlink_init();
 
+#ifdef CONFIG_DEBUG_FS
+	scsi_debugfs_root = debugfs_create_dir("scsi", NULL);
+	if (!scsi_debugfs_root)
+		goto cleanup_netlink;
+	scsi_debugfs_uld = debugfs_create_dir("uld", scsi_debugfs_root);
+	if (!scsi_debugfs_uld)
+		goto cleanup_debugfs;
+	scsi_debugfs_lld = debugfs_create_dir("lld", scsi_debugfs_root);
+	if (!scsi_debugfs_lld)
+		goto cleanup_debugfs;
+#endif
+
 	printk(KERN_NOTICE "SCSI subsystem initialized\n");
 	return 0;
 
+#ifdef CONFIG_DEBUG_FS
+cleanup_debugfs:
+	debugfs_remove_recursive(scsi_debugfs_root);
+cleanup_netlink:
+	scsi_netlink_exit();
+#endif
 cleanup_sysctl:
 	scsi_exit_sysctl();
 cleanup_hosts:
@@ -832,6 +851,10 @@  static int __init init_scsi(void)
 
 static void __exit exit_scsi(void)
 {
+
+#ifdef CONFIG_DEBUG_FS
+	debugfs_remove_recursive(scsi_debugfs_root);
+#endif
 	scsi_netlink_exit();
 	scsi_sysfs_unregister();
 	scsi_exit_sysctl();
diff --git a/drivers/scsi/scsi_debugfs.c b/drivers/scsi/scsi_debugfs.c
index c5a8756384bc..b06eee3a134e 100644
--- a/drivers/scsi/scsi_debugfs.c
+++ b/drivers/scsi/scsi_debugfs.c
@@ -4,6 +4,12 @@ 
 #include <scsi/scsi_dbg.h>
 #include "scsi_debugfs.h"
 
+#ifdef CONFIG_DEBUG_FS
+struct dentry *scsi_debugfs_root;
+struct dentry *scsi_debugfs_uld;
+struct dentry *scsi_debugfs_lld;
+#endif
+
 #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name
 static const char *const scsi_cmd_flags[] = {
 	SCSI_CMD_FLAG_NAME(TAGGED),
diff --git a/drivers/scsi/scsi_debugfs.h b/drivers/scsi/scsi_debugfs.h
index 951b043e82d0..b1a8de6eaf07 100644
--- a/drivers/scsi/scsi_debugfs.h
+++ b/drivers/scsi/scsi_debugfs.h
@@ -1,4 +1,12 @@ 
+#include <linux/debugfs.h>
+
 struct request;
 struct seq_file;
 
+#ifdef CONFIG_DEBUG_FS
+extern struct dentry *scsi_debugfs_root;
+extern struct dentry *scsi_debugfs_uld;
+extern struct dentry *scsi_debugfs_lld;
+#endif
+
 void scsi_show_rq(struct seq_file *m, struct request *rq);