linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command
@ 2020-02-25 18:07 Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists Tzvetomir Stoyanov (VMware)
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-02-25 18:07 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The "trace-cmd reset" command is supposed to set the ftrace state to default.
However, some ftrace configurations are not reseted: synthetic events and
error_log file. The command is extended to clean these.
Two new tracefs APIs were also implemented, to check if given ftrace
file / directory exists:
  bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
  bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

[
 v2 changes:
  - Removed these patches from the "SQL-like syntax for ftrace histograms
    configuration" patch set, as they are not directly related to it.
 v3 changes:
  - Remove the warning in case there are no configured synthetic events.
 v4 chanegs:
 - Implemented new tracefs APIs to check if given ftrace file /
   directory exists. Use the new APIs to check if synthetic_events and
   error_log files exist, before accessing them.
]

Tzvetomir Stoyanov (VMware) (4):
  trace-cmd: Add new tracefs APIs for checking if a ftrace file /
    directory exists
  trace-cmd: Unit tests for new libtracefs APIs
  trace-cmd: Clear synthetic events on reset subcommand
  trace-cmd: Clear error log on reset subcommand

 include/tracefs/tracefs.h      |  3 ++
 lib/tracefs/tracefs-instance.c | 49 ++++++++++++++++++++++++++-
 tracecmd/trace-record.c        | 61 ++++++++++++++++++++++++++++++++++
 utest/tracefs-utest.c          | 16 +++++++++
 4 files changed, 128 insertions(+), 1 deletion(-)

-- 
2.24.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists
  2020-02-25 18:07 [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
@ 2020-02-25 18:07 ` Tzvetomir Stoyanov (VMware)
  2020-04-09 18:22   ` Steven Rostedt
  2020-02-25 18:07 ` [PATCH v4 2/4] trace-cmd: Unit tests for new libtracefs APIs Tzvetomir Stoyanov (VMware)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-02-25 18:07 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Some ftrace files and directories are optional, depending on specific kernel configuration or version.
It is a good practice to check if the file / directory exist, before trying to access it. There are a lot of places in trace-cmd implementation with such checks.
The new libtracefs APIs can be used for this, they are ftarce instance aware:
 bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
 bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs/tracefs.h      |  3 +++
 lib/tracefs/tracefs-instance.c | 49 +++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index 85690b66..bc8bebcb 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -33,6 +33,9 @@ int tracefs_instance_file_write(struct tracefs_instance *instance,
 char *tracefs_instance_file_read(struct tracefs_instance *instance,
 				 char *file, int *psize);
 
+bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
+bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
+
 /* events */
 void tracefs_list_free(char **list);
 char **tracefs_event_systems(const char *tracing_dir);
diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
index b96ab61c..67123e7c 100644
--- a/lib/tracefs/tracefs-instance.c
+++ b/lib/tracefs/tracefs-instance.c
@@ -13,7 +13,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-
+#include <linux/limits.h>
 #include "tracefs.h"
 #include "tracefs-local.h"
 
@@ -247,3 +247,50 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance,
 
 	return buf;
 }
+
+static bool check_file_exist(struct tracefs_instance *instance,
+			     char *name, bool dir)
+{
+	char file[PATH_MAX];
+	struct stat st;
+	char *path;
+	int ret;
+
+	path = tracefs_instance_get_dir(instance);
+	snprintf(file, PATH_MAX, "%s/%s", path, name);
+	tracefs_put_tracing_file(path);
+	ret = stat(file, &st);
+	if (ret < 0)
+		return false;
+
+	if (dir && !S_ISDIR(st.st_mode))
+		return false;
+	if (!dir && S_ISDIR(st.st_mode))
+		return false;
+
+	return true;
+}
+
+/**
+ * tracefs_file_exist - Check if a file with given name exists in given instance
+ * @instance: ftrace instance, can be NULL for the top instance
+ * @name: name of the file
+ *
+ * Returns true if the file exists, false otherwise
+ */
+bool tracefs_file_exist(struct tracefs_instance *instance, char *name)
+{
+	return check_file_exist(instance, name, false);
+}
+
+/**
+ * tracefs_dir_exist - Check if a directory with given name exists in given instance
+ * @instance: ftrace instance, can be NULL for the top instance
+ * @name: name of the directory
+ *
+ * Returns true if the directory exists, false otherwise
+ */
+bool tracefs_dir_exist(struct tracefs_instance *instance, char *name)
+{
+	return check_file_exist(instance, name, true);
+}
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/4] trace-cmd: Unit tests for new libtracefs APIs
  2020-02-25 18:07 [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists Tzvetomir Stoyanov (VMware)
@ 2020-02-25 18:07 ` Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 3/4] trace-cmd: Clear synthetic events on reset subcommand Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 4/4] trace-cmd: Clear error log " Tzvetomir Stoyanov (VMware)
  3 siblings, 0 replies; 7+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-02-25 18:07 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Unit tests for tracefs APIs, checking for ftrace file / directory existence:
  bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
  bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 utest/tracefs-utest.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 2473e893..3f57ecad 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -175,6 +175,7 @@ static void test_instance_file_read(struct tracefs_instance *inst, char *fname)
 
 #define ALL_TRACERS	"available_tracers"
 #define CUR_TRACER	"current_tracer"
