diff options
| -rw-r--r-- | kernel/trace/ftrace.c | 64 | ||||
| -rw-r--r-- | kernel/trace/trace.h | 9 | ||||
| -rw-r--r-- | kernel/trace/trace_events_filter.c | 20 |
3 files changed, 23 insertions, 70 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index cc615f84751b..ddf23a225b52 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
| @@ -1655,60 +1655,6 @@ ftrace_regex_lseek(struct file *file, loff_t offset, int origin) | |||
| 1655 | return ret; | 1655 | return ret; |
| 1656 | } | 1656 | } |
| 1657 | 1657 | ||
| 1658 | enum { | ||
| 1659 | MATCH_FULL, | ||
| 1660 | MATCH_FRONT_ONLY, | ||
| 1661 | MATCH_MIDDLE_ONLY, | ||
| 1662 | MATCH_END_ONLY, | ||
| 1663 | }; | ||
| 1664 | |||
| 1665 | /* | ||
| 1666 | * (static function - no need for kernel doc) | ||
| 1667 | * | ||
| 1668 | * Pass in a buffer containing a glob and this function will | ||
| 1669 | * set search to point to the search part of the buffer and | ||
| 1670 | * return the type of search it is (see enum above). | ||
| 1671 | * This does modify buff. | ||
| 1672 | * | ||
| 1673 | * Returns enum type. | ||
| 1674 | * search returns the pointer to use for comparison. | ||
| 1675 | * not returns 1 if buff started with a '!' | ||
| 1676 | * 0 otherwise. | ||
| 1677 | */ | ||
| 1678 | static int | ||
| 1679 | ftrace_setup_glob(char *buff, int len, char **search, int *not) | ||
| 1680 | { | ||
| 1681 | int type = MATCH_FULL; | ||
| 1682 | int i; | ||
| 1683 | |||
| 1684 | if (buff[0] == '!') { | ||
| 1685 | *not = 1; | ||
| 1686 | buff++; | ||
| 1687 | len--; | ||
| 1688 | } else | ||
| 1689 | *not = 0; | ||
| 1690 | |||
| 1691 | *search = buff; | ||
| 1692 | |||
| 1693 | for (i = 0; i < len; i++) { | ||
| 1694 | if (buff[i] == '*') { | ||
| 1695 | if (!i) { | ||
| 1696 | *search = buff + 1; | ||
| 1697 | type = MATCH_END_ONLY; | ||
| 1698 | } else { | ||
| 1699 | if (type == MATCH_END_ONLY) | ||
| 1700 | type = MATCH_MIDDLE_ONLY; | ||
| 1701 | else | ||
| 1702 | type = MATCH_FRONT_ONLY; | ||
| 1703 | buff[i] = 0; | ||
| 1704 | break; | ||
| 1705 | } | ||
| 1706 | } | ||
| 1707 | } | ||
| 1708 | |||
| 1709 | return type; | ||
| 1710 | } | ||
| 1711 | |||
| 1712 | static int ftrace_match(char *str, char *regex, int len, int type) | 1658 | static int ftrace_match(char *str, char *regex, int len, int type) |
| 1713 | { | 1659 | { |
| 1714 | int matched = 0; | 1660 | int matched = 0; |
| @@ -1757,7 +1703,7 @@ static void ftrace_match_records(char *buff, int len, int enable) | |||
| 1757 | int not; | 1703 | int not; |
| 1758 | 1704 | ||
| 1759 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; | 1705 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
| 1760 | type = ftrace_setup_glob(buff, len, &search, ¬); | 1706 | type = filter_parse_regex(buff, len, &search, ¬); |
| 1761 | 1707 | ||
| 1762 | search_len = strlen(search); | 1708 | search_len = strlen(search); |
| 1763 | 1709 | ||
| @@ -1825,7 +1771,7 @@ static void ftrace_match_module_records(char *buff, char *mod, int enable) | |||
| 1825 | } | 1771 | } |
| 1826 | 1772 | ||
| 1827 | if (strlen(buff)) { | 1773 | if (strlen(buff)) { |
| 1828 | type = ftrace_setup_glob(buff, strlen(buff), &search, ¬); | 1774 | type = filter_parse_regex(buff, strlen(buff), &search, ¬); |
| 1829 | search_len = strlen(search); | 1775 | search_len = strlen(search); |
| 1830 | } | 1776 | } |
| 1831 | 1777 | ||
| @@ -1990,7 +1936,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
| 1990 | int count = 0; | 1936 | int count = 0; |
| 1991 | char *search; | 1937 | char *search; |
| 1992 | 1938 | ||
| 1993 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); | 1939 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
| 1994 | len = strlen(search); | 1940 | len = strlen(search); |
| 1995 | 1941 | ||
| 1996 | /* we do not support '!' for function probes */ | 1942 | /* we do not support '!' for function probes */ |
| @@ -2067,7 +2013,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | |||
| 2067 | else if (glob) { | 2013 | else if (glob) { |
| 2068 | int not; | 2014 | int not; |
| 2069 | 2015 | ||
| 2070 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); | 2016 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
| 2071 | len = strlen(search); | 2017 | len = strlen(search); |
| 2072 | 2018 | ||
| 2073 | /* we do not support '!' for function probes */ | 2019 | /* we do not support '!' for function probes */ |
| @@ -2520,7 +2466,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer) | |||
| 2520 | return -ENODEV; | 2466 | return -ENODEV; |
| 2521 | 2467 | ||
| 2522 | /* decode regex */ | 2468 | /* decode regex */ |
| 2523 | type = ftrace_setup_glob(buffer, strlen(buffer), &search, ¬); | 2469 | type = filter_parse_regex(buffer, strlen(buffer), &search, ¬); |
| 2524 | if (not) | 2470 | if (not) |
| 2525 | return -EINVAL; | 2471 | return -EINVAL; |
| 2526 | 2472 | ||
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 8d0db6018fe4..db6b83edd49b 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -709,6 +709,13 @@ typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event, | |||
| 709 | 709 | ||
| 710 | typedef int (*regex_match_func)(char *str, struct regex *r, int len); | 710 | typedef int (*regex_match_func)(char *str, struct regex *r, int len); |
| 711 | 711 | ||
| 712 | enum regex_type { | ||
| 713 | MATCH_FULL, | ||
| 714 | MATCH_FRONT_ONLY, | ||
| 715 | MATCH_MIDDLE_ONLY, | ||
| 716 | MATCH_END_ONLY, | ||
| 717 | }; | ||
| 718 | |||
| 712 | struct regex { | 719 | struct regex { |
| 713 | char pattern[MAX_FILTER_STR_VAL]; | 720 | char pattern[MAX_FILTER_STR_VAL]; |
| 714 | int len; | 721 | int len; |
| @@ -727,6 +734,8 @@ struct filter_pred { | |||
| 727 | int pop_n; | 734 | int pop_n; |
| 728 | }; | 735 | }; |
| 729 | 736 | ||
| 737 | extern enum regex_type | ||
| 738 | filter_parse_regex(char *buff, int len, char **search, int *not); | ||
| 730 | extern void print_event_filter(struct ftrace_event_call *call, | 739 | extern void print_event_filter(struct ftrace_event_call *call, |
| 731 | struct trace_seq *s); | 740 | struct trace_seq *s); |
| 732 | extern int apply_event_filter(struct ftrace_event_call *call, | 741 | extern int apply_event_filter(struct ftrace_event_call *call, |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index d3c94c139567..8c194de675b0 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
| @@ -279,15 +279,14 @@ static int regex_match_end(char *str, struct regex *r, int len) | |||
| 279 | return 0; | 279 | return 0; |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | enum regex_type { | 282 | /** |
| 283 | MATCH_FULL, | 283 | * filter_parse_regex - parse a basic regex |
| 284 | MATCH_FRONT_ONLY, | 284 | * @buff: the raw regex |
| 285 | MATCH_MIDDLE_ONLY, | 285 | * @len: length of the regex |
| 286 | MATCH_END_ONLY, | 286 | * @search: will point to the beginning of the string to compare |
| 287 | }; | 287 | * @not: tell whether the match will have to be inverted |
| 288 | 288 | * | |
| 289 | /* | 289 | * This passes in a buffer containing a regex and this function will |
| 290 | * Pass in a buffer containing a regex and this function will | ||
| 291 | * set search to point to the search part of the buffer and | 290 | * set search to point to the search part of the buffer and |
| 292 | * return the type of search it is (see enum above). | 291 | * return the type of search it is (see enum above). |
| 293 | * This does modify buff. | 292 | * This does modify buff. |
| @@ -297,8 +296,7 @@ enum regex_type { | |||
| 297 | * not returns 1 if buff started with a '!' | 296 | * not returns 1 if buff started with a '!' |
| 298 | * 0 otherwise. | 297 | * 0 otherwise. |
| 299 | */ | 298 | */ |
| 300 | static enum regex_type | 299 | enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not) |
| 301 | filter_parse_regex(char *buff, int len, char **search, int *not) | ||
| 302 | { | 300 | { |
| 303 | int type = MATCH_FULL; | 301 | int type = MATCH_FULL; |
| 304 | int i; | 302 | int i; |
