Skip to content

Commit

Permalink
tracing: Use trace_create_file() to simplify creation of tracefs entries
Browse files Browse the repository at this point in the history
Creating tracefs entries with tracefs_create_file() followed by pr_warn()
is tedious and repetitive, we can use trace_create_file() to simplify
this process and make the code more readable.

Link: https://lkml.kernel.org/r/20220114131052.534382-1-ytcoode@gmail.com

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
ytcoode authored and rostedt committed May 27, 2022
1 parent e35c2d8 commit e4931b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 48 deletions.
9 changes: 3 additions & 6 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ static struct tracer_stat function_stats __initdata = {
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
{
struct ftrace_profile_stat *stat;
struct dentry *entry;
char *name;
int ret;
int cpu;
Expand Down Expand Up @@ -983,11 +982,9 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
}
}

entry = tracefs_create_file("function_profile_enabled",
TRACE_MODE_WRITE, d_tracer, NULL,
&ftrace_profile_fops);
if (!entry)
pr_warn("Could not create tracefs 'function_profile_enabled' entry\n");
trace_create_file("function_profile_enabled",
TRACE_MODE_WRITE, d_tracer, NULL,
&ftrace_profile_fops);
}

#else /* CONFIG_FUNCTION_PROFILER */
Expand Down
9 changes: 2 additions & 7 deletions kernel/trace/trace_dynevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,14 @@ static const struct file_operations dynamic_events_ops = {
/* Make a tracefs interface for controlling dynamic events */
static __init int init_dynamic_event(void)
{
struct dentry *entry;
int ret;

ret = tracing_init_dentry();
if (ret)
return 0;

entry = tracefs_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,
NULL, &dynamic_events_ops);

/* Event list interface */
if (!entry)
pr_warn("Could not create tracefs 'dynamic_events' entry\n");
trace_create_file("dynamic_events", TRACE_MODE_WRITE, NULL,
NULL, &dynamic_events_ops);

return 0;
}
Expand Down
29 changes: 10 additions & 19 deletions kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,12 +3546,10 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
struct dentry *d_events;
struct dentry *entry;

entry = tracefs_create_file("set_event", TRACE_MODE_WRITE, parent,
tr, &ftrace_set_event_fops);
if (!entry) {
pr_warn("Could not create tracefs 'set_event' entry\n");
entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent,
tr, &ftrace_set_event_fops);
if (!entry)
return -ENOMEM;
}

d_events = tracefs_create_dir("events", parent);
if (!d_events) {
Expand All @@ -3566,16 +3564,12 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)

/* There are not as crucial, just warn if they are not created */

entry = tracefs_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
tr, &ftrace_set_event_pid_fops);
if (!entry)
pr_warn("Could not create tracefs 'set_event_pid' entry\n");
trace_create_file("set_event_pid", TRACE_MODE_WRITE, parent,
tr, &ftrace_set_event_pid_fops);

entry = tracefs_create_file("set_event_notrace_pid",
TRACE_MODE_WRITE, parent, tr,
&ftrace_set_event_notrace_pid_fops);
if (!entry)
pr_warn("Could not create tracefs 'set_event_notrace_pid' entry\n");
trace_create_file("set_event_notrace_pid",
TRACE_MODE_WRITE, parent, tr,
&ftrace_set_event_notrace_pid_fops);

/* ring buffer internal formats */
trace_create_file("header_page", TRACE_MODE_READ, d_events,
Expand Down Expand Up @@ -3790,17 +3784,14 @@ static __init int event_trace_init_fields(void)
__init int event_trace_init(void)
{
struct trace_array *tr;
struct dentry *entry;
int ret;

tr = top_trace_array();
if (!tr)
return -ENODEV;

entry = tracefs_create_file("available_events", TRACE_MODE_READ,
NULL, tr, &ftrace_avail_fops);
if (!entry)
pr_warn("Could not create tracefs 'available_events' entry\n");
trace_create_file("available_events", TRACE_MODE_READ,
NULL, tr, &ftrace_avail_fops);

ret = early_event_add_tracer(NULL, tr);
if (ret)
Expand Down
15 changes: 4 additions & 11 deletions kernel/trace/trace_kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1907,25 +1907,18 @@ core_initcall(init_kprobe_trace_early);
static __init int init_kprobe_trace(void)
{
int ret;
struct dentry *entry;

ret = tracing_init_dentry();
if (ret)
return 0;

entry = tracefs_create_file("kprobe_events", TRACE_MODE_WRITE,
NULL, NULL, &kprobe_events_ops);

/* Event list interface */
if (!entry)
pr_warn("Could not create tracefs 'kprobe_events' entry\n");
trace_create_file("kprobe_events", TRACE_MODE_WRITE,
NULL, NULL, &kprobe_events_ops);

/* Profile interface */
entry = tracefs_create_file("kprobe_profile", TRACE_MODE_READ,
NULL, NULL, &kprobe_profile_ops);

if (!entry)
pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
trace_create_file("kprobe_profile", TRACE_MODE_READ,
NULL, NULL, &kprobe_profile_ops);

setup_boot_kprobe_events();

Expand Down
7 changes: 2 additions & 5 deletions kernel/trace/trace_recursion_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,9 @@ static const struct file_operations recursed_functions_fops = {

__init static int create_recursed_functions(void)
{
struct dentry *dentry;

dentry = trace_create_file("recursed_functions", TRACE_MODE_WRITE,
NULL, NULL, &recursed_functions_fops);
if (!dentry)
pr_warn("WARNING: Failed to create recursed_functions\n");
trace_create_file("recursed_functions", TRACE_MODE_WRITE,
NULL, NULL, &recursed_functions_fops);
return 0;
}

Expand Down

0 comments on commit e4931b8

Please sign in to comment.