Commit db1806edcfef007d9594435a331dcf7e7f1b8fac
Committed by
Arnaldo Carvalho de Melo
1 parent
25cd480e44
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
perf tools: Fix statfs.f_type data type mismatch build error with uclibc
ARC Linux uses the no legacy syscalls abi and corresponding uClibc headers statfs defines f_type to be U32 which causes perf build breakage http://git.uclibc.org/uClibc/tree/libc/sysdeps/linux/common-generic/bits/statfs.h ----------->8--------------- CC fs/fs.o fs/fs.c: In function 'fs__valid_mount': fs/fs.c:82:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] else if (st_fs.f_type != magic) ^ cc1: all warnings being treated as errors ----------->8--------------- Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Borislav Petkov <bp@suse.de> Cc: Cody P Schafer <dev@codyps.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Vineet Gupta <Vineet.Gupta1@synopsys.com> Link: http://lkml.kernel.org/r/1420888254-17504-2-git-send-email-vgupta@synopsys.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Showing 2 changed files with 2 additions and 2 deletions Inline Diff
tools/lib/api/fs/debugfs.c
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <sys/vfs.h> | 6 | #include <sys/vfs.h> |
7 | #include <sys/mount.h> | 7 | #include <sys/mount.h> |
8 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
9 | 9 | ||
10 | #include "debugfs.h" | 10 | #include "debugfs.h" |
11 | 11 | ||
12 | char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; | 12 | char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; |
13 | 13 | ||
14 | static const char * const debugfs_known_mountpoints[] = { | 14 | static const char * const debugfs_known_mountpoints[] = { |
15 | "/sys/kernel/debug", | 15 | "/sys/kernel/debug", |
16 | "/debug", | 16 | "/debug", |
17 | 0, | 17 | 0, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | static bool debugfs_found; | 20 | static bool debugfs_found; |
21 | 21 | ||
22 | /* find the path to the mounted debugfs */ | 22 | /* find the path to the mounted debugfs */ |
23 | const char *debugfs_find_mountpoint(void) | 23 | const char *debugfs_find_mountpoint(void) |
24 | { | 24 | { |
25 | const char * const *ptr; | 25 | const char * const *ptr; |
26 | char type[100]; | 26 | char type[100]; |
27 | FILE *fp; | 27 | FILE *fp; |
28 | 28 | ||
29 | if (debugfs_found) | 29 | if (debugfs_found) |
30 | return (const char *)debugfs_mountpoint; | 30 | return (const char *)debugfs_mountpoint; |
31 | 31 | ||
32 | ptr = debugfs_known_mountpoints; | 32 | ptr = debugfs_known_mountpoints; |
33 | while (*ptr) { | 33 | while (*ptr) { |
34 | if (debugfs_valid_mountpoint(*ptr) == 0) { | 34 | if (debugfs_valid_mountpoint(*ptr) == 0) { |
35 | debugfs_found = true; | 35 | debugfs_found = true; |
36 | strcpy(debugfs_mountpoint, *ptr); | 36 | strcpy(debugfs_mountpoint, *ptr); |
37 | return debugfs_mountpoint; | 37 | return debugfs_mountpoint; |
38 | } | 38 | } |
39 | ptr++; | 39 | ptr++; |
40 | } | 40 | } |
41 | 41 | ||
42 | /* give up and parse /proc/mounts */ | 42 | /* give up and parse /proc/mounts */ |
43 | fp = fopen("/proc/mounts", "r"); | 43 | fp = fopen("/proc/mounts", "r"); |
44 | if (fp == NULL) | 44 | if (fp == NULL) |
45 | return NULL; | 45 | return NULL; |
46 | 46 | ||
47 | while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", | 47 | while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", |
48 | debugfs_mountpoint, type) == 2) { | 48 | debugfs_mountpoint, type) == 2) { |
49 | if (strcmp(type, "debugfs") == 0) | 49 | if (strcmp(type, "debugfs") == 0) |
50 | break; | 50 | break; |
51 | } | 51 | } |
52 | fclose(fp); | 52 | fclose(fp); |
53 | 53 | ||
54 | if (strcmp(type, "debugfs") != 0) | 54 | if (strcmp(type, "debugfs") != 0) |
55 | return NULL; | 55 | return NULL; |
56 | 56 | ||
57 | debugfs_found = true; | 57 | debugfs_found = true; |
58 | 58 | ||
59 | return debugfs_mountpoint; | 59 | return debugfs_mountpoint; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* verify that a mountpoint is actually a debugfs instance */ | 62 | /* verify that a mountpoint is actually a debugfs instance */ |
63 | 63 | ||
64 | int debugfs_valid_mountpoint(const char *debugfs) | 64 | int debugfs_valid_mountpoint(const char *debugfs) |
65 | { | 65 | { |
66 | struct statfs st_fs; | 66 | struct statfs st_fs; |
67 | 67 | ||
68 | if (statfs(debugfs, &st_fs) < 0) | 68 | if (statfs(debugfs, &st_fs) < 0) |
69 | return -ENOENT; | 69 | return -ENOENT; |
70 | else if (st_fs.f_type != (long) DEBUGFS_MAGIC) | 70 | else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC) |
71 | return -ENOENT; | 71 | return -ENOENT; |
72 | 72 | ||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | /* mount the debugfs somewhere if it's not mounted */ | 76 | /* mount the debugfs somewhere if it's not mounted */ |
77 | char *debugfs_mount(const char *mountpoint) | 77 | char *debugfs_mount(const char *mountpoint) |
78 | { | 78 | { |
79 | /* see if it's already mounted */ | 79 | /* see if it's already mounted */ |
80 | if (debugfs_find_mountpoint()) | 80 | if (debugfs_find_mountpoint()) |
81 | goto out; | 81 | goto out; |
82 | 82 | ||
83 | /* if not mounted and no argument */ | 83 | /* if not mounted and no argument */ |
84 | if (mountpoint == NULL) { | 84 | if (mountpoint == NULL) { |
85 | /* see if environment variable set */ | 85 | /* see if environment variable set */ |
86 | mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT); | 86 | mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT); |
87 | /* if no environment variable, use default */ | 87 | /* if no environment variable, use default */ |
88 | if (mountpoint == NULL) | 88 | if (mountpoint == NULL) |
89 | mountpoint = "/sys/kernel/debug"; | 89 | mountpoint = "/sys/kernel/debug"; |
90 | } | 90 | } |
91 | 91 | ||
92 | if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) | 92 | if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) |
93 | return NULL; | 93 | return NULL; |
94 | 94 | ||
95 | /* save the mountpoint */ | 95 | /* save the mountpoint */ |
96 | debugfs_found = true; | 96 | debugfs_found = true; |
97 | strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); | 97 | strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); |
98 | out: | 98 | out: |
99 | return debugfs_mountpoint; | 99 | return debugfs_mountpoint; |
100 | } | 100 | } |
101 | 101 |
tools/lib/api/fs/fs.c
1 | /* TODO merge/factor in debugfs.c here */ | 1 | /* TODO merge/factor in debugfs.c here */ |
2 | 2 | ||
3 | #include <ctype.h> | 3 | #include <ctype.h> |
4 | #include <errno.h> | 4 | #include <errno.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <sys/vfs.h> | 9 | #include <sys/vfs.h> |
10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
11 | #include <sys/stat.h> | 11 | #include <sys/stat.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <unistd.h> | 13 | #include <unistd.h> |
14 | 14 | ||
15 | #include "debugfs.h" | 15 | #include "debugfs.h" |
16 | #include "fs.h" | 16 | #include "fs.h" |
17 | 17 | ||
18 | static const char * const sysfs__fs_known_mountpoints[] = { | 18 | static const char * const sysfs__fs_known_mountpoints[] = { |
19 | "/sys", | 19 | "/sys", |
20 | 0, | 20 | 0, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | static const char * const procfs__known_mountpoints[] = { | 23 | static const char * const procfs__known_mountpoints[] = { |
24 | "/proc", | 24 | "/proc", |
25 | 0, | 25 | 0, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | struct fs { | 28 | struct fs { |
29 | const char *name; | 29 | const char *name; |
30 | const char * const *mounts; | 30 | const char * const *mounts; |
31 | char path[PATH_MAX + 1]; | 31 | char path[PATH_MAX + 1]; |
32 | bool found; | 32 | bool found; |
33 | long magic; | 33 | long magic; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | enum { | 36 | enum { |
37 | FS__SYSFS = 0, | 37 | FS__SYSFS = 0, |
38 | FS__PROCFS = 1, | 38 | FS__PROCFS = 1, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static struct fs fs__entries[] = { | 41 | static struct fs fs__entries[] = { |
42 | [FS__SYSFS] = { | 42 | [FS__SYSFS] = { |
43 | .name = "sysfs", | 43 | .name = "sysfs", |
44 | .mounts = sysfs__fs_known_mountpoints, | 44 | .mounts = sysfs__fs_known_mountpoints, |
45 | .magic = SYSFS_MAGIC, | 45 | .magic = SYSFS_MAGIC, |
46 | }, | 46 | }, |
47 | [FS__PROCFS] = { | 47 | [FS__PROCFS] = { |
48 | .name = "proc", | 48 | .name = "proc", |
49 | .mounts = procfs__known_mountpoints, | 49 | .mounts = procfs__known_mountpoints, |
50 | .magic = PROC_SUPER_MAGIC, | 50 | .magic = PROC_SUPER_MAGIC, |
51 | }, | 51 | }, |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static bool fs__read_mounts(struct fs *fs) | 54 | static bool fs__read_mounts(struct fs *fs) |
55 | { | 55 | { |
56 | bool found = false; | 56 | bool found = false; |
57 | char type[100]; | 57 | char type[100]; |
58 | FILE *fp; | 58 | FILE *fp; |
59 | 59 | ||
60 | fp = fopen("/proc/mounts", "r"); | 60 | fp = fopen("/proc/mounts", "r"); |
61 | if (fp == NULL) | 61 | if (fp == NULL) |
62 | return NULL; | 62 | return NULL; |
63 | 63 | ||
64 | while (!found && | 64 | while (!found && |
65 | fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", | 65 | fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", |
66 | fs->path, type) == 2) { | 66 | fs->path, type) == 2) { |
67 | 67 | ||
68 | if (strcmp(type, fs->name) == 0) | 68 | if (strcmp(type, fs->name) == 0) |
69 | found = true; | 69 | found = true; |
70 | } | 70 | } |
71 | 71 | ||
72 | fclose(fp); | 72 | fclose(fp); |
73 | return fs->found = found; | 73 | return fs->found = found; |
74 | } | 74 | } |
75 | 75 | ||
76 | static int fs__valid_mount(const char *fs, long magic) | 76 | static int fs__valid_mount(const char *fs, long magic) |
77 | { | 77 | { |
78 | struct statfs st_fs; | 78 | struct statfs st_fs; |
79 | 79 | ||
80 | if (statfs(fs, &st_fs) < 0) | 80 | if (statfs(fs, &st_fs) < 0) |
81 | return -ENOENT; | 81 | return -ENOENT; |
82 | else if (st_fs.f_type != magic) | 82 | else if ((long)st_fs.f_type != magic) |
83 | return -ENOENT; | 83 | return -ENOENT; |
84 | 84 | ||
85 | return 0; | 85 | return 0; |
86 | } | 86 | } |
87 | 87 | ||
88 | static bool fs__check_mounts(struct fs *fs) | 88 | static bool fs__check_mounts(struct fs *fs) |
89 | { | 89 | { |
90 | const char * const *ptr; | 90 | const char * const *ptr; |
91 | 91 | ||
92 | ptr = fs->mounts; | 92 | ptr = fs->mounts; |
93 | while (*ptr) { | 93 | while (*ptr) { |
94 | if (fs__valid_mount(*ptr, fs->magic) == 0) { | 94 | if (fs__valid_mount(*ptr, fs->magic) == 0) { |
95 | fs->found = true; | 95 | fs->found = true; |
96 | strcpy(fs->path, *ptr); | 96 | strcpy(fs->path, *ptr); |
97 | return true; | 97 | return true; |
98 | } | 98 | } |
99 | ptr++; | 99 | ptr++; |
100 | } | 100 | } |
101 | 101 | ||
102 | return false; | 102 | return false; |
103 | } | 103 | } |
104 | 104 | ||
105 | static void mem_toupper(char *f, size_t len) | 105 | static void mem_toupper(char *f, size_t len) |
106 | { | 106 | { |
107 | while (len) { | 107 | while (len) { |
108 | *f = toupper(*f); | 108 | *f = toupper(*f); |
109 | f++; | 109 | f++; |
110 | len--; | 110 | len--; |
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | /* | 114 | /* |
115 | * Check for "NAME_PATH" environment variable to override fs location (for | 115 | * Check for "NAME_PATH" environment variable to override fs location (for |
116 | * testing). This matches the recommendation in Documentation/sysfs-rules.txt | 116 | * testing). This matches the recommendation in Documentation/sysfs-rules.txt |
117 | * for SYSFS_PATH. | 117 | * for SYSFS_PATH. |
118 | */ | 118 | */ |
119 | static bool fs__env_override(struct fs *fs) | 119 | static bool fs__env_override(struct fs *fs) |
120 | { | 120 | { |
121 | char *override_path; | 121 | char *override_path; |
122 | size_t name_len = strlen(fs->name); | 122 | size_t name_len = strlen(fs->name); |
123 | /* name + "_PATH" + '\0' */ | 123 | /* name + "_PATH" + '\0' */ |
124 | char upper_name[name_len + 5 + 1]; | 124 | char upper_name[name_len + 5 + 1]; |
125 | memcpy(upper_name, fs->name, name_len); | 125 | memcpy(upper_name, fs->name, name_len); |
126 | mem_toupper(upper_name, name_len); | 126 | mem_toupper(upper_name, name_len); |
127 | strcpy(&upper_name[name_len], "_PATH"); | 127 | strcpy(&upper_name[name_len], "_PATH"); |
128 | 128 | ||
129 | override_path = getenv(upper_name); | 129 | override_path = getenv(upper_name); |
130 | if (!override_path) | 130 | if (!override_path) |
131 | return false; | 131 | return false; |
132 | 132 | ||
133 | fs->found = true; | 133 | fs->found = true; |
134 | strncpy(fs->path, override_path, sizeof(fs->path)); | 134 | strncpy(fs->path, override_path, sizeof(fs->path)); |
135 | return true; | 135 | return true; |
136 | } | 136 | } |
137 | 137 | ||
138 | static const char *fs__get_mountpoint(struct fs *fs) | 138 | static const char *fs__get_mountpoint(struct fs *fs) |
139 | { | 139 | { |
140 | if (fs__env_override(fs)) | 140 | if (fs__env_override(fs)) |
141 | return fs->path; | 141 | return fs->path; |
142 | 142 | ||
143 | if (fs__check_mounts(fs)) | 143 | if (fs__check_mounts(fs)) |
144 | return fs->path; | 144 | return fs->path; |
145 | 145 | ||
146 | if (fs__read_mounts(fs)) | 146 | if (fs__read_mounts(fs)) |
147 | return fs->path; | 147 | return fs->path; |
148 | 148 | ||
149 | return NULL; | 149 | return NULL; |
150 | } | 150 | } |
151 | 151 | ||
152 | static const char *fs__mountpoint(int idx) | 152 | static const char *fs__mountpoint(int idx) |
153 | { | 153 | { |
154 | struct fs *fs = &fs__entries[idx]; | 154 | struct fs *fs = &fs__entries[idx]; |
155 | 155 | ||
156 | if (fs->found) | 156 | if (fs->found) |
157 | return (const char *)fs->path; | 157 | return (const char *)fs->path; |
158 | 158 | ||
159 | return fs__get_mountpoint(fs); | 159 | return fs__get_mountpoint(fs); |
160 | } | 160 | } |
161 | 161 | ||
162 | #define FS__MOUNTPOINT(name, idx) \ | 162 | #define FS__MOUNTPOINT(name, idx) \ |
163 | const char *name##__mountpoint(void) \ | 163 | const char *name##__mountpoint(void) \ |
164 | { \ | 164 | { \ |
165 | return fs__mountpoint(idx); \ | 165 | return fs__mountpoint(idx); \ |
166 | } | 166 | } |
167 | 167 | ||
168 | FS__MOUNTPOINT(sysfs, FS__SYSFS); | 168 | FS__MOUNTPOINT(sysfs, FS__SYSFS); |
169 | FS__MOUNTPOINT(procfs, FS__PROCFS); | 169 | FS__MOUNTPOINT(procfs, FS__PROCFS); |
170 | 170 | ||
171 | int filename__read_int(const char *filename, int *value) | 171 | int filename__read_int(const char *filename, int *value) |
172 | { | 172 | { |
173 | char line[64]; | 173 | char line[64]; |
174 | int fd = open(filename, O_RDONLY), err = -1; | 174 | int fd = open(filename, O_RDONLY), err = -1; |
175 | 175 | ||
176 | if (fd < 0) | 176 | if (fd < 0) |
177 | return -1; | 177 | return -1; |
178 | 178 | ||
179 | if (read(fd, line, sizeof(line)) > 0) { | 179 | if (read(fd, line, sizeof(line)) > 0) { |
180 | *value = atoi(line); | 180 | *value = atoi(line); |
181 | err = 0; | 181 | err = 0; |
182 | } | 182 | } |
183 | 183 | ||
184 | close(fd); | 184 | close(fd); |
185 | return err; | 185 | return err; |
186 | } | 186 | } |
187 | 187 | ||
188 | int sysctl__read_int(const char *sysctl, int *value) | 188 | int sysctl__read_int(const char *sysctl, int *value) |
189 | { | 189 | { |
190 | char path[PATH_MAX]; | 190 | char path[PATH_MAX]; |
191 | const char *procfs = procfs__mountpoint(); | 191 | const char *procfs = procfs__mountpoint(); |
192 | 192 | ||
193 | if (!procfs) | 193 | if (!procfs) |
194 | return -1; | 194 | return -1; |
195 | 195 | ||
196 | snprintf(path, sizeof(path), "%s/sys/%s", procfs, sysctl); | 196 | snprintf(path, sizeof(path), "%s/sys/%s", procfs, sysctl); |
197 | 197 | ||
198 | return filename__read_int(path, value); | 198 | return filename__read_int(path, value); |
199 | } | 199 | } |
200 | 200 |