Skip to content

Commit e1f187d

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Have existing event_command.parse() implementations use helpers
Simplify the existing event_command.parse() implementations by having them make use of the helper functions previously introduced. Link: https://lkml.kernel.org/r/b353e3427a81f9d3adafd98fd7d73e78a8209f43.1644010576.git.zanussi@kernel.org Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4767054 commit e1f187d

File tree

4 files changed

+69
-151
lines changed

4 files changed

+69
-151
lines changed

kernel/trace/trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,8 @@ extern int event_enable_trigger_print(struct seq_file *m,
15771577
extern void event_enable_trigger_free(struct event_trigger_data *data);
15781578
extern int event_enable_trigger_parse(struct event_command *cmd_ops,
15791579
struct trace_event_file *file,
1580-
char *glob, char *cmd, char *param);
1580+
char *glob, char *cmd,
1581+
char *param_and_filter);
15811582
extern int event_enable_register_trigger(char *glob,
15821583
struct event_trigger_data *data,
15831584
struct trace_event_file *file);

kernel/trace/trace_eprobe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ static struct event_trigger_ops eprobe_trigger_ops = {
546546

547547
static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops,
548548
struct trace_event_file *file,
549-
char *glob, char *cmd, char *param)
549+
char *glob, char *cmd,
550+
char *param_and_filter)
550551
{
551552
return -1;
552553
}

kernel/trace/trace_events_hist.c

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,8 @@ static char *find_trigger_filter(struct hist_trigger_data *hist_data,
27852785
static struct event_command trigger_hist_cmd;
27862786
static int event_hist_trigger_parse(struct event_command *cmd_ops,
27872787
struct trace_event_file *file,
2788-
char *glob, char *cmd, char *param);
2788+
char *glob, char *cmd,
2789+
char *param_and_filter);
27892790

27902791
static bool compatible_keys(struct hist_trigger_data *target_hist_data,
27912792
struct hist_trigger_data *hist_data,
@@ -6166,17 +6167,17 @@ static void hist_unreg_all(struct trace_event_file *file)
61666167

61676168
static int event_hist_trigger_parse(struct event_command *cmd_ops,
61686169
struct trace_event_file *file,
6169-
char *glob, char *cmd, char *param)
6170+
char *glob, char *cmd,
6171+
char *param_and_filter)
61706172
{
61716173
unsigned int hist_trigger_bits = TRACING_MAP_BITS_DEFAULT;
61726174
struct event_trigger_data *trigger_data;
61736175
struct hist_trigger_attrs *attrs;
6174-
struct event_trigger_ops *trigger_ops;
61756176
struct hist_trigger_data *hist_data;
6177+
char *param, *filter, *p, *start;
61766178
struct synth_event *se;
61776179
const char *se_name;
6178-
bool remove = false;
6179-
char *trigger, *p, *start;
6180+
bool remove;
61806181
int ret = 0;
61816182

61826183
lockdep_assert_held(&event_mutex);
@@ -6185,31 +6186,30 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
61856186

61866187
if (strlen(glob)) {
61876188
hist_err_clear();
6188-
last_cmd_set(file, param);
6189+
last_cmd_set(file, param_and_filter);
61896190
}
61906191

6191-
if (!param)
6192-
return -EINVAL;
6192+
remove = event_trigger_check_remove(glob);
61936193

6194-
if (glob[0] == '!')
6195-
remove = true;
6194+
if (event_trigger_empty_param(param_and_filter))
6195+
return -EINVAL;
61966196

61976197
/*
61986198
* separate the trigger from the filter (k:v [if filter])
61996199
* allowing for whitespace in the trigger
62006200
*/
6201-
p = trigger = param;
6201+
p = param = param_and_filter;
62026202
do {
62036203
p = strstr(p, "if");
62046204
if (!p)
62056205
break;
6206-
if (p == param)
6206+
if (p == param_and_filter)
62076207
return -EINVAL;
62086208
if (*(p - 1) != ' ' && *(p - 1) != '\t') {
62096209
p++;
62106210
continue;
62116211
}
6212-
if (p >= param + strlen(param) - (sizeof("if") - 1) - 1)
6212+
if (p >= param_and_filter + strlen(param_and_filter) - (sizeof("if") - 1) - 1)
62136213
return -EINVAL;
62146214
if (*(p + sizeof("if") - 1) != ' ' && *(p + sizeof("if") - 1) != '\t') {
62156215
p++;
@@ -6219,24 +6219,24 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
62196219
} while (1);
62206220

62216221
if (!p)
6222-
param = NULL;
6222+
filter = NULL;
62236223
else {
62246224
*(p - 1) = '\0';
6225-
param = strstrip(p);
6226-
trigger = strstrip(trigger);
6225+
filter = strstrip(p);
6226+
param = strstrip(param);
62276227
}
62286228

62296229
/*
62306230
* To simplify arithmetic expression parsing, replace occurrences of
62316231
* '.sym-offset' modifier with '.symXoffset'
62326232
*/
6233-
start = strstr(trigger, ".sym-offset");
6233+
start = strstr(param, ".sym-offset");
62346234
while (start) {
62356235
*(start + 4) = 'X';
62366236
start = strstr(start + 11, ".sym-offset");
62376237
}
62386238

6239-
attrs = parse_hist_trigger_attrs(file->tr, trigger);
6239+
attrs = parse_hist_trigger_attrs(file->tr, param);
62406240
if (IS_ERR(attrs))
62416241
return PTR_ERR(attrs);
62426242

@@ -6249,29 +6249,15 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
62496249
return PTR_ERR(hist_data);
62506250
}
62516251

6252-
trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
6253-
6254-
trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
6252+
trigger_data = event_trigger_alloc(cmd_ops, cmd, param, hist_data);
62556253
if (!trigger_data) {
62566254
ret = -ENOMEM;
62576255
goto out_free;
62586256
}
62596257

6260-
trigger_data->count = -1;
6261-
trigger_data->ops = trigger_ops;
6262-
trigger_data->cmd_ops = cmd_ops;
6263-
6264-
INIT_LIST_HEAD(&trigger_data->list);
6265-
RCU_INIT_POINTER(trigger_data->filter, NULL);
6266-
6267-
trigger_data->private_data = hist_data;
6268-
6269-
/* if param is non-empty, it's supposed to be a filter */
6270-
if (param && cmd_ops->set_filter) {
6271-
ret = cmd_ops->set_filter(param, trigger_data, file);
6272-
if (ret < 0)
6273-
goto out_free;
6274-
}
6258+
ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
6259+
if (ret < 0)
6260+
goto out_free;
62756261

62766262
if (remove) {
62776263
if (!have_hist_trigger_match(trigger_data, file))
@@ -6298,8 +6284,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
62986284
if (!(attrs->pause || attrs->cont || attrs->clear))
62996285
ret = -ENOENT;
63006286
goto out_free;
6301-
} else if (ret < 0)
6302-
goto out_free;
6287+
}
63036288

63046289
if (get_named_trigger_data(trigger_data))
63056290
goto enable;
@@ -6331,8 +6316,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
63316316
out_unreg:
63326317
event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
63336318
out_free:
6334-
if (cmd_ops->set_filter)
6335-
cmd_ops->set_filter(NULL, trigger_data, NULL);
6319+
event_trigger_reset_filter(cmd_ops, trigger_data);
63366320

63376321
remove_hist_vars(hist_data);
63386322

0 commit comments

Comments
 (0)