aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hastings <abh@cray.com>2010-11-11 09:20:36 -0600
committerEric B Munson <emunson@mgebm.net>2010-11-15 13:51:29 -0700
commit4111538db91858cf6ddb1519127e65484111fbbf (patch)
tree6ce68788c6640c835a9e47315e5c291df34c7d69
parentc484ac48d4fdaa650bcd641b08b5a9dc310f3330 (diff)
downloadlibhugetlbfs-4111538db91858cf6ddb1519127e65484111fbbf.tar.gz
find_mounts(): ignore non-hugetlbfs filesystems
libhugetlbfs attempts to restrict its statfs calls to only hugetlbfs filesystems. Unfortunately, the sscanf pattern isn't quite correct, and libhugetlbfs ends up calling statfs on all mounted filesystems. This can be quite costly when many network filesystems are mounted. Correct the sscanf pattern. Signed-off-by: Andrew Hastings <abh@cray.com> on behalf of Cray Inc. Signed-off-by: Eric B Munson <emunson@mgebm.net>
-rw-r--r--hugeutils.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/hugeutils.c b/hugeutils.c
index 4e6afd8..3b442c3 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -508,7 +508,7 @@ static void find_mounts(void)
char path[PATH_MAX+1];
char line[LINE_MAXLEN + 1];
char *eol;
- int bytes, err;
+ int bytes, err, dummy;
off_t offset;
fd = open("/proc/mounts", O_RDONLY);
@@ -537,9 +537,16 @@ static void find_mounts(void)
offset = bytes - (eol + 1 - line);
lseek(fd, -offset, SEEK_CUR);
- err = sscanf(line, "%*s %" stringify(PATH_MAX) "s hugetlbfs ",
- path);
- if ((err == 1) && (hugetlbfs_test_path(path) == 1))
+ /*
+ * Match only hugetlbfs filesystems.
+ * Subtle: sscanf returns the number of input items matched
+ * and assigned. To force sscanf to match the literal
+ * "hugetlbfs" string we include a 'dummy' input item
+ * following that string.
+ */
+ err = sscanf(line, "%*s %" stringify(PATH_MAX) "s hugetlbfs "
+ "%*s %d", path, &dummy);
+ if ((err == 2) && (hugetlbfs_test_path(path) == 1))
add_hugetlbfs_mount(path, 0);
}
close(fd);