+#define PER_CPU		"per_cpu"
 static void test_instance_file(void)
 {
 	struct tracefs_instance *instance = NULL;
@@ -251,6 +252,21 @@ static void test_instance_file(void)
 	tracefs_put_tracing_file(inst_file);
 	free(fname);
 
+	CU_TEST(tracefs_file_exist(NULL, (char *)name) == false);
+	CU_TEST(tracefs_dir_exist(NULL, (char *)name) == false);
+	CU_TEST(tracefs_file_exist(instance, (char *)name) == false);
+	CU_TEST(tracefs_dir_exist(instance, (char *)name) == false);
+
+	CU_TEST(tracefs_file_exist(NULL, CUR_TRACER) == true);
+	CU_TEST(tracefs_dir_exist(NULL, CUR_TRACER) == false);
+	CU_TEST(tracefs_file_exist(instance, CUR_TRACER) == true);
+	CU_TEST(tracefs_dir_exist(instance, CUR_TRACER) == false);
+
+	CU_TEST(tracefs_file_exist(NULL, PER_CPU) == false);
+	CU_TEST(tracefs_dir_exist(NULL, PER_CPU) == true);
+	CU_TEST(tracefs_file_exist(instance, PER_CPU) == false);
+	CU_TEST(tracefs_dir_exist(instance, PER_CPU) == true);
+
 	CU_TEST(tracefs_instance_destroy(NULL) != 0);
 	CU_TEST(tracefs_instance_destroy(instance) == 0);
 	CU_TEST(tracefs_instance_destroy(instance) != 0);
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 3/4] trace-cmd: Clear synthetic events on reset subcommand
  2020-02-25 18:07 [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 2/4] trace-cmd: Unit tests for new libtracefs APIs Tzvetomir Stoyanov (VMware)
@ 2020-02-25 18:07 ` Tzvetomir Stoyanov (VMware)
  2020-02-25 18:07 ` [PATCH v4 4/4] trace-cmd: Clear error log " Tzvetomir Stoyanov (VMware)
  3 siblings, 0 replies; 7+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-02-25 18:07 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The "trace-cmd reset" command is supposed to set the ftrace state to default.
However, the synthetic events are not reseted.
A logic is added to delete all entries from "synthetic_events" files.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>

---
v3: remove the warning in case there are no configured synthetic events
v2: remove the patch from "SQL-like syntax for ftrace histograms configuration" patch set
---
 tracecmd/trace-record.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 4a49b640..7c76ffa8 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4638,6 +4638,43 @@ static void clear_triggers(void)
 		clear_instance_triggers(instance);
 }
 
+static void clear_all_synth_events(void)
+{
+	char sevent[BUFSIZ];
+	char *save = NULL;
+	char *line;
+	char *file;
+	char *buf;
+	int len;
+
+	if (!tracefs_file_exist(NULL, "synthetic_events"))
+		return;
+	file = tracefs_instance_get_file(NULL, "synthetic_events");
+	if (!file)
+		return;
+
+	buf = read_file(file);
+	if (!buf)
+		goto out;
+
+	sevent[0] = '!';
+
+	for (line = strtok_r(buf, "\n", &save); line; line = strtok_r(NULL, "\n", &save)) {
+		len = strlen(line);
+		if (len > BUFSIZ - 2)
+			len = BUFSIZ - 2;
+		strncpy(sevent + 1, line, len);
+		sevent[len + 1] = '\0';
+		write_file(file, sevent);
+	}
+out:
+	free(buf);
+	tracefs_put_tracing_file(file);
+
+}
+
+
+
 static void clear_func_filters(void)
 {
 	struct buffer_instance *instance;
@@ -5344,6 +5381,7 @@ void trace_reset(int argc, char **argv)
 	set_buffer_size();
 	clear_filters();
 	clear_triggers();
+	clear_all_synth_events();
 	/* set clock to "local" */
 	reset_clock();
 	reset_event_pid();
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 4/4] trace-cmd: Clear error log on reset subcommand
  2020-02-25 18:07 [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
                   ` (2 preceding siblings ...)
  2020-02-25 18:07 ` [PATCH v4 3/4] trace-cmd: Clear synthetic events on reset subcommand Tzvetomir Stoyanov (VMware)
@ 2020-02-25 18:07 ` Tzvetomir Stoyanov (VMware)
  3 siblings, 0 replies; 7+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-02-25 18:07 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The "trace-cmd reset" command is supposed to set the ftrace state to default.
However, the ftrace error logs are not reseted.
A logic is added to delete the content of "error_log" file when "trace-cmd reset" is executed.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 tracecmd/trace-record.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 7c76ffa8..5c65a26f 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4638,6 +4638,28 @@ static void clear_triggers(void)
 		clear_instance_triggers(instance);
 }
 
+static void clear_instance_error_log(struct buffer_instance *instance)
+{
+	char *file;
+
+	if (!tracefs_file_exist(instance->tracefs, "error_log"))
+		return;
+
+	file = tracefs_instance_get_file(instance->tracefs, "error_log");
+	if (!file)
+		return;
+	write_file(file, " ");
+	tracefs_put_tracing_file(file);
+}
+
+static void clear_error_log(void)
+{
+	struct buffer_instance *instance;
+
+	for_all_instances(instance)
+		clear_instance_error_log(instance);
+}
+
 static void clear_all_synth_events(void)
 {
 	char sevent[BUFSIZ];
@@ -5382,6 +5404,7 @@ void trace_reset(int argc, char **argv)
 	clear_filters();
 	clear_triggers();
 	clear_all_synth_events();
+	clear_error_log();
 	/* set clock to "local" */
 	reset_clock();
 	reset_event_pid();
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists
  2020-02-25 18:07 ` [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists Tzvetomir Stoyanov (VMware)
@ 2020-04-09 18:22   ` Steven Rostedt
  2020-04-13  6:52     ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2020-04-09 18:22 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Tue, 25 Feb 2020 20:07:30 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> Some ftrace files and directories are optional, depending on specific kernel configuration or version.
> It is a good practice to check if the file / directory exist, before trying to access it. There are a lot of places in trace-cmd implementation with such checks.
> The new libtracefs APIs can be used for this, they are ftarce instance aware:
>  bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
>  bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  include/tracefs/tracefs.h      |  3 +++
>  lib/tracefs/tracefs-instance.c | 49 +++++++++++++++++++++++++++++++++-
>  2 files changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
> index 85690b66..bc8bebcb 100644
> --- a/include/tracefs/tracefs.h
> +++ b/include/tracefs/tracefs.h
> @@ -33,6 +33,9 @@ int tracefs_instance_file_write(struct tracefs_instance *instance,
>  char *tracefs_instance_file_read(struct tracefs_instance *instance,
>  				 char *file, int *psize);
>  
> +bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
> +bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
> +
>  /* events */
>  void tracefs_list_free(char **list);
>  char **tracefs_event_systems(const char *tracing_dir);
> diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
> index b96ab61c..67123e7c 100644
> --- a/lib/tracefs/tracefs-instance.c
> +++ b/lib/tracefs/tracefs-instance.c
> @@ -13,7 +13,7 @@
>  #include <errno.h>
>  #include <sys/stat.h>
>  #include <fcntl.h>
> -
> +#include <linux/limits.h>
>  #include "tracefs.h"
>  #include "tracefs-local.h"
>  
> @@ -247,3 +247,50 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance,
>  
>  	return buf;
>  }
> +
> +static bool check_file_exist(struct tracefs_instance *instance,
> +			     char *name, bool dir)
> +{
> +	char file[PATH_MAX];
> +	struct stat st;
> +	char *path;
> +	int ret;
> +
> +	path = tracefs_instance_get_dir(instance);
> +	snprintf(file, PATH_MAX, "%s/%s", path, name);
> +	tracefs_put_tracing_file(path);
> +	ret = stat(file, &st);
> +	if (ret < 0)
> +		return false;
> +
> +	if (dir && !S_ISDIR(st.st_mode))
> +		return false;
> +	if (!dir && S_ISDIR(st.st_mode))
> +		return false;
> +
> +	return true;

BTW, the above can be converted to just:

	return !dir == !S_ISDIR(st.st_mode);


> +}
> +
> +/**
> + * tracefs_file_exist - Check if a file with given name exists in given instance
> + * @instance: ftrace instance, can be NULL for the top instance
> + * @name: name of the file
> + *
> + * Returns true if the file exists, false otherwise

Probably should comment that this will return false if the "file" exists
but is a directory.

Is there any reason we would not want to return true here if it was a
directory? A directory is just another kind of "file" (in the Unix world).

-- Steve

> + */
> +bool tracefs_file_exist(struct tracefs_instance *instance, char *name)
> +{
> +	return check_file_exist(instance, name, false);
> +}
> +
> +/**
> + * tracefs_dir_exist - Check if a directory with given name exists in given instance
> + * @instance: ftrace instance, can be NULL for the top instance
> + * @name: name of the directory
> + *
> + * Returns true if the directory exists, false otherwise
> + */
> +bool tracefs_dir_exist(struct tracefs_instance *instance, char *name)
> +{
> +	return check_file_exist(instance, name, true);
> +}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists
  2020-04-09 18:22   ` Steven Rostedt
@ 2020-04-13  6:52     ` Tzvetomir Stoyanov
  0 siblings, 0 replies; 7+ messages in thread
From: Tzvetomir Stoyanov @ 2020-04-13  6:52 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel

On Thu, Apr 9, 2020 at 9:22 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 25 Feb 2020 20:07:30 +0200
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
>
> > Some ftrace files and directories are optional, depending on specific kernel configuration or version.
> > It is a good practice to check if the file / directory exist, before trying to access it. There are a lot of places in trace-cmd implementation with such checks.
> > The new libtracefs APIs can be used for this, they are ftarce instance aware:
> >  bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
> >  bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
> >
> > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> > ---
> >  include/tracefs/tracefs.h      |  3 +++
> >  lib/tracefs/tracefs-instance.c | 49 +++++++++++++++++++++++++++++++++-
> >  2 files changed, 51 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
> > index 85690b66..bc8bebcb 100644
> > --- a/include/tracefs/tracefs.h
> > +++ b/include/tracefs/tracefs.h
> > @@ -33,6 +33,9 @@ int tracefs_instance_file_write(struct tracefs_instance *instance,
> >  char *tracefs_instance_file_read(struct tracefs_instance *instance,
> >                                char *file, int *psize);
> >
> > +bool tracefs_file_exist(struct tracefs_instance *instance, char *name);
> > +bool tracefs_dir_exist(struct tracefs_instance *instance, char *name);
> > +
> >  /* events */
> >  void tracefs_list_free(char **list);
> >  char **tracefs_event_systems(const char *tracing_dir);
> > diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
> > index b96ab61c..67123e7c 100644
> > --- a/lib/tracefs/tracefs-instance.c
> > +++ b/lib/tracefs/tracefs-instance.c
> > @@ -13,7 +13,7 @@
> >  #include <errno.h>
> >  #include <sys/stat.h>
> >  #include <fcntl.h>
> > -
> > +#include <linux/limits.h>
> >  #include "tracefs.h"
> >  #include "tracefs-local.h"
> >
> > @@ -247,3 +247,50 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance,
> >
> >       return buf;
> >  }
> > +
> > +static bool check_file_exist(struct tracefs_instance *instance,
> > +                          char *name, bool dir)
> > +{
> > +     char file[PATH_MAX];
> > +     struct stat st;
> > +     char *path;
> > +     int ret;
> > +
> > +     path = tracefs_instance_get_dir(instance);
> > +     snprintf(file, PATH_MAX, "%s/%s", path, name);
> > +     tracefs_put_tracing_file(path);
> > +     ret = stat(file, &st);
> > +     if (ret < 0)
> > +             return false;
> > +
> > +     if (dir && !S_ISDIR(st.st_mode))
> > +             return false;
> > +     if (!dir && S_ISDIR(st.st_mode))
> > +             return false;
> > +
> > +     return true;
>
> BTW, the above can be converted to just:
>
>         return !dir == !S_ISDIR(st.st_mode);
>
>
> > +}
> > +
> > +/**
> > + * tracefs_file_exist - Check if a file with given name exists in given instance
> > + * @instance: ftrace instance, can be NULL for the top instance
> > + * @name: name of the file
> > + *
> > + * Returns true if the file exists, false otherwise
>
> Probably should comment that this will return false if the "file" exists
> but is a directory.
>
> Is there any reason we would not want to return true here if it was a
> directory? A directory is just another kind of "file" (in the Unix world).
>

The use case of the API is to check if a given file exists in tracefs, before
writing to / reading from it. If the user expects file, but it is a directory -
the operation will fail. We can think of adding additional input parameter
to the API, to let the user specify the desired behavior of the API ?
Something like :
bool tracefs_file_exist(struct tracefs_instance *instance, char *name,
bool any);


> -- Steve
>
> > + */
> > +bool tracefs_file_exist(struct tracefs_instance *instance, char *name)
> > +{
> > +     return check_file_exist(instance, name, false);
> > +}
> > +
> > +/**
> > + * tracefs_dir_exist - Check if a directory with given name exists in given instance
> > + * @instance: ftrace instance, can be NULL for the top instance
> > + * @name: name of the directory
> > + *
> > + * Returns true if the directory exists, false otherwise
> > + */
> > +bool tracefs_dir_exist(struct tracefs_instance *instance, char *name)
> > +{
> > +     return check_file_exist(instance, name, true);
> > +}
>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-13  6:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-25 18:07 [PATCH v4 0/4] Extend coverage of "trace-cmd reset" command Tzvetomir Stoyanov (VMware)
2020-02-25 18:07 ` [PATCH v4 1/4] trace-cmd: Add new tracefs APIs for checking if a ftrace file / directory exists Tzvetomir Stoyanov (VMware)
2020-04-09 18:22   ` Steven Rostedt
2020-04-13  6:52     ` Tzvetomir Stoyanov
2020-02-25 18:07 ` [PATCH v4 2/4] trace-cmd: Unit tests for new libtracefs APIs Tzvetomir Stoyanov (VMware)
2020-02-25 18:07 ` [PATCH v4 3/4] trace-cmd: Clear synthetic events on reset subcommand Tzvetomir Stoyanov (VMware)
2020-02-25 18:07 ` [PATCH v4 4/4] trace-cmd: Clear error log " Tzvetomir Stoyanov (VMware)

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).