Skip to content

Commit 8434dc9

Browse files
committed
tracing: Convert the tracing facility over to use tracefs
debugfs was fine for the tracing facility as a quick way to get an interface. Now that tracing has matured, it should separate itself from debugfs such that it can be mounted separately without needing to mount all of debugfs with it. That is, users resist using tracing because it requires mounting debugfs. Having tracing have its own file system lets users get the features of tracing without needing to bring in the rest of the kernel's debug infrastructure. Another reason for tracefs is that debubfs does not support mkdir. Currently, to create instances, one does a mkdir in the tracing/instance directory. This is implemented via a hack that forces debugfs to do something it is not intended on doing. By converting over to tracefs, this hack can be removed and mkdir can be properly implemented. This patch does not address this yet, but it lays the ground work for that to be done. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 4282d60 commit 8434dc9

8 files changed

Lines changed: 74 additions & 66 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <linux/kallsyms.h>
1919
#include <linux/seq_file.h>
2020
#include <linux/suspend.h>
21-
#include <linux/debugfs.h>
21+
#include <linux/tracefs.h>
2222
#include <linux/hardirq.h>
2323
#include <linux/kthread.h>
2424
#include <linux/uaccess.h>
@@ -1008,7 +1008,7 @@ static struct tracer_stat function_stats __initdata = {
10081008
.stat_show = function_stat_show
10091009
};
10101010

1011-
static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
1011+
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
10121012
{
10131013
struct ftrace_profile_stat *stat;
10141014
struct dentry *entry;
@@ -1044,15 +1044,15 @@ static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
10441044
}
10451045
}
10461046

1047-
entry = debugfs_create_file("function_profile_enabled", 0644,
1047+
entry = tracefs_create_file("function_profile_enabled", 0644,
10481048
d_tracer, NULL, &ftrace_profile_fops);
10491049
if (!entry)
1050-
pr_warning("Could not create debugfs "
1050+
pr_warning("Could not create tracefs "
10511051
"'function_profile_enabled' entry\n");
10521052
}
10531053

10541054
#else /* CONFIG_FUNCTION_PROFILER */
1055-
static __init void ftrace_profile_debugfs(struct dentry *d_tracer)
1055+
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
10561056
{
10571057
}
10581058
#endif /* CONFIG_FUNCTION_PROFILER */
@@ -4690,7 +4690,7 @@ void ftrace_destroy_filter_files(struct ftrace_ops *ops)
46904690
mutex_unlock(&ftrace_lock);
46914691
}
46924692

4693-
static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer)
4693+
static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer)
46944694
{
46954695

46964696
trace_create_file("available_filter_functions", 0444,
@@ -4998,7 +4998,7 @@ static int __init ftrace_nodyn_init(void)
49984998
}
49994999
core_initcall(ftrace_nodyn_init);
50005000

5001-
static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; }
5001+
static inline int ftrace_init_dyn_tracefs(struct dentry *d_tracer) { return 0; }
50025002
static inline void ftrace_startup_enable(int command) { }
50035003
static inline void ftrace_startup_all(int command) { }
50045004
/* Keep as macros so we do not need to define the commands */
@@ -5451,24 +5451,24 @@ static const struct file_operations ftrace_pid_fops = {
54515451
.release = ftrace_pid_release,
54525452
};
54535453

5454-
static __init int ftrace_init_debugfs(void)
5454+
static __init int ftrace_init_tracefs(void)
54555455
{
54565456
struct dentry *d_tracer;
54575457

54585458
d_tracer = tracing_init_dentry();
54595459
if (IS_ERR(d_tracer))
54605460
return 0;
54615461

5462-
ftrace_init_dyn_debugfs(d_tracer);
5462+
ftrace_init_dyn_tracefs(d_tracer);
54635463

54645464
trace_create_file("set_ftrace_pid", 0644, d_tracer,
54655465
NULL, &ftrace_pid_fops);
54665466

5467-
ftrace_profile_debugfs(d_tracer);
5467+
ftrace_profile_tracefs(d_tracer);
54685468

54695469
return 0;
54705470
}
5471-
fs_initcall(ftrace_init_debugfs);
5471+
fs_initcall(ftrace_init_tracefs);
54725472

