tracing/filter: Separate predicate init and filter addition

Making the code cleaner by having one function to fully prepare
the predicate (create_pred), and another to add the predicate to
the filter (filter_add_pred).

As a benefit, this way the dry_run flag stays only inside the
replace_preds function and is not passed deeper.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1313072754-4620-3-git-send-email-jolsa@redhat.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
Jiri Olsa 2011-08-11 16:25:46 +02:00 committed by Steven Rostedt
parent 81570d9caa
commit 9d96cd1743

View file

@ -685,8 +685,7 @@ __pop_pred_stack(struct pred_stack *stack)
static int filter_set_pred(struct event_filter *filter, static int filter_set_pred(struct event_filter *filter,
int idx, int idx,
struct pred_stack *stack, struct pred_stack *stack,
struct filter_pred *src, struct filter_pred *src)
filter_pred_fn_t fn)
{ {
struct filter_pred *dest = &filter->preds[idx]; struct filter_pred *dest = &filter->preds[idx];
struct filter_pred *left; struct filter_pred *left;
@ -698,7 +697,6 @@ static int filter_set_pred(struct event_filter *filter,
if (!dest->field_name) if (!dest->field_name)
return -ENOMEM; return -ENOMEM;
} }
dest->fn = fn;
dest->index = idx; dest->index = idx;
if (dest->op == OP_OR || dest->op == OP_AND) { if (dest->op == OP_OR || dest->op == OP_AND) {
@ -836,12 +834,10 @@ static void filter_free_subsystem_filters(struct event_subsystem *system)
} }
} }
static int filter_add_pred_fn(struct filter_parse_state *ps, static int filter_add_pred(struct filter_parse_state *ps,
struct ftrace_event_call *call, struct event_filter *filter,
struct event_filter *filter, struct filter_pred *pred,
struct filter_pred *pred, struct pred_stack *stack)
struct pred_stack *stack,
filter_pred_fn_t fn)
{ {
int idx, err; int idx, err;
@ -852,7 +848,7 @@ static int filter_add_pred_fn(struct filter_parse_state *ps,
idx = filter->n_preds; idx = filter->n_preds;
filter_clear_pred(&filter->preds[idx]); filter_clear_pred(&filter->preds[idx]);
err = filter_set_pred(filter, idx, stack, pred, fn); err = filter_set_pred(filter, idx, stack, pred);
if (err) if (err)
return err; return err;
@ -933,25 +929,16 @@ static filter_pred_fn_t select_comparison_fn(int op, int field_size,
return fn; return fn;
} }
static int filter_add_pred(struct filter_parse_state *ps, static int init_pred(struct filter_parse_state *ps,
struct ftrace_event_call *call, struct ftrace_event_call *call,
struct event_filter *filter, struct filter_pred *pred)
struct filter_pred *pred,
struct pred_stack *stack,
bool dry_run)
{ {
struct ftrace_event_field *field; struct ftrace_event_field *field;
filter_pred_fn_t fn; filter_pred_fn_t fn = filter_pred_none;
unsigned long long val; unsigned long long val;
int ret; int ret;
fn = pred->fn = filter_pred_none;
if (pred->op == OP_AND)
goto add_pred_fn;
else if (pred->op == OP_OR)
goto add_pred_fn;
field = find_event_field(call, pred->field_name); field = find_event_field(call, pred->field_name);
if (!field) { if (!field) {
parse_error(ps, FILT_ERR_FIELD_NOT_FOUND, 0); parse_error(ps, FILT_ERR_FIELD_NOT_FOUND, 0);
@ -997,9 +984,7 @@ static int filter_add_pred(struct filter_parse_state *ps,
if (pred->op == OP_NE) if (pred->op == OP_NE)
pred->not = 1; pred->not = 1;
add_pred_fn: pred->fn = fn;
if (!dry_run)
return filter_add_pred_fn(ps, call, filter, pred, stack, fn);
return 0; return 0;
} }
@ -1299,6 +1284,7 @@ parse_operand:
} }
static struct filter_pred *create_pred(struct filter_parse_state *ps, static struct filter_pred *create_pred(struct filter_parse_state *ps,
struct ftrace_event_call *call,
int op, char *operand1, char *operand2) int op, char *operand1, char *operand2)
{ {
static struct filter_pred pred; static struct filter_pred pred;
@ -1321,7 +1307,7 @@ static struct filter_pred *create_pred(struct filter_parse_state *ps,
strcpy(pred.regex.pattern, operand2); strcpy(pred.regex.pattern, operand2);
pred.regex.len = strlen(pred.regex.pattern); pred.regex.len = strlen(pred.regex.pattern);
return &pred; return init_pred(ps, call, &pred) ? NULL : &pred;
} }
static int check_preds(struct filter_parse_state *ps) static int check_preds(struct filter_parse_state *ps)
@ -1630,16 +1616,20 @@ static int replace_preds(struct ftrace_event_call *call,
goto fail; goto fail;
} }
pred = create_pred(ps, elt->op, operand1, operand2); pred = create_pred(ps, call, elt->op, operand1, operand2);
if (!pred) { if (!pred) {
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
err = filter_add_pred(ps, call, filter, pred, &stack, dry_run); if (!dry_run) {
filter_free_pred(pred); err = filter_add_pred(ps, filter, pred, &stack);
if (err) if (err) {
goto fail; filter_free_pred(pred);
goto fail;
}
}
filter_free_pred(pred);
operand1 = operand2 = NULL; operand1 = operand2 = NULL;
} }