linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Tom Zanussi <zanussi@kernel.org>
Subject: [for-next][PATCH 08/21] tracing: Add trace_get/put_event_file()
Date: Thu, 30 Jan 2020 09:47:51 -0500	[thread overview]
Message-ID: <20200130144811.405011255@goodmis.org> (raw)
In-Reply-To: 20200130144743.527378179@goodmis.org

From: Tom Zanussi <zanussi@kernel.org>

Add a function to get an event file and prevent it from going away on
module or instance removal.

trace_get_event_file() will find an event file in a given instance (if
instance is NULL, it assumes the top trace array) and return it,
pinning the instance's trace array as well as the event's module, if
applicable, so they won't go away while in use.

trace_put_event_file() does the matching release.

Link: http://lkml.kernel.org/r/bb31ac4bdda168d5ed3c4b5f5a4c8f633e8d9118.1580323897.git.zanussi@kernel.org

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
[ Moved trace_array_put() to end of trace_put_event_file() ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 include/linux/trace_events.h |  5 +++
 kernel/trace/trace_events.c  | 85 ++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 20948ee56f8c..8d621a73c97e 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -349,6 +349,11 @@ enum {
 	EVENT_FILE_FL_WAS_ENABLED_BIT,
 };
 
+extern struct trace_event_file *trace_get_event_file(const char *instance,
+						     const char *system,
+						     const char *event);
+extern void trace_put_event_file(struct trace_event_file *file);
+
 /*
  * Event file flags:
  *  ENABLED	  - The event is enabled
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index dfb736a964d6..da62472b1297 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2536,6 +2536,91 @@ find_event_file(struct trace_array *tr, const char *system, const char *event)
 	return file;
 }
 
+/**
+ * trace_get_event_file - Find and return a trace event file
+ * @instance: The name of the trace instance containing the event
+ * @system: The name of the system containing the event
+ * @event: The name of the event
+ *
+ * Return a trace event file given the trace instance name, trace
+ * system, and trace event name.  If the instance name is NULL, it
+ * refers to the top-level trace array.
+ *
+ * This function will look it up and return it if found, after calling
+ * trace_array_get() to prevent the instance from going away, and
+ * increment the event's module refcount to prevent it from being
+ * removed.
+ *
+ * To release the file, call trace_put_event_file(), which will call
+ * trace_array_put() and decrement the event's module refcount.
+ *
+ * Return: The trace event on success, ERR_PTR otherwise.
+ */
+struct trace_event_file *trace_get_event_file(const char *instance,
+					      const char *system,
+					      const char *event)
+{
+	struct trace_array *tr = top_trace_array();
+	struct trace_event_file *file = NULL;
+	int ret = -EINVAL;
+
+	if (instance) {
+		tr = trace_array_find_get(instance);
+		if (!tr)
+			return ERR_PTR(-ENOENT);
+	} else {
+		ret = trace_array_get(tr);
+		if (ret)
+			return ERR_PTR(ret);
+	}
+
+	mutex_lock(&event_mutex);
+
+	file = find_event_file(tr, system, event);
+	if (!file) {
+		trace_array_put(tr);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	/* Don't let event modules unload while in use */
+	ret = try_module_get(file->event_call->mod);
+	if (!ret) {
+		trace_array_put(tr);
+		ret = -EBUSY;
+		goto out;
+	}
+
+	ret = 0;
+ out:
+	mutex_unlock(&event_mutex);
+
+	if (ret)
+		file = ERR_PTR(ret);
+
+	return file;
+}
+EXPORT_SYMBOL_GPL(trace_get_event_file);
+
+/**
+ * trace_put_event_file - Release a file from trace_get_event_file()
+ * @file: The trace event file
+ *
+ * If a file was retrieved using trace_get_event_file(), this should
+ * be called when it's no longer needed.  It will cancel the previous
+ * trace_array_get() called by that function, and decrement the
+ * event's module refcount.
+ */
+void trace_put_event_file(struct trace_event_file *file)
+{
+	mutex_lock(&event_mutex);
+	module_put(file->event_call->mod);
+	mutex_unlock(&event_mutex);
+
+	trace_array_put(file->tr);
+}
+EXPORT_SYMBOL_GPL(trace_put_event_file);
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 
 /* Avoid typos */
-- 
2.24.1



  parent reply	other threads:[~2020-01-30 14:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 14:47 [for-next][PATCH 00/21] tracing: Some more last minute updates for 5.6 Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 01/21] tracing/boot: Include required headers and sort it alphabetically Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 02/21] tracing/boot: Move external function declarations to kernel/trace/trace.h Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 03/21] tracing: Fix sched switch start/stop refcount racy updates Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 04/21] ftrace: fpid_next() should increase position index Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 05/21] tracing: eval_map_next() should always " Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 06/21] trigger_next should " Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 07/21] tracing: Add trace_array_find/_get() to find instance trace arrays Steven Rostedt
2020-01-30 14:47 ` Steven Rostedt [this message]
2020-01-30 14:47 ` [for-next][PATCH 09/21] tracing: Add synth_event_delete() Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 10/21] tracing: Add dynamic event command creation interface Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 11/21] tracing: Add synthetic event command generation functions Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 12/21] tracing: Add synth_event_trace() and related functions Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 13/21] tracing: Add synth event generation test module Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 14/21] tracing: Add kprobe event command generation functions Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 15/21] tracing: Change trace_boot to use kprobe_event interface Steven Rostedt
2020-01-30 14:47 ` [for-next][PATCH 16/21] tracing: Add kprobe event command generation test module Steven Rostedt
2020-01-30 14:48 ` [for-next][PATCH 17/21] tracing: Documentation for in-kernel synthetic event API Steven Rostedt
2020-01-30 14:48 ` [for-next][PATCH 18/21] tracing: Move all function tracing configs together Steven Rostedt
2020-01-30 14:48 ` [for-next][PATCH 19/21] tracing: Move tracing test module " Steven Rostedt
2020-01-30 14:48 ` [for-next][PATCH 20/21] tracing: Move mmio tracer config up with the other tracers Steven Rostedt
2020-01-30 14:48 ` [for-next][PATCH 21/21] tracing: Move tracing selftests to bottom of menu Steven Rostedt

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=20200130144811.405011255@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=zanussi@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;
as well as URLs for NNTP newsgroup(s).