unix: mkdir VPP_RUN_DIR before opening a socket in it 34/7434/2
authorChris Luke <chrisy@flirble.org>
Wed, 5 Jul 2017 22:02:53 +0000 (18:02 -0400)
committerDamjan Marion <dmarion.lists@gmail.com>
Thu, 6 Jul 2017 13:26:23 +0000 (13:26 +0000)
Change https://gerrit.fd.io/r/#/c/7230/ added a Unix domain
CLI socket in the default startup.conf; however unless you
had previously run VPP with the DPDK plugin enabled the
directory that it is created in. /run/vpp, would not exist
and startup would fail. This directory is typically hosted
in a tmpfs ramdisk and is thus ephemeral.

This patch adds a function that attempts to mkdir VPP_RUN_DIR
and uses it in both the DPDK plugin and the CLI code if the
CLI socket is to be created in that directory.

Change-Id: Ibbf925819099dce2b5eb0fa238b9edca1036d6fd
Signed-off-by: Chris Luke <chrisy@flirble.org>
src/plugins/dpdk/device/init.c
src/vlib/unix/cli.c
src/vlib/unix/unix.h
src/vlib/unix/util.c

index d9ab075..04344f7 100755 (executable)
@@ -37,8 +37,7 @@ dpdk_main_t dpdk_main;
 
 #define LINK_STATE_ELOGS       0
 
-#define DEFAULT_HUGE_DIR "/run/vpp/hugepages"
-#define VPP_RUN_DIR "/run/vpp"
+#define DEFAULT_HUGE_DIR (VPP_RUN_DIR "/hugepages")
 
 /* Port configuration, mildly modified Intel app values */
 
@@ -1047,13 +1046,10 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
 
       vec_free (mem_by_socket);
 
-      rv = mkdir (VPP_RUN_DIR, 0755);
-      if (rv && errno != EEXIST)
-       {
-         error = clib_error_return (0, "mkdir '%s' failed errno %d",
-                                    VPP_RUN_DIR, errno);
-         goto done;
-       }
+      /* Make sure VPP_RUN_DIR exists */
+      error = unix_make_vpp_run_dir ();
+      if (error)
+       goto done;
 
       rv = mkdir (DEFAULT_HUGE_DIR, 0755);
       if (rv && errno != EEXIST)
index 953d133..1befa25 100644 (file)
@@ -2642,6 +2642,17 @@ 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)
+       {
+         error = unix_make_vpp_run_dir ();
+         if (error)
+           return error;
+       }
+
       s->flags = SOCKET_IS_SERVER |    /* listen, don't connect */
        SOCKET_ALLOW_GROUP_WRITE;       /* PF_LOCAL socket only */
       error = clib_socket_init (s);
index de607c0..ffa92bb 100644 (file)
 #include <vppinfra/socket.h>
 #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);
 
@@ -229,6 +233,8 @@ 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);
+
 #endif /* included_unix_unix_h */
 
 /*
index edc3e59..51b4a4e 100644 (file)
@@ -222,6 +222,19 @@ done:
   return r;
 }
 
+clib_error_t *
+unix_make_vpp_run_dir (void)
+{
+  int rv;
+
+  rv = mkdir (VPP_RUN_DIR, 0755);
+  if (rv && errno != EEXIST)
+    return clib_error_return (0, "mkdir '%s' failed errno %d",
+                             VPP_RUN_DIR, errno);
+
+  return 0;
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *