aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/api/fs
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2015-09-02 03:56:44 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-14 11:50:15 -0400
commit60a1133a5b39738671eff1e4d77bedc1ee3fa528 (patch)
tree646ab3b3dc8c42950b19f27e0b0f99bdfbf75833 /tools/lib/api/fs
parent4605eab3487dc818b1f3cbee2cd139cca3564be7 (diff)
tools lib api fs: Remove debugfs, tracefs and findfs objects
We have all the functionality in fs.c, let's remove unneeded objects. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Raphael Beamonte <raphael.beamonte@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1441180605-24737-15-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/api/fs')
-rw-r--r--tools/lib/api/fs/Build3
-rw-r--r--tools/lib/api/fs/debugfs.c77
-rw-r--r--tools/lib/api/fs/debugfs.h23
-rw-r--r--tools/lib/api/fs/findfs.c63
-rw-r--r--tools/lib/api/fs/findfs.h23
-rw-r--r--tools/lib/api/fs/tracefs.c78
-rw-r--r--tools/lib/api/fs/tracefs.h21
7 files changed, 0 insertions, 288 deletions
diff --git a/tools/lib/api/fs/Build b/tools/lib/api/fs/Build
index fa726f679b29..f4ed9629ae85 100644
--- a/tools/lib/api/fs/Build
+++ b/tools/lib/api/fs/Build
@@ -1,5 +1,2 @@
1libapi-y += fs.o 1libapi-y += fs.o
2libapi-y += tracing_path.o 2libapi-y += tracing_path.o
3libapi-y += debugfs.o
4libapi-y += findfs.o
5libapi-y += tracefs.o
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
deleted file mode 100644
index c707cfb32782..000000000000
--- a/tools/lib/api/fs/debugfs.c
+++ /dev/null
@@ -1,77 +0,0 @@
1#define _GNU_SOURCE
2#include <errno.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7#include <stdbool.h>
8#include <sys/vfs.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/mount.h>
12#include <linux/kernel.h>
13
14#include "debugfs.h"
15#include "tracefs.h"
16
17#ifndef DEBUGFS_DEFAULT_PATH
18#define DEBUGFS_DEFAULT_PATH "/sys/kernel/debug"
19#endif
20
21char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
22
23static const char * const debugfs_known_mountpoints[] = {
24 DEBUGFS_DEFAULT_PATH,
25 "/debug",
26 0,
27};
28
29static bool debugfs_found;
30
31bool debugfs_configured(void)
32{
33 return debugfs_find_mountpoint() != NULL;
34}
35
36/* find the path to the mounted debugfs */
37const char *debugfs_find_mountpoint(void)
38{
39 const char *ret;
40
41 if (debugfs_found)
42 return (const char *)debugfs_mountpoint;
43
44 ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
45 debugfs_mountpoint, PATH_MAX + 1,
46 debugfs_known_mountpoints);
47 if (ret)
48 debugfs_found = true;
49
50 return ret;
51}
52
53/* mount the debugfs somewhere if it's not mounted */
54char *debugfs_mount(const char *mountpoint)
55{
56 /* see if it's already mounted */
57 if (debugfs_find_mountpoint())
58 goto out;
59
60 /* if not mounted and no argument */
61 if (mountpoint == NULL) {
62 /* see if environment variable set */
63 mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
64 /* if no environment variable, use default */
65 if (mountpoint == NULL)
66 mountpoint = DEBUGFS_DEFAULT_PATH;
67 }
68
69 if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
70 return NULL;
71
72 /* save the mountpoint */
73 debugfs_found = true;
74 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
75out:
76 return debugfs_mountpoint;
77}
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
deleted file mode 100644
index 455023698d2b..000000000000
--- a/tools/lib/api/fs/debugfs.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef __API_DEBUGFS_H__
2#define __API_DEBUGFS_H__
3
4#include "findfs.h"
5
6#ifndef DEBUGFS_MAGIC
7#define DEBUGFS_MAGIC 0x64626720
8#endif
9
10#ifndef PERF_DEBUGFS_ENVIRONMENT
11#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
12#endif
13
14bool debugfs_configured(void);
15const char *debugfs_find_mountpoint(void);
16char *debugfs_mount(const char *mountpoint);
17
18extern char debugfs_mountpoint[];
19
20int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename);
21int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
22
23#endif /* __API_DEBUGFS_H__ */
diff --git a/tools/lib/api/fs/findfs.c b/tools/lib/api/fs/findfs.c
deleted file mode 100644
index 49946cb6d7af..000000000000
--- a/tools/lib/api/fs/findfs.c
+++ /dev/null
@@ -1,63 +0,0 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <stdbool.h>
6#include <sys/vfs.h>
7
8#include "findfs.h"
9
10/* verify that a mountpoint is actually the type we want */
11
12int valid_mountpoint(const char *mount, long magic)
13{
14 struct statfs st_fs;
15
16 if (statfs(mount, &st_fs) < 0)
17 return -ENOENT;
18 else if ((long)st_fs.f_type != magic)
19 return -ENOENT;
20
21 return 0;
22}
23
24/* find the path to a mounted file system */
25const char *find_mountpoint(const char *fstype, long magic,
26 char *mountpoint, int len,
27 const char * const *known_mountpoints)
28{
29 const char * const *ptr;
30 char format[128];
31 char type[100];
32 FILE *fp;
33
34 if (known_mountpoints) {
35 ptr = known_mountpoints;
36 while (*ptr) {
37 if (valid_mountpoint(*ptr, magic) == 0) {
38 strncpy(mountpoint, *ptr, len - 1);
39 mountpoint[len-1] = 0;
40 return mountpoint;
41 }
42 ptr++;
43 }
44 }
45
46 /* give up and parse /proc/mounts */
47 fp = fopen("/proc/mounts", "r");
48 if (fp == NULL)
49 return NULL;
50
51 snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);
52
53 while (fscanf(fp, format, mountpoint, type) == 2) {
54 if (strcmp(type, fstype) == 0)
55 break;
56 }
57 fclose(fp);
58
59 if (strcmp(type, fstype) != 0)
60 return NULL;
61
62 return mountpoint;
63}
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
deleted file mode 100644
index b6f5d05acc42..000000000000
--- a/tools/lib/api/fs/findfs.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef __API_FINDFS_H__
2#define __API_FINDFS_H__
3
4#include <stdbool.h>
5
6#define _STR(x) #x
7#define STR(x) _STR(x)
8
9/*
10 * On most systems <limits.h> would have given us this, but not on some systems
11 * (e.g. GNU/Hurd).
12 */
13#ifndef PATH_MAX
14#define PATH_MAX 4096
15#endif
16
17const char *find_mountpoint(const char *fstype, long magic,
18 char *mountpoint, int len,
19 const char * const *known_mountpoints);
20
21int valid_mountpoint(const char *mount, long magic);
22
23#endif /* __API_FINDFS_H__ */
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
deleted file mode 100644
index e4aa9688b71e..000000000000
--- a/tools/lib/api/fs/tracefs.c
+++ /dev/null
@@ -1,78 +0,0 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include <stdbool.h>
7#include <sys/vfs.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <sys/mount.h>
11#include <linux/kernel.h>
12
13#include "tracefs.h"
14
15#ifndef TRACEFS_DEFAULT_PATH
16#define TRACEFS_DEFAULT_PATH "/sys/kernel/tracing"
17#endif
18
19char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
20
21static const char * const tracefs_known_mountpoints[] = {
22 TRACEFS_DEFAULT_PATH,
23 "/sys/kernel/debug/tracing",
24 "/tracing",
25 "/trace",
26 0,
27};
28
29static bool tracefs_found;
30
31bool tracefs_configured(void)
32{
33 return tracefs_find_mountpoint() != NULL;
34}
35
36/* find the path to the mounted tracefs */
37const char *tracefs_find_mountpoint(void)
38{
39 const char *ret;
40
41 if (tracefs_found)
42 return (const char *)tracefs_mountpoint;
43
44 ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
45 tracefs_mountpoint, PATH_MAX + 1,
46 tracefs_known_mountpoints);
47
48 if (ret)
49 tracefs_found = true;
50
51 return ret;
52}
53
54/* mount the tracefs somewhere if it's not mounted */
55char *tracefs_mount(const char *mountpoint)
56{
57 /* see if it's already mounted */
58 if (tracefs_find_mountpoint())
59 goto out;
60
61 /* if not mounted and no argument */
62 if (mountpoint == NULL) {
63 /* see if environment variable set */
64 mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
65 /* if no environment variable, use default */
66 if (mountpoint == NULL)
67 mountpoint = TRACEFS_DEFAULT_PATH;
68 }
69
70 if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
71 return NULL;
72
73 /* save the mountpoint */
74 tracefs_found = true;
75 strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
76out:
77 return tracefs_mountpoint;
78}
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
deleted file mode 100644
index da780ac49acb..000000000000
--- a/tools/lib/api/fs/tracefs.h
+++ /dev/null
@@ -1,21 +0,0 @@
1#ifndef __API_TRACEFS_H__
2#define __API_TRACEFS_H__
3
4#include "findfs.h"
5
6#ifndef TRACEFS_MAGIC
7#define TRACEFS_MAGIC 0x74726163
8#endif
9
10#ifndef PERF_TRACEFS_ENVIRONMENT
11#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
12#endif
13
14bool tracefs_configured(void);
15const char *tracefs_find_mountpoint(void);
16int tracefs_valid_mountpoint(const char *debugfs);
17char *tracefs_mount(const char *mountpoint);
18
19extern char tracefs_mountpoint[];
20
21#endif /* __API_DEBUGFS_H__ */