vppinfra: fix legacy huge pages creation for default size
Type: fix
Change-Id: I941b92ebec66ccd9c9e9a12d485844313c9f117b
Signed-off-by: Benoît Ganne <bganne@cisco.com>
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 1b3694b..8b2fd14 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -359,11 +359,20 @@
clib_mem_main_t *mm = &clib_mem_main;
int fd = -1;
char *mount_dir;
+ u8 *temp;
u8 *filename;
+ /*
+ * Since mkdtemp will modify template string "/tmp/hugepage_mount.XXXXXX",
+ * it must not be a string constant, but should be declared as
+ * a character array.
+ */
+ temp = format (0, "/tmp/hugepage_mount.XXXXXX%c", 0);
+
/* create mount directory */
- if ((mount_dir = mkdtemp ("/tmp/hugepage_mount.XXXXXX")) == 0)
+ if ((mount_dir = mkdtemp ((char *) temp)) == 0)
{
+ vec_free (temp);
vec_reset_length (mm->error);
mm->error = clib_error_return_unix (mm->error, "mkdtemp");
return CLIB_MEM_ERROR;
@@ -371,6 +380,7 @@
if (mount ("none", mount_dir, "hugetlbfs", 0, NULL))
{
+ vec_free (temp);
rmdir ((char *) mount_dir);
vec_reset_length (mm->error);
mm->error = clib_error_return_unix (mm->error, "mount");
@@ -388,6 +398,7 @@
umount2 ((char *) mount_dir, MNT_DETACH);
rmdir ((char *) mount_dir);
vec_free (filename);
+ vec_free (temp);
return fd;
}
@@ -403,6 +414,8 @@
if (log2_page_size == mm->log2_page_sz)
log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT;
+ else if (log2_page_size == mm->log2_default_hugepage_sz)
+ log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT_HUGE;
switch (log2_page_size)
{