All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs()
@ 2017-11-07 15:31 Namhyung Kim
  2017-11-07 15:31 ` [Qemu-devel] [PATCH 2/3] trace: Generalize searching for debugfs Namhyung Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Namhyung Kim @ 2017-11-07 15:31 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

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 <namhyung@gmail.com>
---
 trace/ftrace.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/trace/ftrace.c b/trace/ftrace.c
index 7de104deba..bfa38e71f0 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -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)
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/3] trace: Generalize searching for debugfs
  2017-11-07 15:31 [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Namhyung Kim
@ 2017-11-07 15:31 ` Namhyung Kim
  2017-11-07 15:31 ` [Qemu-devel] [PATCH 3/3] trace: Try using tracefs first Namhyung Kim
  2017-11-09 10:42 ` [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Stefan Hajnoczi
  2 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2017-11-07 15:31 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

The find_debugfs() can be shared to find a different filesystem like
tracefs.  So make it more general and rename to find_mount().

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 trace/ftrace.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/trace/ftrace.c b/trace/ftrace.c
index bfa38e71f0..213cb2205f 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -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");
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/3] trace: Try using tracefs first
  2017-11-07 15:31 [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Namhyung Kim
  2017-11-07 15:31 ` [Qemu-devel] [PATCH 2/3] trace: Generalize searching for debugfs Namhyung Kim
@ 2017-11-07 15:31 ` Namhyung Kim
  2017-11-09 10:42 ` [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Stefan Hajnoczi
  2 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2017-11-07 15:31 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

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>
---
 trace/ftrace.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/trace/ftrace.c b/trace/ftrace.c
index 213cb2205f..61692a8682 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -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;
     }
 
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs()
  2017-11-07 15:31 [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Namhyung Kim
  2017-11-07 15:31 ` [Qemu-devel] [PATCH 2/3] trace: Generalize searching for debugfs Namhyung Kim
  2017-11-07 15:31 ` [Qemu-devel] [PATCH 3/3] trace: Try using tracefs first Namhyung Kim
@ 2017-11-09 10:42 ` Stefan Hajnoczi
  2017-11-09 14:35   ` Namhyung Kim
  2 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2017-11-09 10:42 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Stefan Hajnoczi, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

On Wed, Nov 08, 2017 at 12:31:34AM +0900, Namhyung Kim wrote:
> 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 <namhyung@gmail.com>
> ---
>  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs()
  2017-11-09 10:42 ` [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Stefan Hajnoczi
@ 2017-11-09 14:35   ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2017-11-09 14:35 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Stefan Hajnoczi, qemu-devel

Hello,

On Thu, Nov 9, 2017 at 7:42 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Wed, Nov 08, 2017 at 12:31:34AM +0900, Namhyung Kim wrote:
>> 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 <namhyung@gmail.com>
>> ---
>>  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.

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.

>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-09 14:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 15:31 [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Namhyung Kim
2017-11-07 15:31 ` [Qemu-devel] [PATCH 2/3] trace: Generalize searching for debugfs Namhyung Kim
2017-11-07 15:31 ` [Qemu-devel] [PATCH 3/3] trace: Try using tracefs first Namhyung Kim
2017-11-09 10:42 ` [Qemu-devel] [PATCH 1/3] trace: Simplify find_debugfs() Stefan Hajnoczi
2017-11-09 14:35   ` Namhyung Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.