Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
988bdb31 592d5a6b

+60 -54
-52
tools/lib/api/fs/debugfs.c
··· 75 75 out: 76 76 return debugfs_mountpoint; 77 77 } 78 - 79 - int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename) 80 - { 81 - char sbuf[128]; 82 - 83 - switch (err) { 84 - case ENOENT: 85 - if (debugfs_found) { 86 - snprintf(buf, size, 87 - "Error:\tFile %s/%s not found.\n" 88 - "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n", 89 - debugfs_mountpoint, filename); 90 - break; 91 - } 92 - snprintf(buf, size, "%s", 93 - "Error:\tUnable to find debugfs\n" 94 - "Hint:\tWas your kernel compiled with debugfs support?\n" 95 - "Hint:\tIs the debugfs filesystem mounted?\n" 96 - "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'"); 97 - break; 98 - case EACCES: { 99 - const char *mountpoint = debugfs_mountpoint; 100 - 101 - if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) { 102 - const char *tracefs_mntpoint = tracefs_find_mountpoint(); 103 - 104 - if (tracefs_mntpoint) 105 - mountpoint = tracefs_mntpoint; 106 - } 107 - 108 - snprintf(buf, size, 109 - "Error:\tNo permissions to read %s/%s\n" 110 - "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n", 111 - debugfs_mountpoint, filename, mountpoint); 112 - } 113 - break; 114 - default: 115 - snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf))); 116 - break; 117 - } 118 - 119 - return 0; 120 - } 121 - 122 - int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name) 123 - { 124 - char path[PATH_MAX]; 125 - 126 - snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*"); 127 - 128 - return debugfs__strerror_open(err, buf, size, path); 129 - }
+54
tools/lib/api/fs/tracing_path.c
··· 5 5 #include <stdio.h> 6 6 #include <stdlib.h> 7 7 #include <string.h> 8 + #include <errno.h> 9 + #include <unistd.h> 8 10 #include "debugfs.h" 9 11 #include "tracefs.h" 10 12 ··· 82 80 void put_tracing_file(char *file) 83 81 { 84 82 free(file); 83 + } 84 + 85 + static int strerror_open(int err, char *buf, size_t size, const char *filename) 86 + { 87 + char sbuf[128]; 88 + 89 + switch (err) { 90 + case ENOENT: 91 + if (debugfs_configured()) { 92 + snprintf(buf, size, 93 + "Error:\tFile %s/%s not found.\n" 94 + "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n", 95 + debugfs_mountpoint, filename); 96 + break; 97 + } 98 + snprintf(buf, size, "%s", 99 + "Error:\tUnable to find debugfs\n" 100 + "Hint:\tWas your kernel compiled with debugfs support?\n" 101 + "Hint:\tIs the debugfs filesystem mounted?\n" 102 + "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'"); 103 + break; 104 + case EACCES: { 105 + const char *mountpoint = debugfs_mountpoint; 106 + 107 + if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) { 108 + const char *tracefs_mntpoint = tracefs_find_mountpoint(); 109 + 110 + if (tracefs_mntpoint) 111 + mountpoint = tracefs_mntpoint; 112 + } 113 + 114 + snprintf(buf, size, 115 + "Error:\tNo permissions to read %s/%s\n" 116 + "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n", 117 + debugfs_mountpoint, filename, mountpoint); 118 + } 119 + break; 120 + default: 121 + snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf))); 122 + break; 123 + } 124 + 125 + return 0; 126 + } 127 + 128 + int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name) 129 + { 130 + char path[PATH_MAX]; 131 + 132 + snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*"); 133 + 134 + return strerror_open(err, buf, size, path); 85 135 }
+3
tools/lib/api/fs/tracing_path.h
··· 1 1 #ifndef __API_FS_TRACING_PATH_H 2 2 #define __API_FS_TRACING_PATH_H 3 3 4 + #include <linux/types.h> 5 + 4 6 extern char tracing_path[]; 5 7 extern char tracing_events_path[]; 6 8 ··· 12 10 char *get_tracing_file(const char *name); 13 11 void put_tracing_file(char *file); 14 12 13 + int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name); 15 14 #endif /* __API_FS_TRACING_PATH_H */
+3 -2
tools/perf/builtin-trace.c
··· 17 17 */ 18 18 19 19 #include <traceevent/event-parse.h> 20 + #include <api/fs/tracing_path.h> 20 21 #include "builtin.h" 21 22 #include "util/color.h" 22 23 #include "util/debug.h" ··· 2687 2686 char errbuf[BUFSIZ]; 2688 2687 2689 2688 out_error_sched_stat_runtime: 2690 - debugfs__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime"); 2689 + tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime"); 2691 2690 goto out_error; 2692 2691 2693 2692 out_error_raw_syscalls: 2694 - debugfs__strerror_open_tp(errno, errbuf, sizeof(errbuf), "raw_syscalls", "sys_(enter|exit)"); 2693 + tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "raw_syscalls", "sys_(enter|exit)"); 2695 2694 goto out_error; 2696 2695 2697 2696 out_error_mmap: