Add support for "full" star globbing patterns in event names and filters
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 15 Feb 2017 16:38:36 +0000 (11:38 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 5 May 2017 15:30:24 +0000 (11:30 -0400)
commit9f449915b9d44ce3c9c9255f5d491a62545fee25
treef371c4e572b850f12c6d11ea35708d49ed27392e
parent9c55c24114a3ba83a423690b0e86d64c9b2fb027
Add support for "full" star globbing patterns in event names and filters

This patch adds the support for "full" star-only globbing patterns to be
used in event names and filter literal strings. A star-only globbing
pattern is a globbing pattern with the star (`*`) being the only special
character. This means `?` and character sets (`[abc-k]`) are not
supported here. We cannot support them without a strategy to
differentiate the globbing pattern because `?` and `[` are not special
characters in event names passed on the command line and filter literal
strings right now. The eventual strategy to support them would probably
look like this for event names:

    lttng enable-event --userspace --glob 'hell?-wo*rl[Ddz]42'

and like this for filter strings:

    filename =* "?sys*.[ch]"

The reason this patch adds the feature for both the event names and the
filter strings at the same time is that, for some agent domains, a
filter string is used to filter the logger name. For example:

    lttng enable-event --python 'hello*world'

In this case, the UST event name is always `lttng_python`, but a filter
string is added to the event rule:

    logger_name == "hello*world"

If I don't add support for filter strings in this patch, then the
globbing feature for event names would not work for all the domains.

src/bin/lttng/commands/enable_events.c
--------------------------------------
The exclusion validation code is cleaner. strutils_split() is used to
split the list (which also supports `\,` to escape delimiters). Then, if
the event name is a globbing pattern which only contains a wildcard star
at the end (the only valid globbing pattern before this patch), the
exclusions which also only contain a wildcard star at the end or no star
at all are validated like it was done previously, with the exception
that escape characters are considered now (that is, in the exclusion
`hello\*world`, `\*` is parsed as is: the star is not a wildcard).

src/bin/lttng-sessiond/cmd.c
----------------------------
The event name validation function is removed because the only thing it
checks is that a star can only appear at the end of the name. This is
not true anymore.

It is expected that the tracers's globbing matching algorithm expect
a globbing pattern without two or more consecutive stars:

    hello**world

Thus in _cmd_enable_event(), strutils_normalize_star_glob_pattern() is
used to "normalize" the star globbing patterns of event names and
exclusion names in place (if they exist). Normalizing here means
crushing consecutive stars as a single one, without considering escaped
stars:

    hello*\***world**** -> hello*\**world*

Note that this also means that the event and exclusion names given by
the user are not necessarily the ones remaining after the enable-event
command is executed. This should not be a problem as `lttng status`
shows the normalized names and normalization is an identity function
when the string is already normalized.

src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c
-----------------------------------------------------
The literal string transformation is modified to include the type of
literal string in the node amongst:

* IR_LOAD_STRING_TYPE_PLAIN
* IR_LOAD_STRING_TYPE_GLOB_STAR_END
* IR_LOAD_STRING_TYPE_GLOB_STAR

This type is used for post-validation and bytecode translation.

src/lib/lttng-ctl/filter/filter-bytecode.h
src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c
-----------------------------------------------------------
A new load bytecode operation is added: FILTER_OP_LOAD_STAR_GLOB_STRING.
When this operation is executed, it should load a string literal as a
full star globbing pattern. The star-at-the-end-only use case is still
expected to be handled by the FILTER_OP_LOAD_STRING operation to avoid
changing anything to the current behaviour.

src/bin/lttng-sessiond/lttng-ust-abi.h
--------------------------------------
Version 7.1 bumped to version 7.2 because a new "load" filter operation
is added to the list of bytecode operations, but the current operation
codes are not changed, so a 7.2 filter interpreter should interpret a
7.1 filter bytecode just fine.

src/common/kernel-ctl/kernel-ioctl.h
------------------------------------
Version 2.2 bumped to version 2.3 because a new "load" filter operation
is added to the list of bytecode operations, but the current operation
codes are not changed, so a 2.3 filter interpreter should interpret a
2.2 filter bytecode just fine.

src/lib/lttng-ctl/filter/filter-visitor-ir-normalize-glob-patterns.c
--------------------------------------------------------------------
This IR visitor normalizes the literal string nodes when their type is
IR_LOAD_STRING_TYPE_GLOB_STAR_END or IR_LOAD_STRING_TYPE_GLOB_STAR.

src/lib/lttng-ctl/filter/filter-visitor-ir-validate-globbing.c
--------------------------------------------------------------
This IR visitor validates that:

1. When there's a binary operation between two literal strings, if one
   of them has the IR_LOAD_STRING_TYPE_GLOB_STAR type, the other one has
   the IR_LOAD_STRING_TYPE_PLAIN type.

   In other words, you cannot compare two globbing patterns, except for
   two globbing patterns with only a star at the end for backward
   compatibility reasons.

2. When there's a binary operation between two literal strings, if one
   of them is a (full) star globbing pattern, the binary operation is
   either == or !=.

src/lib/lttng-ctl/filter/filter-visitor-ir-validate-string.c
------------------------------------------------------------
The code to ensure that a wildcard star can only appear at the end of a
literal string is removed.

src/lib/lttng-ctl/lttng-ctl.c
-----------------------------
New visitors are called.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
14 files changed:
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/cmd.c
src/bin/lttng/Makefile.am
src/bin/lttng/commands/enable_events.c
src/lib/lttng-ctl/filter/Makefile.am
src/lib/lttng-ctl/filter/filter-ast.h
src/lib/lttng-ctl/filter/filter-bytecode.h
src/lib/lttng-ctl/filter/filter-ir.h
src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c
src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c
src/lib/lttng-ctl/filter/filter-visitor-ir-normalize-glob-patterns.c [new file with mode: 0644]
src/lib/lttng-ctl/filter/filter-visitor-ir-validate-globbing.c [new file with mode: 0644]
src/lib/lttng-ctl/filter/filter-visitor-ir-validate-string.c
src/lib/lttng-ctl/lttng-ctl.c
This page took 0.026928 seconds and 4 git commands to generate.