From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim <jaegeuk@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Bean Huo <beanhuo@micron.com>, Can Guo <cang@codeaurora.org>,
Asutosh Das <asutoshd@codeaurora.org>
Subject: [PATCH v2 06/10] scsi: ufs: Make it easier to add new debugfs attributes
Date: Wed, 20 Oct 2021 14:40:20 -0700 [thread overview]
Message-ID: <20211020214024.2007615-7-bvanassche@acm.org> (raw)
In-Reply-To: <20211020214024.2007615-1-bvanassche@acm.org>
Introduce an array for debugfs attributes to make it easier to add new
debugfs attributes. Change the value of the inode.i_private pointer for
debugfs attributes from a pointer to the HBA data structure to a pointer
to the attribute description for the stats attribute. Store the HBA
pointer in the private data of the parent inode instead.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/ufs/ufs-debugfs.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/ufs/ufs-debugfs.c b/drivers/scsi/ufs/ufs-debugfs.c
index 4e1ff209b933..1d4e5aa4b762 100644
--- a/drivers/scsi/ufs/ufs-debugfs.c
+++ b/drivers/scsi/ufs/ufs-debugfs.c
@@ -8,6 +8,18 @@
static struct dentry *ufs_debugfs_root;
+struct ufs_debugfs_attr {
+ const char *name;
+ mode_t mode;
+ const struct file_operations *fops;
+};
+
+/* @file corresponds to a debugfs attribute in directory hba->debugfs_root. */
+static inline struct ufs_hba *hba_from_file(const struct file *file)
+{
+ return d_inode(file->f_path.dentry->d_parent)->i_private;
+}
+
void __init ufs_debugfs_init(void)
{
ufs_debugfs_root = debugfs_create_dir("ufshcd", NULL);
@@ -20,7 +32,7 @@ void ufs_debugfs_exit(void)
static int ufs_debugfs_stats_show(struct seq_file *s, void *data)
{
- struct ufs_hba *hba = s->private;
+ struct ufs_hba *hba = hba_from_file(s->file);
struct ufs_event_hist *e = hba->ufs_stats.event;
#define PRT(fmt, typ) \
@@ -126,13 +138,28 @@ static void ufs_debugfs_restart_ee(struct work_struct *work)
ufs_debugfs_put_user_access(hba);
}
+static const struct ufs_debugfs_attr ufs_attrs[] = {
+ { "stats", 0400, &ufs_debugfs_stats_fops },
+ { }
+};
+
void ufs_debugfs_hba_init(struct ufs_hba *hba)
{
+ const struct ufs_debugfs_attr *attr;
+ struct dentry *root;
+
/* Set default exception event rate limit period to 20ms */
hba->debugfs_ee_rate_limit_ms = 20;
INIT_DELAYED_WORK(&hba->debugfs_ee_work, ufs_debugfs_restart_ee);
- hba->debugfs_root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
- debugfs_create_file("stats", 0400, hba->debugfs_root, hba, &ufs_debugfs_stats_fops);
+
+ root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
+ if (IS_ERR_OR_NULL(root))
+ return;
+ hba->debugfs_root = root;
+ d_inode(root)->i_private = hba;
+ for (attr = ufs_attrs; attr->name; attr++)
+ debugfs_create_file(attr->name, attr->mode, root, (void *)attr,
+ attr->fops);
debugfs_create_file("exception_event_mask", 0600, hba->debugfs_root,
hba, &ee_usr_mask_fops);
debugfs_create_u32("exception_event_rate_limit_ms", 0600, hba->debugfs_root,
next prev parent reply other threads:[~2021-10-20 21:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-20 21:40 [PATCH v2 00/10] UFS patches for kernel v5.16 Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 01/10] scsi: ufs: Revert "Retry aborted SCSI commands instead of completing these successfully" Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 02/10] scsi: ufs: Improve source code comments Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 03/10] scsi: ufs: Improve static type checking Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 04/10] scsi: ufs: Log error handler activity Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 05/10] scsi: ufs: Export ufshcd_schedule_eh_work() Bart Van Assche
2021-10-20 21:40 ` Bart Van Assche [this message]
2021-10-20 21:40 ` [PATCH v2 07/10] scsi: ufs: Add debugfs attributes for triggering the UFS EH Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 08/10] scsi: ufs: Remove three superfluous casts Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 09/10] scsi: ufs: Add a compile-time structure size check Bart Van Assche
2021-10-20 21:40 ` [PATCH v2 10/10] scsi: ufs: Micro-optimize ufshcd_map_sg() Bart Van Assche
2021-10-24 7:49 ` [PATCH v2 00/10] UFS patches for kernel v5.16 Avri Altman
2021-10-27 3:25 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211020214024.2007615-7-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=adrian.hunter@intel.com \
--cc=asutoshd@codeaurora.org \
--cc=beanhuo@micron.com \
--cc=cang@codeaurora.org \
--cc=jaegeuk@kernel.org \
--cc=jejb@linux.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox