Commit b9df92d2 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt

ftrace: Consolidate the function match routines for normal and mods

The code used for matching functions is almost identical between normal
selecting of functions and using the :mod: feature of set_ftrace_notrace.

Consolidate the two users into one function.
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 491d0dcf
...@@ -1726,34 +1726,52 @@ update_record(struct dyn_ftrace *rec, unsigned long flag, int not) ...@@ -1726,34 +1726,52 @@ update_record(struct dyn_ftrace *rec, unsigned long flag, int not)
} }
static int static int
ftrace_match_record(struct dyn_ftrace *rec, char *regex, int len, int type) ftrace_match_record(struct dyn_ftrace *rec, char *mod,
char *regex, int len, int type)
{ {
char str[KSYM_SYMBOL_LEN]; char str[KSYM_SYMBOL_LEN];
char *modname;
kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
if (mod) {
/* module lookup requires matching the module */
if (!modname || strcmp(modname, mod))
return 0;
/* blank search means to match all funcs in the mod */
if (!len)
return 1;
}
kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
return ftrace_match(str, regex, len, type); return ftrace_match(str, regex, len, type);
} }
static int ftrace_match_records(char *buff, int len, int enable) static int match_records(char *buff, int len, char *mod, int enable, int not)
{ {
unsigned int search_len; unsigned search_len = 0;
struct ftrace_page *pg; struct ftrace_page *pg;
struct dyn_ftrace *rec; struct dyn_ftrace *rec;
int type = MATCH_FULL;
char *search = buff;
unsigned long flag; unsigned long flag;
char *search;
int type;
int not;
int found = 0; int found = 0;
flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; if (len) {
type = filter_parse_regex(buff, len, &search, &not); type = filter_parse_regex(buff, len, &search, &not);
search_len = strlen(search);
}
search_len = strlen(search); flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
mutex_lock(&ftrace_lock); mutex_lock(&ftrace_lock);
if (unlikely(ftrace_disabled))
goto out_unlock;
do_for_each_ftrace_rec(pg, rec) { do_for_each_ftrace_rec(pg, rec) {
if (ftrace_match_record(rec, search, search_len, type)) { if (ftrace_match_record(rec, mod, search, search_len, type)) {
update_record(rec, flag, not); update_record(rec, flag, not);
found = 1; found = 1;
} }
...@@ -1763,43 +1781,23 @@ static int ftrace_match_records(char *buff, int len, int enable) ...@@ -1763,43 +1781,23 @@ static int ftrace_match_records(char *buff, int len, int enable)
*/ */
if (enable && (rec->flags & FTRACE_FL_FILTER)) if (enable && (rec->flags & FTRACE_FL_FILTER))
ftrace_filtered = 1; ftrace_filtered = 1;
} while_for_each_ftrace_rec(); } while_for_each_ftrace_rec();
out_unlock:
mutex_unlock(&ftrace_lock); mutex_unlock(&ftrace_lock);
return found; return found;
} }
static int static int
ftrace_match_module_record(struct dyn_ftrace *rec, char *mod, ftrace_match_records(char *buff, int len, int enable)
char *regex, int len, int type)
{ {
char str[KSYM_SYMBOL_LEN]; return match_records(buff, len, NULL, enable, 0);
char *modname;
kallsyms_lookup(rec->ip, NULL, NULL, &modname, str);
if (!modname || strcmp(modname, mod))
return 0;
/* blank search means to match all funcs in the mod */
if (len)
return ftrace_match(str, regex, len, type);
else
return 1;
} }
static int ftrace_match_module_records(char *buff, char *mod, int enable) static int ftrace_match_module_records(char *buff, char *mod, int enable)
{ {
unsigned search_len = 0;
struct ftrace_page *pg;
struct dyn_ftrace *rec;
int type = MATCH_FULL;
char *search = buff;
unsigned long flag;
int not = 0; int not = 0;
int found = 0;
flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
/* blank or '*' mean the same */ /* blank or '*' mean the same */
if (strcmp(buff, "*") == 0) if (strcmp(buff, "*") == 0)
...@@ -1811,31 +1809,7 @@ static int ftrace_match_module_records(char *buff, char *mod, int enable) ...@@ -1811,31 +1809,7 @@ static int ftrace_match_module_records(char *buff, char *mod, int enable)
not = 1; not = 1;
} }
if (strlen(buff)) { return match_records(buff, strlen(buff), mod, enable, not);
type = filter_parse_regex(buff, strlen(buff), &search, &not);
search_len = strlen(search);
}
mutex_lock(&ftrace_lock);
if (unlikely(ftrace_disabled))
goto out_unlock;
do_for_each_ftrace_rec(pg, rec) {
if (ftrace_match_module_record(rec, mod,
search, search_len, type)) {
update_record(rec, flag, not);
found = 1;
}
if (enable && (rec->flags & FTRACE_FL_FILTER))
ftrace_filtered = 1;
} while_for_each_ftrace_rec();
out_unlock:
mutex_unlock(&ftrace_lock);
return found;
} }
/* /*
...@@ -1993,7 +1967,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, ...@@ -1993,7 +1967,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
do_for_each_ftrace_rec(pg, rec) { do_for_each_ftrace_rec(pg, rec) {
if (!ftrace_match_record(rec, search, len, type)) if (!ftrace_match_record(rec, NULL, search, len, type))
continue; continue;
entry = kmalloc(sizeof(*entry), GFP_KERNEL); entry = kmalloc(sizeof(*entry), GFP_KERNEL);
...@@ -2548,7 +2522,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer) ...@@ -2548,7 +2522,7 @@ ftrace_set_func(unsigned long *array, int *idx, char *buffer)
if (rec->flags & FTRACE_FL_FREE) if (rec->flags & FTRACE_FL_FREE)
continue; continue;
if (ftrace_match_record(rec, search, search_len, type)) { if (ftrace_match_record(rec, NULL, search, search_len, type)) {
/* if it is in the array */ /* if it is in the array */
exists = false; exists = false;
for (i = 0; i < *idx; i++) { for (i = 0; i < *idx; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment