Adds a create-global-mounts option that builds and mounts a mount point for each huge page size available. The mounts will be under /var/lib/hugetlbfs/global, they will be owned by root:root and will be set to 1777.
Signed-off-by: Eric B Munson <ebmun...@us.ibm.com> --- Changes from V1: Update hugeadm man page with new option hugeadm.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- man/hugeadm.8 | 8 ++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/hugeadm.c b/hugeadm.c index 4f6e552..1f9b0ee 100644 --- a/hugeadm.c +++ b/hugeadm.c @@ -81,6 +81,10 @@ void print_usage() CONT("Creates a mount point for each available huge"); CONT("page size under /var/lib/hugetlbfs/<user>"); CONT("for use by <user>"); + OPTION("--create-global-mounts", ""); + CONT("Creates a mount point for each available huge"); + CONT("page size under /var/lib/hugetlbfs/global"); + CONT("for use by anyone"); OPTION("--page-sizes", "Display page sizes that a configured pool"); OPTION("--page-sizes-all", @@ -105,9 +109,10 @@ int opt_dry_run = 0; #define LONG_MOUNTS ('m' << 8) #define LONG_CREATE_MOUNTS (LONG_MOUNTS|'C') -#define LONG_CREATE_GROUP_MOUNTS (LONG_MOUNTS|'G') +#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 LONG_CREATE_GLOBAL_MOUNTS (LONG_MOUNTS|'G') #define MAX_POOLS 32 @@ -272,7 +277,7 @@ void create_mounts(char *base, uid_t user, gid_t group) chown(base, user, group); chmod(base, S_IRUSR | S_IWUSR | S_IXUSR ); } - if ( group != -1) { + else if ( group != -1) { chown(base, user, group); chmod(base, S_ISGID | S_IRGRP | S_IWGRP | S_IXGRP ); } @@ -307,6 +312,61 @@ void create_mounts(char *base, uid_t user, gid_t group) } } +void create_global_mounts() +{ + struct hpage_pool pools[MAX_POOLS]; + char base[PATH_MAX]; + char path[PATH_MAX]; + char options[ARG_MAX]; + int cnt, pos; + + if (geteuid() != 0) { + ERROR("mounts can only be created by root"); + exit(EXIT_FAILURE); + } + + cnt = hpool_sizes(pools, MAX_POOLS); + if (cnt < 0) { + ERROR("unable to obtain pools list"); + exit(EXIT_FAILURE); + } + + qsort(pools, cnt, sizeof(pools[0]), cmpsizes); + + snprintf(base, PATH_MAX, "%s/%s", MOUNT_DIR, "global"); + if (ensure_dir(base)) { + ERROR("cannot create directory %s\n", base); + exit(EXIT_FAILURE); + } + chown(base, 0, 0); + chmod(base, S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH); + + for (pos = 0; cnt--; pos++) { + snprintf(path, PATH_MAX, "%s/pagesize-%ld", + base, pools[pos].pagesize); + snprintf(options, ARG_MAX, "pagesize=%ld", + pools[pos].pagesize); + if (ensure_dir(path)) { + ERROR("unable to create dir '%s', error: %s\n", + path, strerror(errno)); + exit(EXIT_FAILURE); + } + + if (mount("none", path, FS_NAME, 0, options)) { + ERROR("unable to mount %s, error: %s", + path, strerror(errno)); + exit(EXIT_FAILURE); + } + + chown(path, 0, 0); + chmod(path, S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH); + } +} + enum { POOL_MIN, POOL_MAX, @@ -468,6 +528,7 @@ int main(int argc, char** argv) {"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}, + {"create-global-mounts", no_argument, NULL, LONG_CREATE_GLOBAL_MOUNTS}, {"page-sizes", no_argument, NULL, LONG_PAGE_SIZES}, {"page-sizes-all", no_argument, NULL, LONG_PAGE_AVAIL}, @@ -568,6 +629,14 @@ int main(int argc, char** argv) create_mounts(path, pwd->pw_uid, -1); break; + case LONG_CREATE_GLOBAL_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); + create_global_mounts(); + break; + case LONG_PAGE_SIZES: page_sizes(0); break; diff --git a/man/hugeadm.8 b/man/hugeadm.8 index 9a17f6b..8e5088c 100644 --- a/man/hugeadm.8 +++ b/man/hugeadm.8 @@ -55,6 +55,14 @@ This creates mount points for each supported huge page size under --create-mounts. After creation they are mounted and are owned by <user>:root with permissions set to 700. +.TP +.B --create-global-mounts + +This creates mount points for each supported huge page size under +/var/lib/hugetlbfs/global. Mount point naming is the same as +--create-mounts. After creation they are mounted and are owned by +root:root with permissions set to 1777. + 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