[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250507-reftrack-dbgfs-v8-7-607717d3bb98@kernel.org>
Date: Wed, 07 May 2025 09:06:32 -0400
From: Jeff Layton <jlayton@...nel.org>
To: Andrew Morton <akpm@...ux-foundation.org>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Tvrtko Ursulin <tursulin@...ulin.net>
Cc: Kuniyuki Iwashima <kuniyu@...zon.com>, Qasim Ijaz <qasdev00@...il.com>,
Nathan Chancellor <nathan@...nel.org>, Andrew Lunn <andrew@...n.ch>,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
dri-devel@...ts.freedesktop.org, intel-gfx@...ts.freedesktop.org,
Jeff Layton <jlayton@...nel.org>
Subject: [PATCH v8 07/10] ref_tracker: add a way to create a symlink to the
ref_tracker_dir debugfs file
Add the ability for a subsystem to add a user-friendly symlink that
points to a ref_tracker_dir's debugfs file.
Signed-off-by: Jeff Layton <jlayton@...nel.org>
---
include/linux/ref_tracker.h | 13 +++++++++++++
lib/ref_tracker.c | 28 ++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h
index dd289fdda12b1a10197912f5796f97002e785aaf..ddc5a7b2bd84692bbc1e1ae67674ec2c6857e1ec 100644
--- a/include/linux/ref_tracker.h
+++ b/include/linux/ref_tracker.h
@@ -22,6 +22,7 @@ struct ref_tracker_dir {
const char *class; /* object classname */
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
+ struct dentry *symlink;
#endif
char name[32];
#endif
@@ -32,6 +33,7 @@ struct ref_tracker_dir {
#ifdef CONFIG_DEBUG_FS
void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir);
+void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...);
#else /* CONFIG_DEBUG_FS */
@@ -39,6 +41,11 @@ static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
{
}
+static inline __ostream_printf
+void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
+{
+}
+
#endif /* CONFIG_DEBUG_FS */
static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
@@ -56,6 +63,7 @@ static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
dir->class = class;
#ifdef CONFIG_DEBUG_FS
dir->dentry = NULL;
+ dir->symlink = NULL;
#endif
strscpy(dir->name, name, sizeof(dir->name));
ref_tracker_dir_debugfs(dir);
@@ -91,6 +99,11 @@ static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
{
}
+static inline __ostream_printf
+void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
+{
+}
+
static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
{
}
diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index 1df12625d80cc7cff65d9f6be89e1dd5c5ffb7f6..5e84e5fd78e147a036d4adb511e657da07866a55 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -390,8 +390,36 @@ void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
}
EXPORT_SYMBOL(ref_tracker_dir_debugfs);
+void __ostream_printf ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
+{
+ char name[NAME_MAX + 1];
+ va_list args;
+ int ret;
+
+ /* Already created, or dentry doesn't exist? Do nothing */
+ if (!IS_ERR_OR_NULL(dir->symlink) || IS_ERR_OR_NULL(dir->dentry))
+ return;
+
+ va_start(args, fmt);
+ ret = vsnprintf(name, sizeof(name), fmt, args);
+ va_end(args);
+ name[sizeof(name) - 1] = '\0';
+
+ if (ret < sizeof(name))
+ dir->symlink = debugfs_create_symlink(name, ref_tracker_debug_dir,
+ dir->dentry->d_name.name);
+ else
+ dir->symlink = ERR_PTR(-ENAMETOOLONG);
+
+ if (IS_ERR(dir->symlink))
+ pr_warn("ref_tracker: unable to create debugfs symlink for %s: %pe\n",
+ name, dir->symlink);
+}
+EXPORT_SYMBOL(ref_tracker_dir_symlink);
+
static void ref_tracker_debugfs_remove(struct ref_tracker_dir *dir)
{
+ debugfs_remove(dir->symlink);
debugfs_remove(dir->dentry);
}
--
2.49.0
Powered by blists - more mailing lists