Make VPP runtime directory configurable 90/7690/4
authorDamjan Marion <damarion@cisco.com>
Thu, 20 Jul 2017 17:17:06 +0000 (19:17 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Thu, 24 Aug 2017 19:49:09 +0000 (19:49 +0000)
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>
src/plugins/dpdk/device/init.c
src/plugins/memif/memif.c
src/plugins/memif/private.h
src/vlib/unix/cli.c
src/vlib/unix/main.c
src/vlib/unix/unix.h
src/vlib/unix/util.c
src/vpp/vnet/main.c

index c6c9ee3..6f7e168 100755 (executable)
@@ -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);
index ba12314..af81faf 100644 (file)
@@ -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);
 
     }
index 0f82f1e..985ac5e 100644 (file)
@@ -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
index 1befa25..068a4e1 100644 (file)
@@ -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 */
index ad1a7c3..cb34a89 100644 (file)
@@ -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)
index ffa92bb..ee1312e 100644 (file)
@@ -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 */
 
index 51b4a4e..93aeb99 100644 (file)
@@ -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;
 }
 
 /*
index ade32aa..9fe65fe 100644 (file)
@@ -41,6 +41,11 @@ vpe_main_init (vlib_main_t * vm)
   vat_plugin_hash_create ();
 }
 
+/*
+ * Default path for runtime data
+ */
+char *vlib_default_runtime_dir = "/run/vpp";
+
 /*
  * Load plugins from /usr/lib/vpp_plugins by default
  */