From: Eric Munson <emun...@bert.localdomain>

This patch adds the ability to list active hugetlbfs mount points to hugeadm.
Mount points are printed with their mount options (anything that was
specified with -o) so mount points for page different page sizes can be
easily identified.

Signed-off-by: Eric B Munson <ebmun...@us.ibm.com>
---
 hugeadm.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/hugeadm.c b/hugeadm.c
index a023786..5e93fab 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,15 @@ extern char *optarg;
 #define OPTION(opts, text)     fprintf(stderr, " %-25s  %s\n", opts, text)
 #define CONT(text)             fprintf(stderr, " %-25s  %s\n", "", text)
 
+#define MTAB "/etc/mtab"
+#define FS_NAME "hugetlbfs"
+
 void print_usage()
 {
        fprintf(stderr, "hugeadm [options]\n");
        fprintf(stderr, "options:\n");
 
+       OPTION("--mounts-list", "List all cuurent hugetlbfs mount points");
        OPTION("--pool-list", "List all pools");
        OPTION("--pool-pages-min <size>:[+|-]<count>", "");
        CONT("Adjust pool 'size' lower bound");
@@ -67,6 +72,7 @@ int opt_dry_run = 0;
  * getopts return values for options which are long only.
  */
 #define LONG_POOL              ('p' << 8)
+#define LONG_MOUNT_LIST                (LONG_POOL|'S')
 #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 +111,26 @@ void pool_list(void)
        }
 }
 
+void mount_list(void)
+{
+       FILE *mtab;
+       struct mntent *ent;
+
+       mtab = setmntent(MTAB, "r");
+       if (!mtab) {
+               ERROR("unable to open %s for reading", MTAB);
+               exit(EXIT_FAILURE);
+       }
+
+       printf("Mount Point               Options\n");
+       while ((ent = getmntent(mtab))) {
+               if (strcasecmp(FS_NAME, ent->mnt_type) == 0)
+                       printf("%-25s %s\n", ent->mnt_dir, ent->mnt_opts);
+       }
+
+       endmntent(mtab);
+}
+
 enum {
        POOL_MIN,
        POOL_MAX,
@@ -256,6 +282,7 @@ int main(int argc, char** argv)
        struct option long_opts[] = {
                {"help",       no_argument, NULL, 'h'},
 
+               {"mounts-list", no_argument, NULL, LONG_MOUNT_LIST},
                {"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 +321,11 @@ int main(int argc, char** argv)
                switch (ret) {
                case -1:
                        break;
+
+               case LONG_MOUNT_LIST:
+                       mount_list();
+                       break;
+
                case LONG_POOL_LIST:
                        pool_list();
                        break;
-- 
1.6.0.4


------------------------------------------------------------------------------
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to