Currently the library will select the first hugetlbfs mount it finds for a given page size for usage. This can lead to frustrating failures when root owns the first mount and a user has a later mount in the list. This patch makes find_mounts check if a given mount is usable by the current user. Mounts that are not usable will be skipped.
Signed-off-by: Eric B Munson <emun...@mgebm.net> Cc: Andrew Lutomirski <l...@mit.edu> --- hugeutils.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-) diff --git a/hugeutils.c b/hugeutils.c index b28bd0a..5b16a31 100644 --- a/hugeutils.c +++ b/hugeutils.c @@ -37,6 +37,7 @@ #include <sys/vfs.h> #include <sys/statfs.h> #include <sys/types.h> +#include <sys/stat.h> #include <sys/mman.h> #include <sys/file.h> #include <sys/uio.h> @@ -607,6 +608,28 @@ void debug_show_page_sizes(void) hpage_sizes[i].mount); } +static bool hugetlbfs_test_access(const char *path) +{ + struct stat stats; + uid_t uid; + gid_t gid; + if (stat(path, &stats)) + return false; + + if (stats.st_mode & S_IRWXO) + return true; + + gid = getegid(); + if (stats.st_gid == gid && (stats.st_mode & S_IRWXG)) + return true; + + uid = geteuid(); + if (stats.st_uid == uid && (stats.st_mode & S_IRWXU)) + return true; + + return false; +} + #define LINE_MAXLEN 2048 static void find_mounts(void) { @@ -652,7 +675,8 @@ static void find_mounts(void) */ err = sscanf(line, "%*s %" stringify(PATH_MAX) "s hugetlbfs " "%*s %d", path, &dummy); - if ((err == 2) && (hugetlbfs_test_path(path) == 1)) + if ((err == 2) && (hugetlbfs_test_path(path) == 1) && + hugetlbfs_test_access(path)) add_hugetlbfs_mount(path, 0); } close(fd); -- 1.7.5.4 ------------------------------------------------------------------------------ Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! http://www.accelacomm.com/jaw/sfnl/114/51491232/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel