/* return 1 if event matches, 0 otherwise (discard) */
int filter_match_preds(struct ftrace_event_call *call, void *rec)
{
+ struct event_filter *filter = call->filter;
int i, matched, and_failed = 0;
struct filter_pred *pred;
- for (i = 0; i < call->n_preds; i++) {
- pred = call->preds[i];
+ for (i = 0; i < filter->n_preds; i++) {
+ pred = filter->preds[i];
if (and_failed && !pred->or)
continue;
matched = pred->fn(pred, rec);
}
EXPORT_SYMBOL_GPL(filter_match_preds);
-static void __filter_print_preds(struct filter_pred **preds, int n_preds,
+static void __filter_print_preds(struct event_filter *filter,
struct trace_seq *s)
{
- char *field_name;
struct filter_pred *pred;
+ char *field_name;
int i;
- if (!n_preds) {
+ if (!filter || !filter->n_preds) {
trace_seq_printf(s, "none\n");
return;
}
- for (i = 0; i < n_preds; i++) {
- pred = preds[i];
+ for (i = 0; i < filter->n_preds; i++) {
+ pred = filter->preds[i];
field_name = pred->field_name;
if (i)
trace_seq_printf(s, pred->or ? "|| " : "&& ");
void filter_print_preds(struct ftrace_event_call *call, struct trace_seq *s)
{
mutex_lock(&filter_mutex);
- __filter_print_preds(call->preds, call->n_preds, s);
+ __filter_print_preds(call->filter, s);
mutex_unlock(&filter_mutex);
}
struct trace_seq *s)
{
mutex_lock(&filter_mutex);
- __filter_print_preds(system->preds, system->n_preds, s);
+ __filter_print_preds(system->filter, s);
mutex_unlock(&filter_mutex);
}
static void __filter_disable_preds(struct ftrace_event_call *call)
{
+ struct event_filter *filter = call->filter;
int i;
- call->n_preds = 0;
+ call->filter_active = 0;
+ filter->n_preds = 0;
for (i = 0; i < MAX_FILTER_PRED; i++)
- call->preds[i]->fn = filter_pred_none;
+ filter->preds[i]->fn = filter_pred_none;
}
void filter_disable_preds(struct ftrace_event_call *call)
int init_preds(struct ftrace_event_call *call)
{
+ struct event_filter *filter;
struct filter_pred *pred;
int i;
- call->n_preds = 0;
-
- call->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), GFP_KERNEL);
- if (!call->preds)
+ filter = call->filter = kzalloc(sizeof(*filter), GFP_KERNEL);
+ if (!call->filter)
return -ENOMEM;
+ call->filter_active = 0;
+ filter->n_preds = 0;
+
+ filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred), GFP_KERNEL);
+ if (!filter->preds)
+ goto oom;
+
for (i = 0; i < MAX_FILTER_PRED; i++) {
pred = kzalloc(sizeof(*pred), GFP_KERNEL);
if (!pred)
goto oom;
pred->fn = filter_pred_none;
- call->preds[i] = pred;
+ filter->preds[i] = pred;
}
return 0;
oom:
for (i = 0; i < MAX_FILTER_PRED; i++) {
- if (call->preds[i])
- filter_free_pred(call->preds[i]);
+ if (filter->preds[i])
+ filter_free_pred(filter->preds[i]);
}
- kfree(call->preds);
- call->preds = NULL;
+ kfree(filter->preds);
+ kfree(call->filter);
+ call->filter = NULL;
return -ENOMEM;
}
static void __filter_free_subsystem_preds(struct event_subsystem *system)
{
+ struct event_filter *filter = system->filter;
struct ftrace_event_call *call;
int i;
- if (system->n_preds) {
- for (i = 0; i < system->n_preds; i++)
- filter_free_pred(system->preds[i]);
- kfree(system->preds);
- system->preds = NULL;
- system->n_preds = 0;
+ if (filter && filter->n_preds) {
+ for (i = 0; i < filter->n_preds; i++)
+ filter_free_pred(filter->preds[i]);
+ kfree(filter->preds);
+ kfree(filter);
+ system->filter = NULL;
}
list_for_each_entry(call, &ftrace_events, list) {
struct filter_pred *pred,
filter_pred_fn_t fn)
{
+ struct event_filter *filter = call->filter;
int idx, err;
- if (call->n_preds && !pred->compound)
+ if (filter->n_preds && !pred->compound)
__filter_disable_preds(call);
- if (call->n_preds == MAX_FILTER_PRED)
+ if (filter->n_preds == MAX_FILTER_PRED)
return -ENOSPC;
- idx = call->n_preds;
- filter_clear_pred(call->preds[idx]);
- err = filter_set_pred(call->preds[idx], pred, fn);
+ idx = filter->n_preds;
+ filter_clear_pred(filter->preds[idx]);
+ err = filter_set_pred(filter->preds[idx], pred, fn);
if (err)
return err;
- call->n_preds++;
+ filter->n_preds++;
+ call->filter_active = 1;
return 0;
}
int filter_add_subsystem_pred(struct event_subsystem *system,
struct filter_pred *pred)
{
+ struct event_filter *filter = system->filter;
struct ftrace_event_call *call;
mutex_lock(&filter_mutex);
- if (system->n_preds && !pred->compound)
+ if (filter && filter->n_preds && !pred->compound) {
__filter_free_subsystem_preds(system);
+ filter = NULL;
+ }
- if (!system->n_preds) {
- system->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred),
+ if (!filter) {
+ system->filter = kzalloc(sizeof(*filter), GFP_KERNEL);
+ if (!system->filter) {
+ mutex_unlock(&filter_mutex);
+ return -ENOMEM;
+ }
+ filter = system->filter;
+ filter->preds = kzalloc(MAX_FILTER_PRED * sizeof(pred),
GFP_KERNEL);
- if (!system->preds) {
+
+ if (!filter->preds) {
+ kfree(system->filter);
+ system->filter = NULL;
mutex_unlock(&filter_mutex);
return -ENOMEM;
}
}
- if (system->n_preds == MAX_FILTER_PRED) {
+ if (filter->n_preds == MAX_FILTER_PRED) {
mutex_unlock(&filter_mutex);
return -ENOSPC;
}
- system->preds[system->n_preds] = pred;
- system->n_preds++;
+ filter->preds[filter->n_preds] = pred;
+ filter->n_preds++;
list_for_each_entry(call, &ftrace_events, list) {
int err;
err = __filter_add_pred(call, pred);
if (err == -ENOMEM) {
- system->preds[system->n_preds] = NULL;
- system->n_preds--;
+ filter->preds[filter->n_preds] = NULL;
+ filter->n_preds--;
mutex_unlock(&filter_mutex);
return err;
}