aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-07-20 19:17:06 +0200
committerDave Wallace <dwallacelf@gmail.com>2017-08-24 19:49:09 +0000
commit57d963f88b2c99e698e2b29f72e190f47f41b1ad (patch)
tree0a26d5fd1e09b4b997db5950fe9bf70835ab9798
parentd48e9763bfc39106eca954a28223b72261bf1aeb (diff)
Make VPP runtime directory configurable
New startup config command: unix { runtime-dir /run/vpp } Also, adds recursive mkdir funtion for use in deifferent places like cli-config socket path and dpdk hugepage directory path. Change-Id: I1446ceab9c220c25804e73a743a3ebb383450124 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rwxr-xr-xsrc/plugins/dpdk/device/init.c29
-rw-r--r--src/plugins/memif/memif.c14
-rw-r--r--src/plugins/memif/private.h1
-rw-r--r--src/vlib/unix/cli.c20
-rw-r--r--src/vlib/unix/main.c13
-rw-r--r--src/vlib/unix/unix.h14
-rw-r--r--src/vlib/unix/util.c36
-rw-r--r--src/vpp/vnet/main.c5
8 files changed, 90 insertions, 42 deletions
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index c6c9ee34..6f7e168b 100755
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -37,8 +37,6 @@ dpdk_main_t dpdk_main;
#define LINK_STATE_ELOGS 0
-#define DEFAULT_HUGE_DIR (VPP_RUN_DIR "/hugepages")
-
/* Port configuration, mildly modified Intel app values */
static struct rte_eth_conf port_conf_template = {
@@ -835,6 +833,10 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
u8 huge_dir = 0;
u8 file_prefix = 0;
u8 *socket_mem = 0;
+ u8 *huge_dir_path = 0;
+
+ huge_dir_path =
+ format (0, "%s/hugepages%c", vlib_unix_get_runtime_dir (), 0);
conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword));
log_level = RTE_LOG_NOTICE;
@@ -980,7 +982,7 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
u8 less_than_1g = 1;
int rv;
- umount (DEFAULT_HUGE_DIR);
+ umount ((char *) huge_dir_path);
/* Process "socket-mem" parameter value */
if (vec_len (socket_mem))
@@ -1057,27 +1059,20 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
vec_free (mem_by_socket);
- /* Make sure VPP_RUN_DIR exists */
- error = unix_make_vpp_run_dir ();
+ error = vlib_unix_recursive_mkdir ((char *) huge_dir_path);
if (error)
- goto done;
-
- rv = mkdir (DEFAULT_HUGE_DIR, 0755);
- if (rv && errno != EEXIST)
{
- error = clib_error_return (0, "mkdir '%s' failed errno %d",
- DEFAULT_HUGE_DIR, errno);
goto done;
}
if (use_1g && !(less_than_1g && use_2m))
{
- rv =
- mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G");
+ rv = mount ("none", (char *) huge_dir_path, "hugetlbfs", 0,
+ "pagesize=1G");
}
else if (use_2m)
{
- rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL);
+ rv = mount ("none", (char *) huge_dir_path, "hugetlbfs", 0, NULL);
}
else
{
@@ -1092,7 +1087,7 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
tmp = format (0, "--huge-dir%c", 0);
vec_add1 (conf->eal_init_args, tmp);
- tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0);
+ tmp = format (0, "%s%c", huge_dir_path, 0);
vec_add1 (conf->eal_init_args, tmp);
if (!file_prefix)
{
@@ -1209,7 +1204,9 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
(char **) conf->eal_init_args);
/* lazy umount hugepages */
- umount2 (DEFAULT_HUGE_DIR, MNT_DETACH);
+ umount2 ((char *) huge_dir_path, MNT_DETACH);
+ rmdir ((char *) huge_dir_path);
+ vec_free (huge_dir_path);
if (ret < 0)
return clib_error_return (0, "rte_eal_init returned %d", ret);
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index ba123149..af81faf2 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -556,15 +556,19 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
if (args->socket_filename == 0 || args->socket_filename[0] != '/')
{
- rv = mkdir (MEMIF_DEFAULT_SOCKET_DIR, 0755);
- if (rv && errno != EEXIST)
- return VNET_API_ERROR_SYSCALL_ERROR_1;
+ clib_error_t *error;
+ error = vlib_unix_recursive_mkdir (vlib_unix_get_runtime_dir ());
+ if (error)
+ {
+ clib_error_free (error);
+ return VNET_API_ERROR_SYSCALL_ERROR_1;
+ }
if (args->socket_filename == 0)
- socket_filename = format (0, "%s/%s%c", MEMIF_DEFAULT_SOCKET_DIR,
+ socket_filename = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
MEMIF_DEFAULT_SOCKET_FILENAME, 0);
else
- socket_filename = format (0, "%s/%s%c", MEMIF_DEFAULT_SOCKET_DIR,
+ socket_filename = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
args->socket_filename, 0);
}
diff --git a/src/plugins/memif/private.h b/src/plugins/memif/private.h
index 0f82f1e9..985ac5ec 100644
--- a/src/plugins/memif/private.h
+++ b/src/plugins/memif/private.h
@@ -17,7 +17,6 @@
#include <vppinfra/lock.h>
-#define MEMIF_DEFAULT_SOCKET_DIR "/run/vpp"
#define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
#define MEMIF_DEFAULT_RING_SIZE 1024
#define MEMIF_DEFAULT_RX_QUEUES 1
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index 1befa25d..068a4e16 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -2642,15 +2642,19 @@ unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
/* CLI listen. */
unix_file_t template = { 0 };
- /* If our listen address looks like a path and it starts with
- * VPP_RUN_DIR, go make sure VPP_RUN_DIR exists before trying to open
- * a socket in it.
- */
- if (strncmp (s->config, VPP_RUN_DIR "/", strlen (VPP_RUN_DIR) + 1) == 0)
+ /* mkdir of file socketu, only under /run */
+ if (strncmp (s->config, "/run", 4) == 0)
{
- error = unix_make_vpp_run_dir ();
- if (error)
- return error;
+ u8 *tmp = format (0, "%s", s->config);
+ int i = vec_len (tmp);
+ while (i && tmp[--i] != '/')
+ ;
+
+ tmp[i] = 0;
+
+ if (i)
+ vlib_unix_recursive_mkdir ((char *) tmp);
+ vec_free (tmp);
}
s->flags = SOCKET_IS_SERVER | /* listen, don't connect */
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index ad1a7c3c..cb34a89f 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -56,6 +56,8 @@
/** Default CLI history depth if not configured in startup.conf */
#define UNIX_CLI_DEFAULT_HISTORY 50
+char *vlib_default_runtime_dir __attribute__ ((weak));
+char *vlib_default_runtime_dir = "/run/vlib";
unix_main_t unix_main;
@@ -332,6 +334,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
else
if (unformat (input, "cli-listen %s", &um->cli_listen_socket.config))
;
+ else if (unformat (input, "runtime-dir %s", &um->runtime_dir))
+ ;
else if (unformat (input, "cli-line-mode"))
um->cli_line_mode = 1;
else if (unformat (input, "cli-no-banner"))
@@ -432,6 +436,9 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
}
um->unix_config_complete = 1;
+ if (um->runtime_dir == 0)
+ um->runtime_dir = format (0, "%s%c", vlib_default_runtime_dir, 0);
+
return 0;
}
@@ -463,6 +470,10 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
* Ask the Linux kernel to dump all memory-mapped address regions, instead
* of just text+data+bss.
*
+ * @cfgcmd{runtime-dir}
+ * Define directory where VPP is going to store all runtime files.
+ * Default is /run/vpp.
+ *
* @cfgcmd{cli-listen, &lt;address:port&gt;}
* Bind the CLI to listen at the address and port given. @clocalhost
* on TCP port @c 5002, given as <tt>cli-listen localhost:5002</tt>,
@@ -489,7 +500,7 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
* Limit pager buffer to @c nn lines of output.
* A value of @c 0 disables the pager. Default value: @c 100000
?*/
-VLIB_CONFIG_FUNCTION (unix_config, "unix");
+VLIB_EARLY_CONFIG_FUNCTION (unix_config, "unix");
static clib_error_t *
unix_exit (vlib_main_t * vm)
diff --git a/src/vlib/unix/unix.h b/src/vlib/unix/unix.h
index ffa92bba..ee1312e3 100644
--- a/src/vlib/unix/unix.h
+++ b/src/vlib/unix/unix.h
@@ -44,9 +44,6 @@
#include <termios.h>
-/** VPP runtime ephemeral directory. Typically stored in a tmpfs. */
-#define VPP_RUN_DIR "/run/vpp"
-
struct unix_file;
typedef clib_error_t *(unix_file_function_t) (struct unix_file * f);
@@ -106,6 +103,9 @@ typedef struct
/* startup-config filename */
u8 *startup_config_filename;
+ /* runtime directory path */
+ u8 *runtime_dir;
+
/* unix config complete */
volatile int unix_config_complete;
@@ -214,6 +214,12 @@ vlib_unix_get_main (void)
return &unix_main;
}
+static inline char *
+vlib_unix_get_runtime_dir (void)
+{
+ return (char *) unix_main.runtime_dir;
+}
+
/* thread stack array; vec_len = max number of threads */
extern u8 **vlib_thread_stacks;
@@ -233,7 +239,7 @@ clib_error_t *foreach_directory_file (char *dir_name,
u8 * file_name),
void *arg, int scan_dirs);
-clib_error_t *unix_make_vpp_run_dir (void);
+clib_error_t *vlib_unix_recursive_mkdir (char *path);
#endif /* included_unix_unix_h */
diff --git a/src/vlib/unix/util.c b/src/vlib/unix/util.c
index 51b4a4ed..93aeb99c 100644
--- a/src/vlib/unix/util.c
+++ b/src/vlib/unix/util.c
@@ -223,16 +223,38 @@ done:
}
clib_error_t *
-unix_make_vpp_run_dir (void)
+vlib_unix_recursive_mkdir (char *path)
{
- int rv;
+ clib_error_t *error = 0;
+ char *c = 0;
+ int i = 0;
- rv = mkdir (VPP_RUN_DIR, 0755);
- if (rv && errno != EEXIST)
- return clib_error_return (0, "mkdir '%s' failed errno %d",
- VPP_RUN_DIR, errno);
+ while (path[i] != 0)
+ {
+ if (c && path[i] == '/')
+ {
+ vec_add1 (c, 0);
+ if ((mkdir (c, 0755)) && (errno != EEXIST))
+ {
+ error = clib_error_return_unix (0, "mkdir '%s'", c);
+ goto done;
+ }
+ _vec_len (c)--;
+ }
+ vec_add1 (c, path[i]);
+ i++;
+ }
- return 0;
+ if ((mkdir (path, 0755)) && (errno != EEXIST))
+ {
+ error = clib_error_return_unix (0, "mkdir '%s'", path);
+ goto done;
+ }
+
+done:
+ vec_free (c);
+
+ return error;
}
/*
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index ade32aa1..9fe65fe2 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -42,6 +42,11 @@ vpe_main_init (vlib_main_t * vm)
}
/*
+ * Default path for runtime data
+ */
+char *vlib_default_runtime_dir = "/run/vpp";
+
+/*
* Load plugins from /usr/lib/vpp_plugins by default
*/
char *vlib_plugin_path = "/usr/lib/vpp_plugins";