linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>
Subject: [PATCH 2/4] libtracefs: Allow filter be NULL if RESET flag is set
Date: Tue, 30 Mar 2021 14:33:26 -0400	[thread overview]
Message-ID: <20210330183546.058728551@goodmis.org> (raw)
In-Reply-To: 20210330183324.709017776@goodmis.org

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

If the TRACEFS_FL_RESET flag is set, and the instance has yet to be
opened, the filter parameter can be NULL. This will allow simply resetting
the filter (clearing it).

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-function-filter.txt | 27 ++++++++++++++------
 src/tracefs-tools.c                          | 15 ++++++++---
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/Documentation/libtracefs-function-filter.txt b/Documentation/libtracefs-function-filter.txt
index a022a2196b75..a4218b75deea 100644
--- a/Documentation/libtracefs-function-filter.txt
+++ b/Documentation/libtracefs-function-filter.txt
@@ -37,6 +37,12 @@ not a period, but will match any one character. To force a regular
 expression, either prefix _filter_ with a '^' or append it with a '$' as
 the _filter_ does complete matches of the functions anyway.
 
+The _filter_ may be NULL if a previous call to *tracefs_function_filter()* with
+the same _instance_ had *TRACEFS_FL_CONTINUE* set and this call does not. This is
+useful to simply commit the previous filters. It may also be NULL
+if *TRACEFS_FL_RESET* is set and the previous call did not have the same _instance_
+and *TRACEFS_FL_CONTINUE* set. This is useful to just clear the filter.
+
 FLAGS
 -----
 
@@ -102,20 +108,25 @@ int main(int argc, char *argv[])
 {
 	struct tracefs_instance *inst = tracefs_instance_create(INST);
 	int ret;
-	int reset = TRACEFS_FL_RESET;
 	int i;
 
 	if (!inst) {
 		/* Error creating new trace instance */
 	}
 
+	/* First reset the filter */
+	ret = tracefs_function_filter(inst, NULL, NULL,
+				      TRACEFS_FL_RESET | TRACEFS_FL_CONTINUE);
+	if (ret) {
+		printf("Failed to reset the filter\n");
+		/* Make sure it is closed, -1 means filter was started */
+		if (ret < 0)
+			tracefs_function_filter(inst, NULL, NULL, 0);
+	}
+
 	for (i = 0; filters[i]; i++) {
-		/*
-		 * Only the first call can have TRACEFS_FL_RESET set
-		 * while TRACEFS_FL_CONTINUE is set.
-		 */
 		ret = tracefs_function_filter(inst, filters[i], NULL,
-				      reset | TRACEFS_FL_CONTINUE);
+					      TRACEFS_FL_CONTINUE);
 
 		if (ret) {
 			if (errno == EINVAL)
@@ -123,7 +134,6 @@ int main(int argc, char *argv[])
 			else
 				printf("Failed writing %s\n", filters[i]);
 		}
-		reset = 0;
 	}
 
 	ret = tracefs_function_filter(inst, "*", "ext4", 0);
@@ -133,8 +143,9 @@ int main(int argc, char *argv[])
 		tracefs_function_filter(inst, NULL, NULL, 0);
 	}
 
+ out:
 	tracefs_instance_destroy(inst);
-	return 0;
+	return ret;
 }
 --
 
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 5719ddf66982..a9a51beb02b2 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -794,6 +794,10 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
 			close(*fd);
 			*fd = -1;
 		}
+		/* Also OK to call if reset flag is set */
+		if (reset)
+			goto open_file;
+
 		goto out;
 	}
 
@@ -804,6 +808,7 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
 	if (ret)
 		goto out_free;
 
+ open_file:
 	ret = 1;
 	ftrace_filter_path = tracefs_instance_get_file(instance, TRACE_FILTER);
 	if (!ftrace_filter_path)
@@ -819,9 +824,13 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char *filte
 
 	errno = 0;
 
-	ret = write_func_list(*fd, func_list);
-	if (ret > 0)
-		ret = controlled_write(*fd, &func_filter, module);
+	ret = 0;
+
+	if (filter) {
+		ret = write_func_list(*fd, func_list);
+		if (ret > 0)
+			ret = controlled_write(*fd, &func_filter, module);
+	}
 
 	if (!cont) {
 		close(*fd);
-- 
2.30.1



  parent reply	other threads:[~2021-03-30 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 18:33 [PATCH 0/4] libtracefs: More updates to tracefs_function_filter() Steven Rostedt
2021-03-30 18:33 ` [PATCH 1/4] libtracefs: Only allow RESET flag if file is not already opened Steven Rostedt
2021-03-30 18:33 ` Steven Rostedt [this message]
2021-03-30 18:33 ` [PATCH 3/4] libtracefs: Allow filter to be NULL if module is set in tracefs_function_filter() Steven Rostedt
2021-03-30 18:33 ` [PATCH 4/4] libtracefs: Add TRACEFS_FL_FUTURE flag for future module filtering 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=20210330183546.058728551@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=sameeruddin.shaik8@gmail.com \
    /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).