Commit 5452af66 authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar
Browse files

tracing/ftrace: factorize the tracing files creation



Impact: cleanup

Most of the tracing files creation follow the same pattern:

ret = debugfs_create_file(...)
if (!ret)
	pr_warning("Couldn't create ... entry\n")

Unify it!

Reported-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <1238109938-11840-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent a5dec557
Loading
Loading
Loading
Loading
+10 −29
Original line number Diff line number Diff line
@@ -2698,38 +2698,23 @@ static const struct file_operations ftrace_graph_fops = {

static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
{
	struct dentry *entry;

	entry = debugfs_create_file("available_filter_functions", 0444,
	trace_create_file("available_filter_functions", 0444,
			d_tracer, NULL, &ftrace_avail_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'available_filter_functions' entry\n");

	entry = debugfs_create_file("failures", 0444,
	trace_create_file("failures", 0444,
			d_tracer, NULL, &ftrace_failures_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'failures' entry\n");

	entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
	trace_create_file("set_ftrace_filter", 0644, d_tracer,
			NULL, &ftrace_filter_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'set_ftrace_filter' entry\n");

	entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer,
	trace_create_file("set_ftrace_notrace", 0644, d_tracer,
				    NULL, &ftrace_notrace_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'set_ftrace_notrace' entry\n");

#ifdef CONFIG_FUNCTION_GRAPH_TRACER
	entry = debugfs_create_file("set_graph_function", 0444, d_tracer,
	trace_create_file("set_graph_function", 0444, d_tracer,
				    NULL,
				    &ftrace_graph_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'set_graph_function' entry\n");
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

	return 0;
@@ -2987,7 +2972,6 @@ static const struct file_operations ftrace_pid_fops = {
static __init int ftrace_init_debugfs(void)
{
	struct dentry *d_tracer;
	struct dentry *entry;

	d_tracer = tracing_init_dentry();
	if (!d_tracer)
@@ -2995,11 +2979,8 @@ static __init int ftrace_init_debugfs(void)

	ftrace_init_dyn_debugfs(d_tracer);

	entry = debugfs_create_file("set_ftrace_pid", 0644, d_tracer,
	trace_create_file("set_ftrace_pid", 0644, d_tracer,
			    NULL, &ftrace_pid_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'set_ftrace_pid' entry\n");

	ftrace_profile_debugfs(d_tracer);

+2 −5
Original line number Diff line number Diff line
@@ -2845,14 +2845,11 @@ static const struct file_operations rb_simple_fops = {
static __init int rb_init_debugfs(void)
{
	struct dentry *d_tracer;
	struct dentry *entry;

	d_tracer = tracing_init_dentry();

	entry = debugfs_create_file("tracing_on", 0644, d_tracer,
	trace_create_file("tracing_on", 0644, d_tracer,
			    &ring_buffer_flags, &rb_simple_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'tracing_on' entry\n");

	return 0;
}
+62 −97
Original line number Diff line number Diff line
@@ -3581,7 +3581,7 @@ struct dentry *tracing_dentry_percpu(void)
static void tracing_init_debugfs_percpu(long cpu)
{
	struct dentry *d_percpu = tracing_dentry_percpu();
	struct dentry *entry, *d_cpu;
	struct dentry *d_cpu;
	/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
	char cpu_dir[7];

@@ -3596,21 +3596,15 @@ static void tracing_init_debugfs_percpu(long cpu)
	}

	/* per cpu trace_pipe */
	entry = debugfs_create_file("trace_pipe", 0444, d_cpu,
	trace_create_file("trace_pipe", 0444, d_cpu,
			(void *) cpu, &tracing_pipe_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'trace_pipe' entry\n");

	/* per cpu trace */
	entry = debugfs_create_file("trace", 0644, d_cpu,
	trace_create_file("trace", 0644, d_cpu,
			(void *) cpu, &tracing_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'trace' entry\n");

	entry = debugfs_create_file("trace_pipe_raw", 0444, d_cpu,
	trace_create_file("trace_pipe_raw", 0444, d_cpu,
			(void *) cpu, &tracing_buffers_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'trace_pipe_raw' entry\n");
}

#ifdef CONFIG_FTRACE_SELFTEST
@@ -3766,6 +3760,22 @@ static const struct file_operations trace_options_core_fops = {
	.write = trace_options_core_write,
};

struct dentry *trace_create_file(const char *name,
				 mode_t mode,
				 struct dentry *parent,
				 void *data,
				 const struct file_operations *fops)
{
	struct dentry *ret;

	ret = debugfs_create_file(name, mode, parent, data, fops);
	if (!ret)
		pr_warning("Could not create debugfs '%s' entry\n", name);

	return ret;
}


static struct dentry *trace_options_init_dentry(void)
{
	struct dentry *d_tracer;
@@ -3793,7 +3803,6 @@ create_trace_option_file(struct trace_option_dentry *topt,
			 struct tracer_opt *opt)
{
	struct dentry *t_options;
	struct dentry *entry;

	t_options = trace_options_init_dentry();
	if (!t_options)
@@ -3802,11 +3811,9 @@ create_trace_option_file(struct trace_option_dentry *topt,
	topt->flags = flags;
	topt->opt = opt;

	entry = debugfs_create_file(opt->name, 0644, t_options, topt,
	topt->entry = trace_create_file(opt->name, 0644, t_options, topt,
				    &trace_options_fops);

	topt->entry = entry;

}

static struct trace_option_dentry *
@@ -3861,123 +3868,81 @@ static struct dentry *
create_trace_option_core_file(const char *option, long index)
{
	struct dentry *t_options;
	struct dentry *entry;

	t_options = trace_options_init_dentry();
	if (!t_options)
		return NULL;

	entry = debugfs_create_file(option, 0644, t_options, (void *)index,
	return trace_create_file(option, 0644, t_options, (void *)index,
				    &trace_options_core_fops);

	return entry;
}

static __init void create_trace_options_dir(void)
{
	struct dentry *t_options;
	struct dentry *entry;
	int i;

	t_options = trace_options_init_dentry();
	if (!t_options)
		return;

	for (i = 0; trace_options[i]; i++) {
		entry = create_trace_option_core_file(trace_options[i], i);
		if (!entry)
			pr_warning("Could not create debugfs %s entry\n",
				   trace_options[i]);
	}
	for (i = 0; trace_options[i]; i++)
		create_trace_option_core_file(trace_options[i], i);
}

static __init int tracer_init_debugfs(void)
{
	struct dentry *d_tracer;
	struct dentry *entry;
	int cpu;

	d_tracer = tracing_init_dentry();

	entry = debugfs_create_file("tracing_enabled", 0644, d_tracer,
	trace_create_file("tracing_enabled", 0644, d_tracer,
			&global_trace, &tracing_ctrl_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'tracing_enabled' entry\n");

	entry = debugfs_create_file("trace_options", 0644, d_tracer,
	trace_create_file("trace_options", 0644, d_tracer,
			NULL, &tracing_iter_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'trace_options' entry\n");

	create_trace_options_dir();

	entry = debugfs_create_file("tracing_cpumask", 0644, d_tracer,
	trace_create_file("tracing_cpumask", 0644, d_tracer,
			NULL, &tracing_cpumask_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");

	entry = debugfs_create_file("trace", 0644, d_tracer,
	trace_create_file("trace", 0644, d_tracer,
			(void *) TRACE_PIPE_ALL_CPU, &tracing_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'trace' entry\n");

	entry = debugfs_create_file("available_tracers", 0444, d_tracer,
	trace_create_file("available_tracers", 0444, d_tracer,
			&global_trace, &show_traces_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'available_tracers' entry\n");

	entry = debugfs_create_file("current_tracer", 0444, d_tracer,
	trace_create_file("current_tracer", 0444, d_tracer,
			&global_trace, &set_tracer_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'current_tracer' entry\n");

	entry = debugfs_create_file("tracing_max_latency", 0644, d_tracer,
				    &tracing_max_latency,
				    &tracing_max_lat_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'tracing_max_latency' entry\n");
	trace_create_file("tracing_max_latency", 0644, d_tracer,
			&tracing_max_latency, &tracing_max_lat_fops);

	entry = debugfs_create_file("tracing_thresh", 0644, d_tracer,
	trace_create_file("tracing_thresh", 0644, d_tracer,
			&tracing_thresh, &tracing_max_lat_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'tracing_thresh' entry\n");
	entry = debugfs_create_file("README", 0644, d_tracer,

	trace_create_file("README", 0644, d_tracer,
			NULL, &tracing_readme_fops);
	if (!entry)
		pr_warning("Could not create debugfs 'README' entry\n");

	entry = debugfs_create_file("trace_pipe", 0444, d_tracer,
	trace_create_file("trace_pipe", 0444, d_tracer,
			(void *) TRACE_PIPE_ALL_CPU, &tracing_pipe_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'trace_pipe' entry\n");

	entry = debugfs_create_file("buffer_size_kb", 0644, d_tracer,
	trace_create_file("buffer_size_kb", 0644, d_tracer,
			&global_trace, &tracing_entries_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'buffer_size_kb' entry\n");

	entry = debugfs_create_file("trace_marker", 0220, d_tracer,
	trace_create_file("trace_marker", 0220, d_tracer,
			NULL, &tracing_mark_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'trace_marker' entry\n");

#ifdef CONFIG_DYNAMIC_FTRACE
	entry = debugfs_create_file("dyn_ftrace_total_info", 0444, d_tracer,
				    &ftrace_update_tot_cnt,
				    &tracing_dyn_info_fops);
	if (!entry)
		pr_warning("Could not create debugfs "
			   "'dyn_ftrace_total_info' entry\n");
	trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
			&ftrace_update_tot_cnt, &tracing_dyn_info_fops);
#endif
#ifdef CONFIG_SYSPROF_TRACER
	init_tracer_sysprof_debugfs(d_tracer);
#endif

	create_trace_options_dir();

	for_each_tracing_cpu(cpu)
		tracing_init_debugfs_percpu(cpu);

+6 −0
Original line number Diff line number Diff line
@@ -470,6 +470,12 @@ void trace_wake_up(void);
void tracing_reset(struct trace_array *tr, int cpu);
void tracing_reset_online_cpus(struct trace_array *tr);
int tracing_open_generic(struct inode *inode, struct file *filp);
struct dentry *trace_create_file(const char *name,
				 mode_t mode,
				 struct dentry *parent,
				 void *data,
				 const struct file_operations *fops);

struct dentry *tracing_init_dentry(void);
void init_tracer_sysprof_debugfs(struct dentry *d_tracer);

+0 −1
Original line number Diff line number Diff line
@@ -28,4 +28,3 @@ void ftrace_profile_disable(int event_id)
			return event->profile_disable(event);
	}
}
Loading