Currently hugeadm will happily remount hugetlbfs to the same directory if --create-*-mounts is specified more than once with the same arguments. This is a problem because the newest mount of a directory will mask the previous one(s) causing confusion when applications attempt tp share segements. This patch makes all the --create-*-mounts switches check to see if the requested directory is already mounted and if so skip the mount request.
Signed-off-by: Eric B Munson <ebmun...@us.ibm.com> --- Changes from V2: Removed extra check of list pointer from mount_dir Changes from V1: Free list of mounts after mounted check fails hugeadm.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 56 insertions(+), 12 deletions(-) diff --git a/hugeadm.c b/hugeadm.c index 22f47a4..87ff62d 100644 --- a/hugeadm.c +++ b/hugeadm.c @@ -181,11 +181,12 @@ void print_mounts(struct mount_list *current, int longest) } } -void mounts_list_all(void) +/* Caller is expected to free the list of mounts */ +struct mount_list * collect_mounts(int *longest) { FILE *mounts; struct mount_list *list, *current, *previous = NULL; - int length, longest = MIN_COL; + int length; /* First try /proc/mounts, then /etc/mtab */ mounts = setmntent(PROCMOUNTS, "r"); @@ -209,8 +210,8 @@ void mounts_list_all(void) while (getmntent_r(mounts, &(current->entry), current->data, MAX_SIZE_MNTENT)) { if (strcasecmp(current->entry.mnt_type, FS_NAME) == 0) { length = strlen(current->entry.mnt_dir); - if (length > longest) - longest = length; + if (length > *longest) + *longest = length; current->next = malloc(sizeof(struct mount_list)); if (!current->next) { @@ -228,16 +229,29 @@ void mounts_list_all(void) if (previous) { free(previous->next); previous->next = NULL; - print_mounts(list, longest); - } else { - /* No hugetlbfs mounts were found */ - printf("No hugetlbfs mount point found.\n"); + return list; } - current = list; - while (current) { - previous = current; - current = current->next; + return NULL; +} + +void mounts_list_all(void) +{ + struct mount_list *list, *previous; + int longest = MIN_COL; + + list = collect_mounts(&longest); + + if (!list) { + ERROR("No hugetlbfs mount point found.\n"); + return; + } + + print_mounts(list, longest); + + while (list) { + previous = list; + list = list->next; free(previous); } } @@ -315,12 +329,42 @@ int ensure_dir(char *path, mode_t mode, uid_t uid, gid_t gid) return 0; } +int check_mount(struct mount_list *list, char *path) +{ + while (list) { + if (!strcmp(list->entry.mnt_dir, path)) + return 1; + list = list->next; + } + return 0; +} + int mount_dir(char *path, char *options, mode_t mode, uid_t uid, gid_t gid) { struct passwd *pwd; struct group *grp; struct mntent entry; FILE *mounts; + struct mount_list *list, *previous; + int dummy = 0; + + list = collect_mounts(&dummy); + + if (list && check_mount(list, path)) { + INFO("Directory %s is already mounted\n", path); + while (list) { + previous = list; + list = list->next; + free(previous); + } + return 0; + } + + while (list) { + previous = list; + list = list->next; + free(previous); + } if (opt_dry_run) { pwd = getpwuid(uid); -- 1.6.1.2 ------------------------------------------------------------------------------ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel