tools lib api debugfs: Check for tracefs when reporting errors
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jul 2015 11:51:41 +0000 (08:51 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jul 2015 15:22:14 +0000 (12:22 -0300)
Now that we have two mountpoints, one for debugfs and another, for
tracefs, we end up needing to check permissions for both, so, on
a system with default config we were always asking the user to
check the permission of the debugfs mountpoint, even when it was
already sufficient. Fix it.

E.g.:

  $ trace -e nanosleep usleep 1
  Error: No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
  Hint:  Try 'sudo mount -o remount,mode=755 /sys/kernel/debug'

  $ sudo mount -o remount,mode=755 /sys/kernel/debug
  $ trace -e nanosleep usleep 1
  Error: No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
  Hint:  Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing'

  $ sudo mount -o remount,mode=755 /sys/kernel/debug/tracing
  $ trace -e nanosleep usleep 1
     0.326 ( 0.061 ms): usleep/11961 nanosleep(rqtp: 0x7ffef1081c50) = 0
  $

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-0viljeuhc7q84ic8kobsna43@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/api/fs/debugfs.c

index 8305b3e9d48e29da0152592524af2e364a3b92f9..eb7cf4d18f8a0e60e04ab2799aa921586f800b24 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kernel.h>
 
 #include "debugfs.h"
+#include "tracefs.h"
 
 #ifndef DEBUGFS_DEFAULT_PATH
 #define DEBUGFS_DEFAULT_PATH           "/sys/kernel/debug"
@@ -94,11 +95,21 @@ int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename
                         "Hint:\tIs the debugfs filesystem mounted?\n"
                         "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
                break;
-       case EACCES:
+       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, debugfs_mountpoint);
+                        debugfs_mountpoint, filename, mountpoint);
+       }
                break;
        default:
                snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));