trace: Try using tracefs first

Recent Linux kernel provides separate tracefs which doesn't need to be
mounted on the debugfs.  Although most systems mount it at the
traditional place on the debugfs, it'd be safer to check tracefs first.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Namhyung Kim 2017-11-08 00:31:36 +09:00 committed by Stefan Hajnoczi
parent babfff8e11
commit c9add62195

View File

@ -42,12 +42,18 @@ bool ftrace_init(void)
{ {
char mount_point[PATH_MAX]; char mount_point[PATH_MAX];
char path[PATH_MAX]; char path[PATH_MAX];
int debugfs_found; int tracefs_found;
int trace_fd = -1; int trace_fd = -1;
const char *subdir = "";
debugfs_found = find_mount(mount_point, "debugfs"); tracefs_found = find_mount(mount_point, "tracefs");
if (debugfs_found) { if (!tracefs_found) {
snprintf(path, PATH_MAX, "%s/tracing/tracing_on", mount_point); tracefs_found = find_mount(mount_point, "debugfs");
subdir = "/tracing";
}
if (tracefs_found) {
snprintf(path, PATH_MAX, "%s%s/tracing_on", mount_point, subdir);
trace_fd = open(path, O_WRONLY); trace_fd = open(path, O_WRONLY);
if (trace_fd < 0) { if (trace_fd < 0) {
if (errno == EACCES) { if (errno == EACCES) {
@ -66,14 +72,14 @@ bool ftrace_init(void)
} }
close(trace_fd); close(trace_fd);
} }
snprintf(path, PATH_MAX, "%s/tracing/trace_marker", mount_point); snprintf(path, PATH_MAX, "%s%s/trace_marker", mount_point, subdir);
trace_marker_fd = open(path, O_WRONLY); trace_marker_fd = open(path, O_WRONLY);
if (trace_marker_fd < 0) { if (trace_marker_fd < 0) {
perror("Could not open ftrace 'trace_marker' file"); perror("Could not open ftrace 'trace_marker' file");
return false; return false;
} }
} else { } else {
fprintf(stderr, "debugfs is not mounted\n"); fprintf(stderr, "tracefs is not mounted\n");
return false; return false;
} }