trace: Simplify find_debugfs()
PATCH 1/3 trace: Simplify find_debugfs()
The return vale of find_debugfs() is 1 if it could find a mount point of debugfs. It can be saved in the while loop instead of checking it again.
--- trace/ftrace.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
trace/ftrace.c +3 -4
@@ -19,6 +19,7 @@ static int find_debugfs(char *debugfs) {char type[100 ];FILE *fp; +int ret =0 ; fp =fopen ("/proc/mounts" ,"r" );if (fp ==NULL ) {
@@ -28,15 +29,13 @@ static int find_debugfs(char *debugfs) while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", debugfs, type) ==2 ) {if (strcmp (type,"debugfs" ) ==0 ) { + ret =1 ;break ; } }fclose (fp); -if (strcmp (type,"debugfs" ) !=0 ) { -return 0 ; - } -return 1 ; +return ret; }bool ftrace_init (void )
Signature · 1 line
2.14.3
PATCH 2/3 trace: Generalize searching for debugfs
The find_debugfs() can be shared to find a different filesystem like tracefs. So make it more general and rename to find_mount().
--- trace/ftrace.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
trace/ftrace.c +7 -7
@@ -15,7 +15,7 @@int trace_marker_fd; -static int find_debugfs (char *debugfs) +static int find_mount (char *mount_point,const char *fstype) {char type[100 ];FILE *fp;
@@ -27,8 +27,8 @@ static int find_debugfs(char *debugfs) } while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", - debugfs, type) ==2 ) { -if (strcmp (type,"debugfs" ) ==0 ) { + mount_point, type) ==2 ) { +if (strcmp (type, fstype) ==0 ) { ret =1 ;break ; }
@@ -40,14 +40,14 @@ static int find_debugfs(char *debugfs)bool ftrace_init (void ) { -char debugfs[PATH_MAX ]; +char mount_point[PATH_MAX ];char path[PATH_MAX ];int debugfs_found;int trace_fd =-1 ; - debugfs_found =find_debugfs (debugfs); + debugfs_found =find_mount (mount_point,"debugfs" );if (debugfs_found) { -snprintf (path,PATH_MAX ,"%s/tracing/tracing_on" , debugfs); +snprintf (path,PATH_MAX ,"%s/tracing/tracing_on" , mount_point); trace_fd =open (path,O_WRONLY );if (trace_fd <0 ) {if (errno ==EACCES ) {
@@ -66,7 +66,7 @@ bool ftrace_init(void) }close (trace_fd); } -snprintf (path,PATH_MAX ,"%s/tracing/trace_marker" , debugfs); +snprintf (path,PATH_MAX ,"%s/tracing/trace_marker" , mount_point); trace_marker_fd =open (path,O_WRONLY );if (trace_marker_fd <0 ) {perror ("Could not open ftrace 'trace_marker' file" );
Signature · 1 line
2.14.3
PATCH 3/3 trace: Try using tracefs first
In reply to Namhyung KimRecent 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.
--- trace/ftrace.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
trace/ftrace.c +12 -6
@@ -42,12 +42,18 @@ bool ftrace_init(void) {char mount_point[PATH_MAX ];char path[PATH_MAX ]; -int debugfs_found; +int tracefs_found;int trace_fd =-1 ; +const char *subdir ="" ; - debugfs_found =find_mount (mount_point,"debugfs" ); -if (debugfs_found) { -snprintf (path,PATH_MAX ,"%s/tracing/tracing_on" , mount_point); + tracefs_found =find_mount (mount_point,"tracefs" ); +if (!tracefs_found) { + 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 );if (trace_fd <0 ) {if (errno ==EACCES ) {
@@ -66,14 +72,14 @@ bool ftrace_init(void) }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 );if (trace_marker_fd <0 ) {perror ("Could not open ftrace 'trace_marker' file" );return false; } }else { -fprintf (stderr,"debugfs is not mounted\n" ); +fprintf (stderr,"tracefs is not mounted\n" );return false; }
Signature · 1 line
2.14.3
Stefan Hajnoczi
AppliedQuoted 7 lines · Namhyung Kim
The return vale of
find_debugfs()is 1 if it could find a mount point of debugfs. It can be saved in the while loop instead of checking it again.Signed-off-by Namhyung Kim <[email protected]>--- trace/ftrace.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Thanks, applied all to my tracing-next tree:
https://github.com/stefanha/qemu/commits/tracing-next
Please send multi-patch series with a cover letter in the future (git format-patch --cover-letter). Continuous integration tools may ignore multi-patch series without a cover letter.
qemu.git/master is currently frozen for the QEMU 2.11 release so you won't see your patches in master until QEMU 2.11 has been released. Once the development window opens again your patches will be merged into qemu.git/master.
Stefan
Hello,
Quoted 9 lines · Stefan Hajnoczi
Quoted 7 lines · Namhyung Kim
The return vale of
find_debugfs()is 1 if it could find a mount point of debugfs. It can be saved in the while loop instead of checking it again.Signed-off-by Namhyung Kim <[email protected]>--- trace/ftrace.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Quoted 6 lines
Thanks, applied all to my tracing-next tree:
https://github.com/stefanha/qemu/commits/tracing-nextPlease send multi-patch series with a cover letter in the future (git format-patch --cover-letter). Continuous integration tools may ignore multi-patch series without a cover letter.
OK. I usually use a cover letter when a patch series has 5+ patches. But will add it for small series too in the future.
Quoted 5 lines
qemu.git/master is currently frozen for the QEMU 2.11 release so you won't see your patches in master until QEMU 2.11 has been released. Once the development window opens again your patches will be merged into qemu.git/master.
Understood.
Thanks
Namhyung