43 #include <sys/types.h> 51 u8 * file_name),
void *arg,
59 d = opendir (dir_name);
75 if (e->d_type == DT_DIR
76 && (!strcmp (e->d_name,
".") || !strcmp (e->d_name,
"..")))
81 if (e->d_type == DT_DIR)
85 s =
format (s,
"%s/%s", dir_name, e->d_name);
86 t =
format (t,
"%s", e->d_name);
87 error = f (arg, s, t);
108 fd = open (file_name, O_WRONLY);
117 if (write (fd, s,
vec_len (s)) < 0)
134 fd = open (file_name, O_RDONLY);
140 sz = read (fd, s,
vec_len (s));
173 r = readlink (link, buffer,
sizeof (buffer) - 1);
179 p = strrchr (buffer,
'/');
199 p =
format (p,
"/sys/devices/system/node/node%u%c", numa_node, 0);
201 if (stat ((
char *) p, &sb) == 0)
203 if (S_ISDIR (sb.st_mode) == 0)
206 else if (numa_node == 0)
209 p =
format (p,
"/sys/kernel/mm%c", 0);
210 if (stat ((
char *) p, &sb) < 0 || S_ISDIR (sb.st_mode) == 0)
217 p =
format (p,
"/hugepages/hugepages-%ukB/free_hugepages%c", page_size, 0);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
clib_error_t * vlib_sysfs_write(char *file_name, char *fmt,...)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u8 * vlib_sysfs_link_to_name(char *link)
#define clib_error_return(e, args...)
int vlib_sysfs_get_free_hugepages(unsigned int numa_node, int page_size)
#define clib_error_return_unix(e, args...)
clib_error_t * vlib_sysfs_read(char *file_name, char *fmt,...)
#define vec_free(V)
Free vector's memory (no header).
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)