From 71dd9d5ff8f9f629d7d917cc2b3695a910640602 Mon Sep 17 00:00:00 2001 From: YohanPipereau Date: Thu, 6 Jun 2019 16:34:14 +0200 Subject: 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 Signed-off-by: Ole Troan --- src/vlib/unix/cli.c | 2 +- src/vpp-api/client/stat_client.h | 2 ++ src/vpp-api/python/vpp_papi/vpp_stats.py | 2 +- src/vpp/stats/stat_segment.c | 44 ++++++++------------------------ 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* */ -- cgit 1.2.3-korg