The --create-group-mounts option takes a group name as an
argument and creates a subdir to /var/lib/hugetlbfs/ with
that group name.  It then creates a mount point for each
available huge page size under that directory with mode
070, mounts it with the appropriate pagesize argument and
chowns it to the specified group.

The --create-user-mounts option does the same as the
group-mounts option except it takes a username, the
mode is 700, and it is chowned to the specified user.

Signed-off-by: Eric B Munson <ebmun...@us.ibm.com>
---
Changes from V2:
Update hugeadm man page with new options

Changes from V1:
Ensure that the base MOUNTS_DIR is readable by all

 hugeadm.c     |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 man/hugeadm.8 |   16 +++++++++++
 2 files changed, 91 insertions(+), 6 deletions(-)

diff --git a/hugeadm.c b/hugeadm.c
index 9a98e7d..4f6e552 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -30,6 +30,8 @@
 #include <limits.h>
 #include <mntent.h>
 #include <unistd.h>
+#include <grp.h>
+#include <pwd.h>
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -71,6 +73,14 @@ void print_usage()
        CONT("Adjust pool 'size' upper bound");
        OPTION("--create-mounts", "Creates a mount point for each available");
        CONT("huge page size on this system under /var/lib/hugetlbfs");
+       OPTION("--create-group-mounts <group>", "");
+       CONT("Creates a mount point for each available huge");
+       CONT("page size under /var/lib/hugetlbfs/<group>");
+       CONT("for user by <group>");
+       OPTION("--create-user-mounts <user>", "");
+       CONT("Creates a mount point for each available huge");
+       CONT("page size under /var/lib/hugetlbfs/<user>");
+       CONT("for use by <user>");
 
        OPTION("--page-sizes", "Display page sizes that a configured pool");
        OPTION("--page-sizes-all",
@@ -93,9 +103,12 @@ int opt_dry_run = 0;
 #define LONG_PAGE_SIZES        (LONG_PAGE|'s')
 #define LONG_PAGE_AVAIL        (LONG_PAGE|'a')
 
-#define LONG_MOUNTS            ('m' << 8)
-#define LONG_CREATE_MOUNTS     (LONG_MOUNTS|'C')
-#define LONG_LIST_ALL_MOUNTS   (LONG_MOUNTS|'A')
+#define LONG_MOUNTS                    ('m' << 8)
+#define LONG_CREATE_MOUNTS             (LONG_MOUNTS|'C')
+#define LONG_CREATE_GROUP_MOUNTS       (LONG_MOUNTS|'G')
+#define LONG_CREATE_USER_MOUNTS                (LONG_MOUNTS|'U')
+#define LONG_LIST_ALL_MOUNTS           (LONG_MOUNTS|'A')
+
 
 #define MAX_POOLS      32
 
@@ -236,7 +249,7 @@ int ensure_dir(char *path)
        return 0;
 }
 
-void create_mounts(void)
+void create_mounts(char *base, uid_t user, gid_t group)
 {
        struct hpage_pool pools[MAX_POOLS];
        char path[PATH_MAX];
@@ -254,11 +267,21 @@ void create_mounts(void)
                exit(EXIT_FAILURE);
        }
 
+       ensure_dir(base);
+       if (user != -1) {
+               chown(base, user, group);
+               chmod(base, S_IRUSR | S_IWUSR | S_IXUSR );
+       }
+       if ( group != -1) {
+               chown(base, user, group);
+               chmod(base, S_ISGID | S_IRGRP | S_IWGRP | S_IXGRP );
+       }
+
        qsort(pools, cnt, sizeof(pools[0]), cmpsizes);
 
        for (pos = 0; cnt--; pos++) {
                snprintf(path, PATH_MAX, "%s/pagesize-%ld",
-                               MOUNT_DIR, pools[pos].pagesize);
+                               base, pools[pos].pagesize);
                snprintf(options, ARG_MAX, "pagesize=%ld",
                                pools[pos].pagesize);
                if (ensure_dir(path)) {
@@ -272,6 +295,15 @@ void create_mounts(void)
                                path, strerror(errno));
                        exit(EXIT_FAILURE);
                }
