[PATCH v6 05/24] tracing: Add init callback to trace remotes

Vincent Donnefort
2025-08-21T11:12:04Z

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 1aa99da3c96a..82d26d97a536 100644
--- a/include/linux/trace_remote.h
+++ b/include/linux/trace_remote.h
@@ -3,9 +3,11 @@
#ifndef _LINUX_TRACE_REMOTE_H
#define _LINUX_TRACE_REMOTE_H

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

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);
diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
index 18b2930186cc..8f8eb1f1e889 100644
--- a/kernel/trace/trace_remote.c
+++ b/kernel/trace/trace_remote.c
@@ -482,6 +482,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)
@@ -498,7 +499,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;
}

void trace_remote_free_buffer(struct trace_buffer_desc *desc)
--
2.51.0.rc2.233.g662b1ed5c5-goog