mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lei Chen <lei.chen@smartx.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lei Chen <lei.chen@smartx.com>
Subject: [PATCH v2 3/5] block: add helpers to link tag set debugfs to controllers
Date: Fri, 20 Nov 2026 10:56:02 +0800	[thread overview]
Message-ID: <d943e20493c4fd50fee90575645a1f18a81450f4.1795143228.git.lei.chen@smartx.com> (raw)
In-Reply-To: <cover.1795143228.git.lei.chen@smartx.com>

A tag set's debugfs directory identifies its attached request queues,
but does not identify the controller that owns it. Drivers with an
existing controller debugfs directory can expose this relationship
without duplicating the controller's debug information.

Add blk_mq_tagset_debugfs_link_controller() and
blk_mq_tagset_debugfs_unlink_controller() for drivers to manage a
controller symlink in the tag set directory. Build a relative target
from the controller dentry so the link stays within debugfs and does
not depend on the mount point.

Serialize link updates with tag set debugfs registration and removal,
and use the existing NOIO scope for allocations. Callers must keep both
objects alive and remove the link before deleting the controller
directory. Provide stubs when CONFIG_BLK_DEBUG_FS is disabled.

Signed-off-by: Lei Chen <lei.chen@smartx.com>
---
 block/blk-mq-debugfs.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/blk-mq.h | 16 +++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index 72634277e088..1a1364a34c0a 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -7,6 +7,7 @@
 #include <linux/blkdev.h>
 #include <linux/build_bug.h>
 #include <linux/debugfs.h>
+#include <linux/dcache.h>
 #include <linux/idr.h>
 
 #include "blk.h"
@@ -860,6 +861,59 @@ static void blk_mq_tagset_debugfs_unlock(unsigned int memflags)
 	memalloc_noio_restore(memflags);
 }
 
+/**
+ * blk_mq_tagset_debugfs_link_controller - link a tag set to its controller
+ * @set: allocated tag set
+ * @controller: controller debugfs directory
+ *
+ * The caller must keep both objects alive during this call and remove the
+ * link before deleting the controller directory. No dentry reference is kept.
+ */
+void blk_mq_tagset_debugfs_link_controller(struct blk_mq_tag_set *set,
+						struct dentry *controller)
+{
+	unsigned int memflags;
+	char *buf, *path, *target;
+
+	if (IS_ERR(controller))
+		return;
+
+	memflags = blk_mq_tagset_debugfs_lock();
+	if (IS_ERR_OR_NULL(set->debugfs_dir))
+		goto out_unlock;
+
+	buf = kmalloc(PATH_MAX, GFP_KERNEL);
+	if (!buf)
+		goto out_unlock;
+	path = dentry_path_raw(controller, buf, PATH_MAX);
+	if (IS_ERR(path))
+		goto out_free;
+
+	/* The tag set lives two levels below the debugfs root. */
+	target = kasprintf(GFP_KERNEL, "../..%s", path);
+	if (!target)
+		goto out_free;
+	debugfs_lookup_and_remove("controller", set->debugfs_dir);
+	debugfs_create_symlink("controller", set->debugfs_dir, target);
+	kfree(target);
+out_free:
+	kfree(buf);
+out_unlock:
+	blk_mq_tagset_debugfs_unlock(memflags);
+}
+EXPORT_SYMBOL_GPL(blk_mq_tagset_debugfs_link_controller);
+
+void blk_mq_tagset_debugfs_unlink_controller(struct blk_mq_tag_set *set)
+{
+	unsigned int memflags;
+
+	memflags = blk_mq_tagset_debugfs_lock();
+	if (!IS_ERR_OR_NULL(set->debugfs_dir))
+		debugfs_lookup_and_remove("controller", set->debugfs_dir);
+	blk_mq_tagset_debugfs_unlock(memflags);
+}
+EXPORT_SYMBOL_GPL(blk_mq_tagset_debugfs_unlink_controller);
+
 #define BLK_MQ_F_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
 static const char *const tagset_flag_name[] = {
 	BLK_MQ_F_NAME(TAG_QUEUE_SHARED),
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 882ed11e7c2b..d98ec1dc1130 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -564,6 +564,22 @@ struct blk_mq_tag_set {
 #endif
 };
 
+#ifdef CONFIG_BLK_DEBUG_FS
+void blk_mq_tagset_debugfs_link_controller(struct blk_mq_tag_set *set,
+						struct dentry *controller);
+void blk_mq_tagset_debugfs_unlink_controller(struct blk_mq_tag_set *set);
+#else
+static inline void blk_mq_tagset_debugfs_link_controller(
+		struct blk_mq_tag_set *set, struct dentry *controller)
+{
+}
+
+static inline void
+blk_mq_tagset_debugfs_unlink_controller(struct blk_mq_tag_set *set)
+{
+}
+#endif
+
 /**
  * struct blk_mq_queue_data - Data about a request inserted in a queue
  *
-- 
2.43.0


  parent reply	other threads:[~2026-11-20  2:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  3:01 [PATCH v1 0/4] Expose blk-mq tag sets through debugfs Lei Chen
2026-10-09  3:01 ` [PATCH v1 1/4] blk-mq: remove stale comment about non-present CPU mapping Lei Chen
2026-10-09  3:01 ` [PATCH v1 2/4] blk-mq: manage driver tags at the tag set level Lei Chen
2026-10-09  3:01 ` [PATCH v1 3/4] block: expose blk-mq tag sets through debugfs Lei Chen
2026-10-09  3:01 ` [PATCH v1 4/4] block: link request queue debugfs directories to tag sets Lei Chen
2026-11-03  9:04 ` [PATCH v1 0/4] Expose blk-mq tag sets through debugfs Lei Chen
2026-11-20  2:55 ` [PATCH v2 0/5] " Lei Chen
2026-11-20  2:56   ` [PATCH v2 1/5] block: expose " Lei Chen
2026-11-20  2:56   ` [PATCH v2 2/5] block: link request queue debugfs directories to tag sets Lei Chen
2026-11-20  2:56   ` Lei Chen [this message]
2026-11-20  2:56   ` [PATCH v2 4/5] scsi: megaraid_sas: Link tag set debugfs to the controller Lei Chen
2026-11-20  2:56   ` [PATCH v2 5/5] scsi: mpt3sas: " Lei Chen
2026-11-20  2:58 ` [RESEND PATCH v1 0/4] Expose blk-mq tag sets through debugfs Lei Chen
2026-11-20  2:58   ` [RESEND PATCH v1 1/4] blk-mq: remove stale comment about non-present CPU mapping Lei Chen
2026-11-20  2:58   ` [RESEND PATCH v1 2/4] blk-mq: manage driver tags at the tag set level Lei Chen
2026-11-20  2:58   ` [RESEND PATCH v1 3/4] block: expose blk-mq tag sets through debugfs Lei Chen
2026-11-20  2:58   ` [RESEND PATCH v1 4/4] block: link request queue debugfs directories to tag sets Lei Chen

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=d943e20493c4fd50fee90575645a1f18a81450f4.1795143228.git.lei.chen@smartx.com \
    --to=lei.chen@smartx.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®