Re: [PATCH 04/11] perf tools: Move debugfs__strerror_open into util.c object

From: Arnaldo Carvalho de Melo
Date: Wed Aug 26 2015 - 09:52:52 EST


Em Wed, Aug 26, 2015 at 03:46:46PM +0200, Jiri Olsa escreveu:
> 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.

If it is "debugfs__" it should not deal with tracefs, right?

My feeling is that they should be decoupled more, not the other way
around :-\

- Arnaldo

> Link: http://lkml.kernel.org/n/tip-bq0f0l4r0bjvy0pjp4m759kv@xxxxxxxxxxxxxx
> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> ---
> tools/lib/api/fs/debugfs.c | 51 ---------------------------------------------
> tools/lib/api/fs/debugfs.h | 3 ---
> tools/perf/util/util.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
> tools/perf/util/util.h | 2 ++
> 4 files changed, 54 insertions(+), 54 deletions(-)
>
> diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
> index eb7cf4d18f8a..896c3595c9df 100644
> --- a/tools/lib/api/fs/debugfs.c
> +++ b/tools/lib/api/fs/debugfs.c
> @@ -76,54 +76,3 @@ out:
> return debugfs_mountpoint;
> }
>
> -int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename)
> -{
> - char sbuf[128];
> -
> - switch (err) {
> - case ENOENT:
> - if (debugfs_found) {
> - snprintf(buf, size,
> - "Error:\tFile %s/%s not found.\n"
> - "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
> - debugfs_mountpoint, filename);
> - break;
> - }
> - snprintf(buf, size, "%s",
> - "Error:\tUnable to find debugfs\n"
> - "Hint:\tWas your kernel compiled with debugfs support?\n"
> - "Hint:\tIs the debugfs filesystem mounted?\n"
> - "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
> - break;
> - case EACCES: {
> - const char *mountpoint = debugfs_mountpoint;
> -
> - if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) {
> - const char *tracefs_mntpoint = tracefs_find_mountpoint();
> -
> - if (tracefs_mntpoint)
> - mountpoint = tracefs_mntpoint;
> - }
> -
> - snprintf(buf, size,
> - "Error:\tNo permissions to read %s/%s\n"
> - "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
> - debugfs_mountpoint, filename, mountpoint);
> - }
> - break;
> - default:
> - snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
> - break;
> - }
> -
> - return 0;
> -}
> -
> -int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
> -{
> - char path[PATH_MAX];
> -
> - snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*");
> -
> - return debugfs__strerror_open(err, buf, size, path);
> -}
> diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
> index 455023698d2b..19a618e9dbc1 100644
> --- a/tools/lib/api/fs/debugfs.h
> +++ b/tools/lib/api/fs/debugfs.h
> @@ -17,7 +17,4 @@ char *debugfs_mount(const char *mountpoint);
>
> extern char debugfs_mountpoint[];
>
> -int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename);
> -int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
> -
> #endif /* __API_DEBUGFS_H__ */
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 7acafb3c5592..03d1d74a5ede 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -442,6 +442,58 @@ void perf_debugfs_set_path(const char *mntpt)
> set_tracing_events_path("tracing/", mntpt);
> }
>
> +int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename)
> +{
> + char sbuf[128];
> +
> + switch (err) {
> + case ENOENT:
> + if (debugfs_configured()) {
> + snprintf(buf, size,
> + "Error:\tFile %s/%s not found.\n"
> + "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
> + debugfs_mountpoint, filename);
> + break;
> + }
> + snprintf(buf, size, "%s",
> + "Error:\tUnable to find debugfs\n"
> + "Hint:\tWas your kernel compiled with debugfs support?\n"
> + "Hint:\tIs the debugfs filesystem mounted?\n"
> + "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
> + break;
> + case EACCES: {
> + const char *mountpoint = debugfs_mountpoint;
> +
> + if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) {
> + const char *tracefs_mntpoint = tracefs_find_mountpoint();
> +
> + if (tracefs_mntpoint)
> + mountpoint = tracefs_mntpoint;
> + }
> +
> + snprintf(buf, size,
> + "Error:\tNo permissions to read %s/%s\n"
> + "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
> + debugfs_mountpoint, filename, mountpoint);
> + }
> + break;
> + default:
> + snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
> + break;
> + }
> +
> + return 0;
> +}
> +
> +int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
> +{
> + char path[PATH_MAX];
> +
> + snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*");
> +
> + return debugfs__strerror_open(err, buf, size, path);
> +}
> +
> char *get_tracing_file(const char *name)
> {
> char *file;
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 291be1d84bc3..da48c00ab0db 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -87,6 +87,8 @@ extern char tracing_path[];
> extern char tracing_events_path[];
> extern void perf_debugfs_set_path(const char *mountpoint);
> const char *perf_debugfs_mount(const char *mountpoint);
> +int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename);
> +int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
> char *get_tracing_file(const char *name);
> void put_tracing_file(char *file);
>
> --
> 2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/