+
+               if (user != -1) {
+                       chown(path, user, group);
+                       chmod(path, S_IRUSR | S_IWUSR | S_IXUSR );
+               }
+               if ( group != -1) {
+                       chown(path, user, group);
+                       chmod(path, S_ISGID | S_IRGRP | S_IWGRP | S_IXGRP );
+               }
        }
 }
 
@@ -420,6 +452,9 @@ int main(int argc, char** argv)
 {
        int ops;
        int has_hugepages = kernel_has_hugepages();
+       char path[PATH_MAX];
+       struct group *grp;
+       struct passwd *pwd;
 
        char opts[] = "+h";
        int ret = 0, index = 0;
@@ -431,6 +466,8 @@ int main(int argc, char** argv)
                {"pool-pages-min", required_argument, NULL, LONG_POOL_MIN_ADJ},
                {"pool-pages-max", required_argument, NULL, LONG_POOL_MAX_ADJ},
                {"create-mounts", no_argument, NULL, LONG_CREATE_MOUNTS},
+               {"create-group-mounts", required_argument, NULL, 
LONG_CREATE_GROUP_MOUNTS},
+               {"create-user-mounts", required_argument, NULL, 
LONG_CREATE_USER_MOUNTS},
 
                {"page-sizes", no_argument, NULL, LONG_PAGE_SIZES},
                {"page-sizes-all", no_argument, NULL, LONG_PAGE_AVAIL},
@@ -496,7 +533,39 @@ int main(int argc, char** argv)
                        chmod(MOUNT_DIR, S_IRUSR | S_IWUSR | S_IXUSR |
                                S_IRGRP | S_IWGRP | S_IXGRP |
                                S_IROTH | S_IWOTH | S_IXOTH);
-                       create_mounts();
+                       create_mounts(MOUNT_DIR, -1, -1);
+                       break;
+
+               case LONG_CREATE_GROUP_MOUNTS:
+                       ensure_dir(MOUNT_DIR);
+                       chmod(MOUNT_DIR, S_IRUSR | S_IWUSR | S_IXUSR |
+                               S_IRGRP | S_IWGRP | S_IXGRP |
+                               S_IROTH | S_IWOTH | S_IXOTH);
+                       grp = getgrnam(optarg);
+                       if (!grp) {
+                               ERROR("could not find specified group %s\n",
+                                       optarg);
+                               exit(EXIT_FAILURE);
+                       }
+                       snprintf(path, PATH_MAX, "%s/%s",
+                                       MOUNT_DIR, grp->gr_name);
+                       create_mounts(path, -1, grp->gr_gid);
+                       break;
+
+               case LONG_CREATE_USER_MOUNTS:
+                       ensure_dir(MOUNT_DIR);
+                       chmod(MOUNT_DIR, S_IRUSR | S_IWUSR | S_IXUSR |
+                               S_IRGRP | S_IWGRP | S_IXGRP |
+                               S_IROTH | S_IWOTH | S_IXOTH);
+                       pwd = getpwnam(optarg);
+                       if (!pwd) {
+                               ERROR("could not find specified user %s\n",
+                                       optarg);
+                               exit(EXIT_FAILURE);
+                       }
+                       snprintf(path, PATH_MAX, "%s/%s",
+                                       MOUNT_DIR, pwd->pw_name);
+                       create_mounts(path, pwd->pw_uid, -1);
                        break;
 
                case LONG_PAGE_SIZES:
diff --git a/man/hugeadm.8 b/man/hugeadm.8
index 1582600..9a17f6b 100644
--- a/man/hugeadm.8
+++ b/man/hugeadm.8
@@ -39,6 +39,22 @@ This creates mount points for each supported huge page size 
under
 root:root with permissions set to 770.  Each mount point is named
 pagesize-<size in bytes>.
 
+.TP
+.B --create-group-mounts=<group>
+
+This creates mount points for each supported huge page size under
+/var/lib/hugetlbfs/<group>.  Mount point naming is the same as
+--create-mounts.  After creation they are mounted and are owned by
+root:group with permissions set to 070.
+
+.TP
+.B --create-user-mounts=<user>
+
+This creates mount points for each supported huge page size under
+/var/lib/hugetlbfs/<user>.  Mount point naming is the same as
+--create-mounts.  After creation they are mounted and are owned by
+<user>:root with permissions set to 700.
+
 The following options display information about the pools.
 
 .TP
-- 
1.6.0.3


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to