Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+33 -3
+33 -3
kernel/trace/trace.c
··· 32 32 #include <linux/splice.h> 33 33 #include <linux/kdebug.h> 34 34 #include <linux/string.h> 35 + #include <linux/mount.h> 35 36 #include <linux/rwsem.h> 36 37 #include <linux/slab.h> 37 38 #include <linux/ctype.h> ··· 6536 6535 6537 6536 } 6538 6537 6538 + static struct vfsmount *trace_automount(void *ingore) 6539 + { 6540 + struct vfsmount *mnt; 6541 + struct file_system_type *type; 6542 + 6543 + /* 6544 + * To maintain backward compatibility for tools that mount 6545 + * debugfs to get to the tracing facility, tracefs is automatically 6546 + * mounted to the debugfs/tracing directory. 6547 + */ 6548 + type = get_fs_type("tracefs"); 6549 + if (!type) 6550 + return NULL; 6551 + mnt = vfs_kern_mount(type, 0, "tracefs", NULL); 6552 + put_filesystem(type); 6553 + if (IS_ERR(mnt)) 6554 + return NULL; 6555 + mntget(mnt); 6556 + 6557 + return mnt; 6558 + } 6559 + 6539 6560 /** 6540 6561 * tracing_init_dentry - initialize top level trace array 6541 6562 * ··· 6569 6546 { 6570 6547 struct trace_array *tr = &global_trace; 6571 6548 6549 + /* The top level trace array uses NULL as parent */ 6572 6550 if (tr->dir) 6573 - return tr->dir; 6551 + return NULL; 6574 6552 6575 6553 if (WARN_ON(!debugfs_initialized())) 6576 6554 return ERR_PTR(-ENODEV); 6577 6555 6578 - tr->dir = debugfs_create_dir("tracing", NULL); 6579 - 6556 + /* 6557 + * As there may still be users that expect the tracing 6558 + * files to exist in debugfs/tracing, we must automount 6559 + * the tracefs file system there, so older tools still 6560 + * work with the newer kerenl. 6561 + */ 6562 + tr->dir = debugfs_create_automount("tracing", NULL, 6563 + trace_automount, NULL); 6580 6564 if (!tr->dir) { 6581 6565 pr_warn_once("Could not create debugfs directory 'tracing'\n"); 6582 6566 return ERR_PTR(-ENOMEM);