aboutsummaryrefslogtreecommitdiff
path: root/hugeadm.c
diff options
context:
space:
mode:
authorEric B Munson <ebmunson@us.ibm.com>2009-01-07 10:06:03 +0000
committerEric B Munson <ebmunson@us.ibm.com>2009-01-08 12:54:50 +0000
commit1e3c6995c197659dfa036e2746c1e0f981a7c79e (patch)
treefb54a8be683957b5c4e558ca90bbd58bdff18412 /hugeadm.c
parent50ebd3a7eed9121b3f94f29af0dadf70314b5e95 (diff)
downloadlibhugetlbfs-1e3c6995c197659dfa036e2746c1e0f981a7c79e.tar.gz
Add --list-all-mounts option to hugeadm
This patch adds the ability to list all active hugetlbfs mount points to hugeadm. Mount points are printed with their mount options (anything that was specified with -o) so mount points for different page sizes can be easily identified. Signed-off-by: Eric B Munson <ebmunson@us.ibm.com> Reviewed-by: Mel Gorman <mel@csn.ul.ie>
Diffstat (limited to 'hugeadm.c')
-rw-r--r--hugeadm.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/hugeadm.c b/hugeadm.c
index a023786..81c53d9 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -28,6 +28,7 @@
#include <errno.h>
#include <string.h>
#include <limits.h>
+#include <mntent.h>
#define _GNU_SOURCE /* for getopt_long */
#include <unistd.h>
@@ -43,11 +44,18 @@ extern char *optarg;
#define OPTION(opts, text) fprintf(stderr, " %-25s %s\n", opts, text)
#define CONT(text) fprintf(stderr, " %-25s %s\n", "", text)
+#define PROCMOUNTS "/proc/mounts"
+#define FS_NAME "hugetlbfs"
+#define MIN_COL 20
+#define MAX_SIZE_MNTENT (64 + PATH_MAX + 32 + 128 + 2 * sizeof(int))
+#define FORMAT_LEN 20
+
void print_usage()
{
fprintf(stderr, "hugeadm [options]\n");
fprintf(stderr, "options:\n");
+ OPTION("--list-all-mounts", "List all current hugetlbfs mount points");
OPTION("--pool-list", "List all pools");
OPTION("--pool-pages-min <size>:[+|-]<count>", "");
CONT("Adjust pool 'size' lower bound");
@@ -67,6 +75,7 @@ int opt_dry_run = 0;
* getopts return values for options which are long only.
*/
#define LONG_POOL ('p' << 8)
+#define LONG_LIST_ALL_MOUNTS (LONG_POOL|'A')
#define LONG_POOL_LIST (LONG_POOL|'l')
#define LONG_POOL_MIN_ADJ (LONG_POOL|'m')
#define LONG_POOL_MAX_ADJ (LONG_POOL|'M')
@@ -105,6 +114,87 @@ void pool_list(void)
}
}
+struct mount_list
+{
+ struct mntent entry;
+ char data[MAX_SIZE_MNTENT];
+ struct mount_list *next;
+};
+
+void print_mounts(struct mount_list *current, int longest)
+{
+ char format_str[FORMAT_LEN];
+
+ snprintf(format_str, FORMAT_LEN, "%%-%ds %%s\n", longest);
+ printf(format_str, "Mount Point", "Options");
+ while (current) {
+ printf(format_str, current->entry.mnt_dir,
+ current->entry.mnt_opts);
+ current = current->next;
+ }
+}
+
+void mounts_list_all(void)
+{
+ FILE *mounts;
+ struct mount_list *list, *current, *previous = NULL;
+ int length, longest = MIN_COL;
+
+ /* First try /proc/mounts, then /etc/mtab */
+ mounts = setmntent(PROCMOUNTS, "r");
+ if (!mounts) {
+ mounts = setmntent(MOUNTED, "r");
+ if (!mounts) {
+ ERROR("unable to open %s or %s for reading",
+ PROCMOUNTS, MOUNTED);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ list = malloc(sizeof(struct mount_list));
+ if (!list) {
+ ERROR("out of memory");
+ exit(EXIT_FAILURE);
+ }
+
+ list->next = NULL;
+ current = list;
+ while (getmntent_r(mounts, &(current->entry), current->data, MAX_SIZE_MNTENT)) {
+ if (strcasecmp(current->entry.mnt_type, FS_NAME) == 0) {
+ length = strlen(current->entry.mnt_dir);
+ if (length > longest)
+ longest = length;
+
+ current->next = malloc(sizeof(struct mount_list));
+ if (!current->next) {
+ ERROR("out of memory");
+ exit(EXIT_FAILURE);
+ }
+ previous = current;
+ current = current->next;
+ current->next = NULL;
+ }
+ }
+
+ endmntent(mounts);
+
+ if (previous) {
+ free(previous->next);
+ previous->next = NULL;
+ print_mounts(list, longest);
+ } else {
+ /* No hugetlbfs mounts were found */
+ printf("No hugetlbfs mount point found.\n");
+ }
+
+ current = list;
+ while (current) {
+ previous = current;
+ current = current->next;
+ free(previous);
+ }
+}
+
enum {
POOL_MIN,
POOL_MAX,
@@ -256,6 +346,7 @@ int main(int argc, char** argv)
struct option long_opts[] = {
{"help", no_argument, NULL, 'h'},
+ {"list-all-mounts", no_argument, NULL, LONG_LIST_ALL_MOUNTS},
{"pool-list", no_argument, NULL, LONG_POOL_LIST},
{"pool-pages-min", required_argument, NULL, LONG_POOL_MIN_ADJ},
{"pool-pages-max", required_argument, NULL, LONG_POOL_MAX_ADJ},
@@ -294,6 +385,11 @@ int main(int argc, char** argv)
switch (ret) {
case -1:
break;
+
+ case LONG_LIST_ALL_MOUNTS:
+ mounts_list_all();
+ break;
+
case LONG_POOL_LIST:
pool_list();
break;