54735473
/**
54745474
* ftrace_kill - kill ftrace

‎kernel/trace/trace.c‎

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/notifier.h>
2121
#include <linux/irqflags.h>
2222
#include <linux/debugfs.h>
23+
#include <linux/tracefs.h>
2324
#include <linux/pagemap.h>
2425
#include <linux/hardirq.h>
2526
#include <linux/linkage.h>
@@ -5828,6 +5829,14 @@ static inline __init int register_snapshot_cmd(void) { return 0; }
58285829

58295830
static struct dentry *tracing_get_dentry(struct trace_array *tr)
58305831
{
5832+
if (WARN_ON(!tr->dir))
5833+
return ERR_PTR(-ENODEV);
5834+
5835+
/* Top directory uses NULL as the parent */
5836+
if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
5837+
return NULL;
5838+
5839+
/* All sub buffers have a descriptor */
58315840
return tr->dir;
58325841
}
58335842

@@ -5842,10 +5851,10 @@ static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu)
58425851
if (IS_ERR(d_tracer))
58435852
return NULL;
58445853

5845-
tr->percpu_dir = debugfs_create_dir("per_cpu", d_tracer);
5854+
tr->percpu_dir = tracefs_create_dir("per_cpu", d_tracer);
58465855

58475856
WARN_ONCE(!tr->percpu_dir,
5848-
"Could not create debugfs directory 'per_cpu/%d'\n", cpu);
5857+
"Could not create tracefs directory 'per_cpu/%d'\n", cpu);
58495858

58505859
return tr->percpu_dir;
58515860
}
@@ -5862,7 +5871,7 @@ trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent,
58625871
}
58635872

58645873
static void
5865-
tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
5874+
tracing_init_tracefs_percpu(struct trace_array *tr, long cpu)
58665875
{
58675876
struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
58685877
struct dentry *d_cpu;
@@ -5872,9 +5881,9 @@ tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
58725881
return;
58735882

58745883
snprintf(cpu_dir, 30, "cpu%ld", cpu);
5875-
d_cpu = debugfs_create_dir(cpu_dir, d_percpu);
5884+
d_cpu = tracefs_create_dir(cpu_dir, d_percpu);
58765885
if (!d_cpu) {
5877-
pr_warning("Could not create debugfs '%s' entry\n", cpu_dir);
5886+
pr_warning("Could not create tracefs '%s' entry\n", cpu_dir);
58785887
return;
58795888
}
58805889

@@ -6026,9 +6035,9 @@ struct dentry *trace_create_file(const char *name,
60266035
{
60276036
struct dentry *ret;
60286037

6029-
ret = debugfs_create_file(name, mode, parent, data, fops);
6038+
ret = tracefs_create_file(name, mode, parent, data, fops);
60306039
if (!ret)
6031-
pr_warning("Could not create debugfs '%s' entry\n", name);
6040+
pr_warning("Could not create tracefs '%s' entry\n", name);
60326041

60336042
return ret;
60346043
}
@@ -6045,9 +6054,9 @@ static struct dentry *trace_options_init_dentry(struct trace_array *tr)
60456054
if (IS_ERR(d_tracer))
60466055
return NULL;
60476056

6048-
tr->options = debugfs_create_dir("options", d_tracer);
6057+
tr->options = tracefs_create_dir("options", d_tracer);
60496058
if (!tr->options) {
6050-
pr_warning("Could not create debugfs directory 'options'\n");
6059+
pr_warning("Could not create tracefs directory 'options'\n");
60516060
return NULL;
60526061
}
60536062

@@ -6116,7 +6125,7 @@ destroy_trace_option_files(struct trace_option_dentry *topts)
61166125
return;
61176126

61186127
for (cnt = 0; topts[cnt].opt; cnt++)
6119-
debugfs_remove(topts[cnt].entry);
6128+
tracefs_remove(topts[cnt].entry);
61206129

61216130
kfree(topts);
61226131
}
@@ -6205,7 +6214,7 @@ static const struct file_operations rb_simple_fops = {
62056214
struct dentry *trace_instance_dir;
62066215

62076216
static void
6208-
init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
6217+
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);
62096218

62106219
static int
62116220
allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size)
@@ -6321,17 +6330,17 @@ static int new_instance_create(const char *name)
63216330
if (allocate_trace_buffers(tr, trace_buf_size) < 0)
63226331
goto out_free_tr;
63236332

6324-
tr->dir = debugfs_create_dir(name, trace_instance_dir);
6333+
tr->dir = tracefs_create_dir(name, trace_instance_dir);
63256334
if (!tr->dir)
63266335
goto out_free_tr;
63276336

63286337
ret = event_trace_add_tracer(tr->dir, tr);
63296338
if (ret) {
6330-
debugfs_remove_recursive(tr->dir);
6339+
tracefs_remove_recursive(tr->dir);
63316340
goto out_free_tr;
63326341
}
63336342

6334-
init_tracer_debugfs(tr, tr->dir);
6343+
init_tracer_tracefs(tr, tr->dir);
63356344

63366345
list_add(&tr->list, &ftrace_trace_arrays);
63376346

@@ -6404,7 +6413,7 @@ static int instance_mkdir (struct inode *inode, struct dentry *dentry, umode_t m
64046413
return -ENOENT;
64056414

64066415
/*
6407-
* The inode mutex is locked, but debugfs_create_dir() will also
6416+
* The inode mutex is locked, but tracefs_create_dir() will also
64086417
* take the mutex. As the instances directory can not be destroyed
64096418
* or changed in any other way, it is safe to unlock it, and
64106419
* let the dentry try. If two users try to make the same dir at
@@ -6434,7 +6443,7 @@ static int instance_rmdir(struct inode *inode, struct dentry *dentry)
64346443
mutex_unlock(&dentry->d_inode->i_mutex);
64356444

64366445
/*
6437-
* The inode mutex is locked, but debugfs_create_dir() will also
6446+
* The inode mutex is locked, but tracefs_create_dir() will also
64386447
* take the mutex. As the instances directory can not be destroyed
64396448
* or changed in any other way, it is safe to unlock it, and
64406449
* let the dentry try. If two users try to make the same dir at
@@ -6459,7 +6468,7 @@ static const struct inode_operations instance_dir_inode_operations = {
64596468

64606469
static __init void create_trace_instances(struct dentry *d_tracer)
64616470
{
6462-
trace_instance_dir = debugfs_create_dir("instances", d_tracer);
6471+
trace_instance_dir = tracefs_create_dir("instances", d_tracer);
64636472
if (WARN_ON(!trace_instance_dir))
64646473
return;
64656474

@@ -6468,7 +6477,7 @@ static __init void create_trace_instances(struct dentry *d_tracer)
64686477
}
64696478

64706479
static void
6471-
init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
6480+
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
64726481
{
64736482
int cpu;
64746483

@@ -6522,7 +6531,7 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
65226531
#endif
65236532

65246533
for_each_tracing_cpu(cpu)
6525-
tracing_init_debugfs_percpu(tr, cpu);
6534+
tracing_init_tracefs_percpu(tr, cpu);
65266535

65276536
}
65286537

@@ -6550,10 +6559,10 @@ struct dentry *tracing_init_dentry(void)
65506559
return ERR_PTR(-ENOMEM);
65516560
}
65526561

6553-
return tr->dir;
6562+
return NULL;
65546563
}
65556564

6556-
static __init int tracer_init_debugfs(void)
6565+
static __init int tracer_init_tracefs(void)
65576566
{
65586567
struct dentry *d_tracer;
65596568

@@ -6563,7 +6572,7 @@ static __init int tracer_init_debugfs(void)
65636572
if (IS_ERR(d_tracer))
65646573
return 0;
65656574

6566-
init_tracer_debugfs(&global_trace, d_tracer);
6575+
init_tracer_tracefs(&global_trace, d_tracer);
65676576

65686577
trace_create_file("tracing_thresh", 0644, d_tracer,
65696578
&global_trace, &tracing_thresh_fops);
@@ -6925,5 +6934,5 @@ __init static int clear_boot_tracer(void)
69256934
return 0;
69266935
}
69276936

6928-
fs_initcall(tracer_init_debugfs);
6937+
fs_initcall(tracer_init_tracefs);
69296938
late_initcall(clear_boot_tracer);

‎kernel/trace/trace.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ struct tracer_flags {
334334

335335

336336
/**
337-
* struct tracer - a specific tracer and its callbacks to interact with debugfs
337+
* struct tracer - a specific tracer and its callbacks to interact with tracefs
338338
* @name: the name chosen to select it on the available_tracers file
339339
* @init: called when one switches to this tracer (echo name > current_tracer)
340340
* @reset: called when one switches to another tracer

0 commit comments

Comments
 (0)