summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohanPipereau <ypiperea@cisco.com>2019-06-06 16:34:14 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-08-09 07:53:46 +0000
commit71dd9d5ff8f9f629d7d917cc2b3695a910640602 (patch)
tree8e536878e88381a50dfb7ab10cbd60105590cbc5
parentedfe2c0079a756f5fb1108037c39450e3521c8bd (diff)
stats: create /run/vpp before stat socket bind()
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>
-rw-r--r--src/vlib/unix/cli.c2
-rw-r--r--src/vpp-api/client/stat_client.h2
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_stats.py2
-rw-r--r--src/vpp/stats/stat_segment.c44
4 files changed, 15 insertions, 35 deletions
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index fa61c6964be..22f56c728c2 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -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);
diff --git a/src/vpp-api/client/stat_client.h b/src/vpp-api/client/stat_client.h
index 12faddb7bce..10b54c8d601 100644
--- a/src/vpp-api/client/stat_client.h
+++ b/src/vpp-api/client/stat_client.h
@@ -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;
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py
index eeaa32d7229..aa576136a7b 100644
--- a/src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/src/vpp-api/python/vpp_papi/vpp_stats.py
@@ -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):
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index 1328ea815ae..7bb01b30d5b 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -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* */