stats: create /run/vpp before stat socket bind() 04/20004/9
authorYohanPipereau <ypiperea@cisco.com>
Thu, 6 Jun 2019 14:34:14 +0000 (16:34 +0200)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 9 Aug 2019 07:53:46 +0000 (07:53 +0000)
When VPP tries to bind to stats.sock it will complain about non-existing
/run/vpp directory.
/run/vpp is created before cli socket operations are performed.
The same should be done for stat socket.

Ticket: VPP-1708
Type: fix
Change-Id: I53d70939c8125d04a365ac51a6cbf8926dc52adf
Signed-off-by: YohanPipereau <ypiperea@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
src/vlib/unix/cli.c
src/vpp-api/client/stat_client.h
src/vpp-api/python/vpp_papi/vpp_stats.py
src/vpp/stats/stat_segment.c

index fa61c69..22f56c7 100644 (file)
@@ -3120,7 +3120,7 @@ unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
          while (i && tmp[--i] != '/')
            ;
 
-         tmp[i] = 0;
+         tmp[i] = '\0';
 
          if (i)
            vlib_unix_recursive_mkdir ((char *) tmp);
index 12faddb..10b54c8 100644 (file)
@@ -35,7 +35,9 @@ typedef enum
 } stat_directory_type_t;
 
 /* Default socket to exchange segment fd */
+/* TODO: Get from runtime directory */
 #define STAT_SEGMENT_SOCKET_FILE "/run/vpp/stats.sock"
+#define STAT_SEGMENT_SOCKET_FILENAME "stats.sock"
 
 typedef struct stat_client_main_t stat_client_main_t;
 
index eeaa32d..aa57613 100644 (file)
@@ -192,7 +192,7 @@ class VPPStatsClientLoadError(RuntimeError):
 class VPPStats(object):
     VPPStatsIOError = VPPStatsIOError
 
-    default_socketname = '/var/run/vpp/stats.sock'
+    default_socketname = '/run/vpp/stats.sock'
     sharedlib_name = 'libvppapiclient.so'
 
     def __init__(self, socketname=default_socketname, timeout=10):
index 1328ea8..7bb01b3 100644 (file)
@@ -652,7 +652,7 @@ stats_socket_accept_ready (clib_file_t * uf)
   return 0;
 }
 
-static void
+static clib_error_t *
 stats_segment_socket_init (void)
 {
   stat_segment_main_t *sm = &stat_segment_main;
@@ -665,10 +665,7 @@ stats_segment_socket_init (void)
     CLIB_SOCKET_F_ALLOW_GROUP_WRITE | CLIB_SOCKET_F_PASSCRED;
 
   if ((error = clib_socket_init (s)))
-    {
-      clib_error_report (error);
-      return;
-    }
+    return error;
 
   clib_file_t template = { 0 };
   template.read_function = stats_socket_accept_ready;
@@ -677,6 +674,8 @@ stats_segment_socket_init (void)
   clib_file_add (&file_main, &template);
 
   sm->socket = s;
+
+  return 0;
 }
 
 static clib_error_t *
@@ -709,25 +708,6 @@ stat_segment_collector_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
   return 0;                    /* or not */
 }
 
-static clib_error_t *
-statseg_init (vlib_main_t * vm)
-{
-  stat_segment_main_t *sm = &stat_segment_main;
-
-  if (sm->socket_name)
-    stats_segment_socket_init ();
-
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_INIT_FUNCTION (statseg_init) =
-{
-  .runs_after = VLIB_INITS("unix_input_init"),
-};
-/* *INDENT-ON* */
-
-
 clib_error_t *
 stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn,
                             u32 caller_index)
@@ -780,12 +760,9 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input)
     {
       if (unformat (input, "socket-name %s", &sm->socket_name))
        ;
+      /* DEPRECATE: default (does nothing) */
       else if (unformat (input, "default"))
-       {
-         vec_reset_length (sm->socket_name);
-         sm->socket_name = format (sm->socket_name, "%s",
-                                   STAT_SEGMENT_SOCKET_FILE);
-       }
+       ;
       else if (unformat (input, "size %U",
                         unformat_memory_size, &sm->memory_size))
        ;
@@ -800,15 +777,16 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input)
 
   /* set default socket file name when statseg config stanza is empty. */
   if (!vec_len (sm->socket_name))
-    sm->socket_name = format (sm->socket_name, "%s",
-                             STAT_SEGMENT_SOCKET_FILE);
+    sm->socket_name = format (0, "%s/%s", vlib_unix_get_runtime_dir (),
+                             STAT_SEGMENT_SOCKET_FILENAME);
+
   /*
    * NULL-terminate socket name string
    * clib_socket_init()->socket_config() use C str*
    */
   vec_terminate_c_string (sm->socket_name);
 
-  return 0;
+  return stats_segment_socket_init ();
 }
 
 static clib_error_t *
@@ -879,7 +857,7 @@ statseg_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
   return 0;
 }
 
-VLIB_EARLY_CONFIG_FUNCTION (statseg_config, "statseg");
+VLIB_CONFIG_FUNCTION (statseg_config, "statseg");
 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (statseg_sw_interface_add_del);
 
 /* *INDENT-OFF* */