Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit a3d9ed7

Browse files
authored
Merge pull request #1298 from hppritcha/topic/mntent_mpool_fixes
mpool/udreg: manual patch to use mntent
2 parents c95a50a + 3912271 commit a3d9ed7

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

opal/mca/mpool/udreg/mpool_udreg_component.c

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,24 @@
3333
#ifdef HAVE_MALLOC_H
3434
#include <malloc.h>
3535
#endif
36+
#ifdef HAVE_SYS_VFS_H
37+
#include <sys/vfs.h>
38+
#endif
39+
#ifdef HAVE_SYS_STATVFS_H
40+
#include <sys/statvfs.h>
41+
#endif
42+
#ifdef HAVE_SYS_MOUNT_H
43+
#include <sys/mount.h>
44+
#endif
45+
#ifdef HAVE_SYS_PARAM_H
46+
#include <sys/param.h>
47+
#endif
48+
#ifdef HAVE_SYS_MMAN_H
49+
#include <sys/mman.h>
50+
#endif
3651

3752
#include <fcntl.h>
53+
#include <mntent.h>
3854

3955
/*
4056
* Local functions
@@ -122,23 +138,19 @@ static int page_compare (opal_list_item_t **a,
122138

123139
static void udreg_find_hugepages (void) {
124140
FILE *fh;
125-
char *path;
126-
char buffer[1024];
141+
struct mntent *mntent;
127142
char *ctx, *tok;
143+
unsigned long page_size = 0;
144+
mca_mpool_udreg_hugepage_t *pool;
128145

129-
fh = fopen ("/proc/mounts", "r");
146+
fh = setmntent ("/proc/mounts", "r");
130147
if (NULL == fh) {
131148
return;
132149
}
133150

134-
while (fgets (buffer, 1024, fh)) {
135-
mca_mpool_udreg_hugepage_t *pool;
151+
while (NULL != (mntent = getmntent(fh))) {
136152

137-
(void) strtok_r (buffer, " ", &ctx);
138-
path = strtok_r (NULL, " ", &ctx);
139-
tok = strtok_r (NULL, " ", &ctx);
140-
141-
if (0 != strcmp (tok, "hugetlbfs")) {
153+
if (0 != strcmp(mntent->mnt_type, "hugetlbfs")) {
142154
continue;
143155
}
144156

@@ -147,28 +159,49 @@ static void udreg_find_hugepages (void) {
147159
break;
148160
}
149161

150-
pool->path = strdup (path);
162+
pool->path = strdup(mntent->mnt_opts);
163+
if (NULL == pool->path) {
164+
break;
165+
}
151166

152-
tok = strtok_r (NULL, " ", &ctx);
153-
tok = strtok_r (tok, ",", &ctx);
167+
tok = strtok_r (pool->path, ",", &ctx);
154168

155169
do {
156170
if (0 == strncmp (tok, "pagesize", 8)) {
157171
break;
158172
}
159173
tok = strtok_r (NULL, ",", &ctx);
160174
} while (tok);
161-
sscanf (tok, "pagesize=%lu", &pool->page_size);
175+
176+
if (!tok) {
177+
#if defined(USE_STATFS)
178+
struct statfs info;
179+
180+
statfs (mntent->mnt_dir, &info);
181+
#elif defined(HAVE_STATVFS)
182+
struct statvfs info;
183+
statvfs (mntent->mnt_dir, &info);
184+
#endif
185+
page_size = info.f_bsize;
186+
} else {
187+
(void) sscanf (tok, "pagesize=%lu", &page_size);
188+
}
189+
190+
if (0 == page_size) {
191+
/* could not get page size */
192+
continue;
193+
}
162194

163195
opal_list_append (&mca_mpool_udreg_component.huge_pages, &pool->super);
164-
}
165196

166-
fclose (fh);
197+
}
167198

168199
opal_list_sort (&mca_mpool_udreg_component.huge_pages, page_compare);
169200

170201
mca_mpool_udreg_component.use_huge_pages =
171202
!!(opal_list_get_size (&mca_mpool_udreg_component.huge_pages));
203+
204+
endmntent (fh);
172205
}
173206

174207

0 commit comments

Comments
 (0)