On Tue, Jan 13, 2009 at 01:37:04PM +0000, Eric B Munson wrote: > 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> > --- > hugeadm.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 71 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); > + } > +
It's a pity code can't be shared. How about always setting a user/group ID? If not specifically set by the command-line, then default to the current user/group. If set to -1, then create global mounts. Is that workable? Functionally, this appeared to do the right thing and no problems jumped out other than the lack of mtab updating. > + 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; > -- > 1.6.0.6 > > > ------------------------------------------------------------------------------ > 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 > -- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab ------------------------------------------------------------------------------ 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