From patchwork Tue Jan 8 04:00:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Gilbert X-Patchwork-Id: 10751379 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4519013B4 for ; Tue, 8 Jan 2019 04:00:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3397628A4C for ; Tue, 8 Jan 2019 04:00:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 279F228B1E; Tue, 8 Jan 2019 04:00:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A89EB28A4C for ; Tue, 8 Jan 2019 04:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727283AbfAHEAk (ORCPT ); Mon, 7 Jan 2019 23:00:40 -0500 Received: from smtp.infotech.no ([82.134.31.41]:48043 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727145AbfAHEAk (ORCPT ); Mon, 7 Jan 2019 23:00:40 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 142F6204248; Tue, 8 Jan 2019 05:00:38 +0100 (CET) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qNxb3THaVUmq; Tue, 8 Jan 2019 05:00:36 +0100 (CET) Received: from xtwo70.bingwo.ca (host-184-164-16-103.dyn.295.ca [184.164.16.103]) by smtp.infotech.no (Postfix) with ESMTPA id 63C75204190; Tue, 8 Jan 2019 05:00:35 +0100 (CET) From: Douglas Gilbert To: linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com, hare@suse.de, john.garry@huawei.com Subject: [PATCH v5] scsi: add debugfs directories Date: Mon, 7 Jan 2019 23:00:34 -0500 Message-Id: <20190108040034.14380-1-dgilbert@interlog.com> X-Mailer: git-send-email 2.17.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a top level "scsi" directory in debugfs (usually at /sys/kernel/debug/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 subdirectories like "scsi/uld/sd" and "scsi/uld/st" as required. LLDs could follow a similar pattern. Changes since v4: - remove export for /sys/kernel/debug/scsi directory but leave the exports for the uld and lld subdirectories - put externs for scsi_debugfs_uld and scsi_debugfs_lld in include/scsi/scsi_dbg.h . So ULDs and LLDs now need to include to use this facility - clean-up whitespaces and redundant code [John Garry] Changes since v3: - re-arrange as per scsi netlink interface [James Bottomley] - make all debugfs code conditional on CONFIG_BLK_DEBUG_FS Changes since v2: - export symbols so other driver can use them [John Garry] - make prior code conditional on CONFIG_BLK_DEBUG_FS Changes since v1: - tweak Makefile to keep kbuild test robot happier Signed-off-by: Douglas Gilbert Reviewed-by: John Garry --- My intention is to add a /sys/kernel/debug/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 sg v4 patchset. John Garry has indicated that he is prepared to modify debugfs patches to the hisi_sas driver to use the proposed /sys/kernel/debug/scsi/lld directory. drivers/scsi/scsi.c | 3 +++ drivers/scsi/scsi_debugfs.c | 32 +++++++++++++++++++++++++++++++- drivers/scsi/scsi_priv.h | 12 ++++++++++++ include/scsi/scsi_dbg.h | 5 +++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index fc1356d101b0..e8676a19ba6e 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -812,6 +812,8 @@ static int __init init_scsi(void) scsi_netlink_init(); + scsi_debugfs_init(); + printk(KERN_NOTICE "SCSI subsystem initialized\n"); return 0; @@ -832,6 +834,7 @@ static int __init init_scsi(void) static void __exit exit_scsi(void) { + scsi_debugfs_exit(); 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..5b0c001c150f 100644 --- a/drivers/scsi/scsi_debugfs.c +++ b/drivers/scsi/scsi_debugfs.c @@ -1,8 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include -#include "scsi_debugfs.h" +#include "scsi_priv.h" + +struct dentry *scsi_debugfs_root; + +struct dentry *scsi_debugfs_uld; +EXPORT_SYMBOL(scsi_debugfs_uld); + +struct dentry *scsi_debugfs_lld; +EXPORT_SYMBOL(scsi_debugfs_lld); + #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name static const char *const scsi_cmd_flags[] = { @@ -50,3 +60,23 @@ void scsi_show_rq(struct seq_file *m, struct request *rq) timeout_ms / 1000, timeout_ms % 1000, alloc_ms / 1000, alloc_ms % 1000); } + +void scsi_debugfs_init(void) +{ + scsi_debugfs_root = debugfs_create_dir("scsi", NULL); + if (!scsi_debugfs_root) + return; + scsi_debugfs_uld = debugfs_create_dir("uld", scsi_debugfs_root); + if (!scsi_debugfs_uld) { + scsi_debugfs_exit(); + return; + } + scsi_debugfs_lld = debugfs_create_dir("lld", scsi_debugfs_root); + if (!scsi_debugfs_lld) + scsi_debugfs_exit(); +} + +void scsi_debugfs_exit(void) +{ + debugfs_remove_recursive(scsi_debugfs_root); +} diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 99f1db5e467e..e24835e8fa4f 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -160,6 +160,18 @@ static inline void scsi_netlink_init(void) {} static inline void scsi_netlink_exit(void) {} #endif +/* scsi_debugfs.c */ +#ifdef CONFIG_BLK_DEBUG_FS +extern void scsi_debugfs_init(void); +extern void scsi_debugfs_exit(void); +extern struct dentry *scsi_debugfs_root; +extern struct dentry *scsi_debugfs_uld; +extern struct dentry *scsi_debugfs_lld; +#else +static inline void scsi_debugfs_init(void) {} +static inline void scsi_debugfs_exit(void) {} +#endif + /* scsi_pm.c */ #ifdef CONFIG_PM extern const struct dev_pm_ops scsi_bus_pm_ops; diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h index e03bd9d41fa8..00d121bf5eb2 100644 --- a/include/scsi/scsi_dbg.h +++ b/include/scsi/scsi_dbg.h @@ -2,6 +2,11 @@ #ifndef _SCSI_SCSI_DBG_H #define _SCSI_SCSI_DBG_H +#ifdef CONFIG_BLK_DEBUG_FS +extern struct dentry *scsi_debugfs_uld; +extern struct dentry *scsi_debugfs_lld; +#endif + struct scsi_cmnd; struct scsi_device; struct scsi_sense_hdr;