[PATCH v9 08/30] tracing: Add init callback to trace remotes

Vincent Donnefort
2025-12-02T09:36:40Z

Add a .init call back so the trace remote callers can add entries to the
tracefs directory.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

diff --git a/include/linux/trace_remote.h b/include/linux/trace_remote.h
index 55754ef78104..15a579633123 100644
--- a/include/linux/trace_remote.h
+++ b/include/linux/trace_remote.h
@@ -3,11 +3,14 @@
#ifndef _LINUX_TRACE_REMOTE_H
#define _LINUX_TRACE_REMOTE_H

+#include <linux/dcache.h>
#include <linux/ring_buffer.h>

/**
* struct trace_remote_callbacks - Callbacks used by Tracefs to control the remote
*
+ * @init: Called once the remote has been registered. Allows the
+ * caller to extend the Tracefs remote directory
* @load_trace_buffer: Called before Tracefs accesses the trace buffer for the first
* time. Must return a &trace_buffer_desc
* (most likely filled with trace_remote_alloc_buffer())
@@ -23,6 +26,7 @@
* new reader-page from the @cpu ring-buffer.
*/
struct trace_remote_callbacks {
+ int (*init)(struct dentry *d, void *priv);
struct trace_buffer_desc *(*load_trace_buffer)(unsigned long size, void *priv);
void (*unload_trace_buffer)(struct trace_buffer_desc *desc, void *priv);
int (*enable_tracing)(bool enable, void *priv);
diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
index a744bbf48e88..924e3f3ec6d2 100644
--- a/kernel/trace/trace_remote.c
+++ b/kernel/trace/trace_remote.c
@@ -837,6 +837,7 @@ static int trace_remote_init_tracefs(const char *name, struct trace_remote *remo
int trace_remote_register(const char *name, struct trace_remote_callbacks *cbs, void *priv)
{
struct trace_remote *remote;
+ int ret;

remote = kzalloc(sizeof(*remote), GFP_KERNEL);
if (!remote)
@@ -854,7 +855,11 @@ int trace_remote_register(const char *name, struct trace_remote_callbacks *cbs,
return -ENOMEM;
}

- return 0;
+ ret = cbs->init ? cbs->init(remote->dentry, priv) : 0;
+ if (ret)
+ pr_err("Init failed for trace remote '%s' (%d)\n", name, ret);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(trace_remote_register);