diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-09-02 03:56:35 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-09-04 11:00:58 -0400 |
commit | 988bdb319246dea977a375beee39a5452e99b3ef (patch) | |
tree | fa6163b12e399fe468638f115f6e46f3b1784f52 /tools/lib/api/fs/tracing_path.c | |
parent | 592d5a6ba86a31681fa5e20a63a145b0a3b53c8a (diff) |
tools lib api fs: Move debugfs__strerror_open into tracing_path.c object
Moving debugfs__strerror_open out of api/fs/debugfs.c, because it's not
debugfs specific. It'll be changed to consider tracefs mount as well in
following patches.
Renaming it into tracing_path__strerror_open_tp to fit into the
namespace. No functional change is intended.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Matt Fleming <matt.fleming@intel.com>
Cc: Raphael Beamonte <raphael.beamonte@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1441180605-24737-6-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/api/fs/tracing_path.c')
-rw-r--r-- | tools/lib/api/fs/tracing_path.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tools/lib/api/fs/tracing_path.c b/tools/lib/api/fs/tracing_path.c index 1fd6e1f99234..3b3e4f5fc50b 100644 --- a/tools/lib/api/fs/tracing_path.c +++ b/tools/lib/api/fs/tracing_path.c | |||
@@ -5,6 +5,8 @@ | |||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <errno.h> | ||
9 | #include <unistd.h> | ||
8 | #include "debugfs.h" | 10 | #include "debugfs.h" |
9 | #include "tracefs.h" | 11 | #include "tracefs.h" |
10 | 12 | ||
@@ -81,3 +83,55 @@ void put_tracing_file(char *file) | |||
81 | { | 83 | { |
82 | free(file); | 84 | free(file); |
83 | } | 85 | } |
86 | |||
87 | static int strerror_open(int err, char *buf, size_t size, const char *filename) | ||
88 | { | ||
89 | char sbuf[128]; | ||
90 | |||
91 | switch (err) { | ||
92 | case ENOENT: | ||
93 | if (debugfs_configured()) { | ||
94 | snprintf(buf, size, | ||
95 | "Error:\tFile %s/%s not found.\n" | ||
96 | "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n", | ||
97 | debugfs_mountpoint, filename); | ||
98 | break; | ||
99 | } | ||
100 | snprintf(buf, size, "%s", | ||
101 | "Error:\tUnable to find debugfs\n" | ||
102 | "Hint:\tWas your kernel compiled with debugfs support?\n" | ||
103 | "Hint:\tIs the debugfs filesystem mounted?\n" | ||
104 | "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'"); | ||
105 | break; | ||
106 | case EACCES: { | ||
107 | const char *mountpoint = debugfs_mountpoint; | ||
108 | |||
109 | if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) { | ||
110 | const char *tracefs_mntpoint = tracefs_find_mountpoint(); | ||
111 | |||
112 | if (tracefs_mntpoint) | ||
113 | mountpoint = tracefs_mntpoint; | ||
114 | } | ||
115 | |||
116 | snprintf(buf, size, | ||
117 | "Error:\tNo permissions to read %s/%s\n" | ||
118 | "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n", | ||
119 | debugfs_mountpoint, filename, mountpoint); | ||
120 | } | ||
121 | break; | ||
122 | default: | ||
123 | snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf))); | ||
124 | break; | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name) | ||
131 | { | ||
132 | char path[PATH_MAX]; | ||
133 | |||
134 | snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*"); | ||
135 | |||
136 | return strerror_open(err, buf, size, path); | ||
137 | } | ||