aboutsummaryrefslogtreecommitdiff
path: root/hugeadm.c
diff options
context:
space:
mode:
authorEric B Munson <ebmunson@us.ibm.com>2009-04-07 12:45:52 +0100
committerEric B Munson <ebmunson@us.ibm.com>2009-04-08 14:25:00 +0100
commit1d4402b00269f0b8fa16d75e30aa63f24761c828 (patch)
tree65a30a977d0e36dc7ae15869eeb5a2bacdcba4bb /hugeadm.c
parentfef07e0f8b9703cb671e623a90f038a0b07afea1 (diff)
downloadlibhugetlbfs-1d4402b00269f0b8fa16d75e30aa63f24761c828.tar.gz
Separate hugetlbfs mount collection from printing
This patch separates the hugetlbfs mount point collection from the printing to pave the wave for a check in mount_dir to see if a specified directory is already mounted. Signed-off-by: Eric B Munson <ebmunson@us.ibm.com> Acked-by: Mel Gorman <mel@csn.ul.ie>
Diffstat (limited to 'hugeadm.c')
-rw-r--r--hugeadm.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/hugeadm.c b/hugeadm.c
index 22f47a4..24a2d2e 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -181,11 +181,16 @@ void print_mounts(struct mount_list *current, int longest)
}
}
-void mounts_list_all(void)
+/* collect_active_mounts returns a list of active hugetlbfs
+ * mount points, and, if longest is not NULL, the number of
+ * characters in the longest mount point to ease output
+ * formatting. Caller is expected to free the list of mounts.
+ */
+struct mount_list *collect_active_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 +214,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 (longest && length > *longest)
+ *longest = length;
current->next = malloc(sizeof(struct mount_list));
if (!current->next) {
@@ -228,16 +233,28 @@ 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;
}
+ return NULL;
+}
- current = list;
- while (current) {
- previous = current;
- current = current->next;
+void mounts_list_all(void)
+{
+ struct mount_list *list, *previous;
+ int longest = MIN_COL;
+
+ list = collect_active_mounts(&longest);
+
+ if (!list) {
+ ERROR("No hugetlbfs mount points found\n");
+ return;
+ }
+
+ print_mounts(list, longest);
+
+ while (list) {
+ previous = list;
+ list = list->next;
free(previous);
}
}