Re: [PATCH 10/13 v2] libtracefs: Pass in reset via flags to tracefs_function_filter()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 30, 2021 at 3:54 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>
>
> Instead of having a separate boolean to tell tracefs_function_filter() to
> reset the file upon opening, make it a flag instead. This way other
> booleans can be passed into the function without having to extend the
> parameters.
>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
> ---
>  Documentation/libtracefs-function-filter.txt | 26 ++++++++++++++------
>  include/tracefs.h                            | 10 +++++++-
>  src/tracefs-tools.c                          | 19 ++++++++------
>  3 files changed, 38 insertions(+), 17 deletions(-)
>
> diff --git a/Documentation/libtracefs-function-filter.txt b/Documentation/libtracefs-function-filter.txt
> index 88aa3b923d54..5b55a72727c8 100644
> --- a/Documentation/libtracefs-function-filter.txt
> +++ b/Documentation/libtracefs-function-filter.txt
> @@ -11,7 +11,7 @@ SYNOPSIS
>  --
>  *#include <tracefs.h>*
>
> -int *tracefs_function_filter*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]pass:[*]_filters_, const char pass:[*]_module_, bool _reset_, const char pass:[*]pass:[*]pass:[*]_errs_);
> +int *tracefs_function_filter*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]pass:[*]_filters_, const char pass:[*]_module_, int _flags_, const char pass:[*]pass:[*]pass:[*]_errs_);
>  --
>
>  DESCRIPTION
> @@ -25,18 +25,17 @@ _filters_, which is an array of the strings that represent a list of filters tha
>  be applied to define what functions are to be traced and The array must end
>  with a NULL pointer.
>  _module_ , name of the module to be traced (or NULL for all functions),
> -_reset_ if set will clear the current set of filters and then apply the
> -filter list, otherwise the list of filters are added to the current set of
> -filters,
> +_flags_ which holds control knobs on how the filters will be handled (see *FLAGS*)
> +section below,
>  _errs_, is a pointer to an array of strings, which will be allocated if
>  any of filters fail to match any available function, If _errs_ is NULL, it will
>  be ignored.
>
>  A filter in the array of _filters_ may be either a straight match of a
> -function, a glob or regex(3). a glob is where '*' matches zero or more
> +function, a glob or regex(3). a glob is where 'pass:[*]' matches zero or more
>  characters, '?' will match zero or one character, and '.' only matches a
>  period. If the filter is determined to be a regex (where it contains
> -anything other than alpha numeric characters, or '.', '*', '?') the filter
> +anything other than alpha numeric characters, or '.', 'pass:[*]', '?') the filter
>  will be processed as a regex(3) following the rules of regex(3), and '.' is
>  not a period, but will match any one character. To force a regular
>  expression, either prefix the filter with a '^' or append it with a '$' as
> @@ -44,6 +43,17 @@ all filters will act as complete matches of functions anyway.
>
>  returns 0  on success, 1 or -x (where x is an integer) on error.
>
> +FLAGS
> +-----
> +
> +The _flags_ parameter may have the following set, or be zero.
> +
> +*TRACEFS_FL_RESET* :
> +If _flags_ contains *TRACEFS_FL_RESET*, then it will clear the filters that
> +are currently set before applying the list of filters from _filters_. Otherwise,
> +the list of filters from _filters_ will be added to the current set of filters
> +already enabled.
> +
>  RETURN VALUE
>  ------------
>  return 0 on success, if there is error, it will return 1 for general errors or
> @@ -66,7 +76,7 @@ int main(int argc, char *argv[])
>  {
>         struct tracefs_instance *inst = tracefs_instance_create(INST);
>         const char **errs = NULL;
> -       bool reset = 1;
> +       int flags = TRACEFS_FL_RESET;
>         int ret;
>         int i = 0;
>
> @@ -74,7 +84,7 @@ int main(int argc, char *argv[])
>                 /* Error creating new trace instance */
>         }
>
> -       ret = tracefs_function_filter(inst, filters, NULL, reset, &errs);
> +       ret = tracefs_function_filter(inst, filters, NULL, flags, &errs);
>
>         if (ret < 0 && errs) {
>                 while (errs[i])
> diff --git a/include/tracefs.h b/include/tracefs.h
> index 9477fdb14c5a..5193d46f41f5 100644
> --- a/include/tracefs.h
> +++ b/include/tracefs.h
> @@ -145,6 +145,14 @@ bool tracefs_option_is_enabled(struct tracefs_instance *instance, enum tracefs_o
>  int tracefs_option_enable(struct tracefs_instance *instance, enum tracefs_option_id id);
>  int tracefs_option_diasble(struct tracefs_instance *instance, enum tracefs_option_id id);
>  const char *tracefs_option_name(enum tracefs_option_id id);
> +
> +/*
> + * RESET       - Reset on opening filter file (O_TRUNC)
> + */
> +enum {
> +       TRACEFS_FL_RESET        = (1 << 0),
> +};
> +
>  int tracefs_function_filter(struct tracefs_instance *instance, const char **filters,
> -                           const char *module, bool reset, const char ***errs);
> +                           const char *module, unsigned int flags, const char ***errs);
>  #endif /* _TRACE_FS_H */
> diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
> index 8f2130948fe0..6d03b4856a63 100644
> --- a/src/tracefs-tools.c
> +++ b/src/tracefs-tools.c
> @@ -835,7 +835,7 @@ static int write_func_list(int fd, struct func_list *list)
>   * @instance: ftrace instance, can be NULL for top tracing instance
>   * @filters: An array of function names ending with a NULL pointer
>   * @module: Module to be traced
> - * @reset: set to true to reset the file before applying the filter
> + * @flags: flags on modifying the filter file
>   * @errs: A pointer to array of constant strings that will be allocated
>   * on negative return of this function, pointing to the filters that
>   * failed.May be NULL, in which case this field will be ignored.
> @@ -843,9 +843,11 @@ static int write_func_list(int fd, struct func_list *list)
>   * The @filters is an array of strings, where each string will be used
>   * to set a function or functions to be traced.
>   *
> - * If @reset is true, then all functions in the filter are cleared
> - * before adding functions from @filters. Otherwise, the functions set
> - * by @filters will be appended to the filter file
> + * @flags:
> + *   TRACEFS_FL_RESET - will clear the functions in the filter file
> + *          before applying the @filters. This flag is ignored
> + *          if this function is called again when the previous
> + *          call had TRACEFS_FL_CONTINUE set.
>   *
>   * returns -x on filter errors (where x is number of failed filter
>   * srtings) and if @errs is not NULL will be an allocated string array
> @@ -858,12 +860,13 @@ static int write_func_list(int fd, struct func_list *list)
>   * return 0 on success and @errs is not set.
>   */
>  int tracefs_function_filter(struct tracefs_instance *instance, const char **filters,
> -                           const char *module, bool reset, const char ***errs)
> +                           const char *module, unsigned int flags, const char ***errs)
>  {
>         struct func_filter *func_filters;
>         struct func_list *func_list = NULL;
>         char *ftrace_filter_path;
> -       int flags;
> +       bool reset = flags & TRACEFS_FL_RESET;
> +       int open_flags;
>         int ret;
>         int fd;
>
> @@ -887,9 +890,9 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char **filt
>         if (!ftrace_filter_path)
>                 goto out_free;
>
> -       flags = reset ? O_TRUNC : O_APPEND;
> +       open_flags = reset ? O_TRUNC : O_APPEND;
>
> -       fd = open(ftrace_filter_path, O_WRONLY | flags);
> +       fd = open(ftrace_filter_path, O_WRONLY | open_flags);
>         tracefs_put_tracing_file(ftrace_filter_path);
>         if (fd < 0)
>                 goto out_free;
> --
> 2.30.1
>
>

It will be useful to allow calling the API with RESET flag set and no
filters, just to reset the current filters without adding new:
   tracefs_function_filter(NULL, NULL, NULL,TRACEFS_FL_RESET, NULL);
could be a valid call to reset filters in the top trace instance.



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



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux