Skip to content

Commit f76180b

Browse files
committed
tracing: Automatically mount tracefs on debugfs/tracing
As tools currently rely on the tracing directory in debugfs, we can not just created a tracefs infrastructure and expect sysadmins to mount the new tracefs to have their old tools work. Instead, the debugfs tracing directory is still created and the tracefs file system is mounted there when the debugfs filesystem is mounted. No longer does the tracing infrastructure update the debugfs file system, but instead interacts with the tracefs file system. But now, it still appears to the user like nothing changed, except you also have the feature of mounting just the tracing system without needing all of debugfs! Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 8434dc9 commit f76180b

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

kernel/trace/trace.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/splice.h>
3333
#include <linux/kdebug.h>
3434
#include <linux/string.h>
35+
#include <linux/mount.h>
3536
#include <linux/rwsem.h>
3637
#include <linux/slab.h>
3738
#include <linux/ctype.h>
@@ -6535,6 +6536,28 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
65356536

65366537
}
65376538

6539+
static struct vfsmount *trace_automount(void *ingore)
6540+
{
6541+
struct vfsmount *mnt;
6542+
struct file_system_type *type;
6543+
6544+
/*
6545+
* To maintain backward compatibility for tools that mount
6546+
* debugfs to get to the tracing facility, tracefs is automatically
6547+
* mounted to the debugfs/tracing directory.
6548+
*/
6549+
type = get_fs_type("tracefs");
6550+
if (!type)
6551+
return NULL;
6552+
mnt = vfs_kern_mount(type, 0, "tracefs", NULL);
6553+
put_filesystem(type);
6554+
if (IS_ERR(mnt))
6555+
return NULL;
6556+
mntget(mnt);
6557+
6558+
return mnt;
6559+
}
6560+
65386561
/**
65396562
* tracing_init_dentry - initialize top level trace array
65406563
*
@@ -6546,14 +6569,21 @@ struct dentry *tracing_init_dentry(void)
65466569
{
65476570
struct trace_array *tr = &global_trace;
65486571

6572+
/* The top level trace array uses NULL as parent */
65496573
if (tr->dir)
6550-
return tr->dir;
6574+
return NULL;
65516575

65526576
if (WARN_ON(!debugfs_initialized()))
65536577
return ERR_PTR(-ENODEV);
65546578

6555-
tr->dir = debugfs_create_dir("tracing", NULL);
6556-
6579+
/*
6580+
* As there may still be users that expect the tracing
6581+
* files to exist in debugfs/tracing, we must automount
6582+
* the tracefs file system there, so older tools still
6583+
* work with the newer kerenl.
6584+
*/
6585+
tr->dir = debugfs_create_automount("tracing", NULL,
6586+
trace_automount, NULL);
65576587
if (!tr->dir) {
65586588
pr_warn_once("Could not create debugfs directory 'tracing'\n");
65596589
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)