diff options
author | Filip Tehlar <ftehlar@cisco.com> | 2023-05-19 12:54:18 +0200 |
---|---|---|
committer | Filip Tehlar <ftehlar@cisco.com> | 2023-05-19 12:54:18 +0200 |
commit | 84fd6493b32729094c87741416f4f9898ab286f8 (patch) | |
tree | dd9f035014de8f9865bf86ed87d01453d420293e | |
parent | 4810e5b4836e806c191ce4ffd1b5b9f6ddb349c0 (diff) |
hsa: make http cli client thread safe
Type: fix
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Change-Id: I9e6fd29c0e09406e48215f06977b2d4678650669
-rw-r--r-- | src/plugins/hs_apps/http_client_cli.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/plugins/hs_apps/http_client_cli.c b/src/plugins/hs_apps/http_client_cli.c index f331670c58f..4530f2e19a2 100644 --- a/src/plugins/hs_apps/http_client_cli.c +++ b/src/plugins/hs_apps/http_client_cli.c @@ -307,14 +307,38 @@ hcc_attach () return 0; } +static int +hcc_connect_rpc (void *rpc_args) +{ + vnet_connect_args_t *a = rpc_args; + int rv; + + rv = vnet_connect (a); + if (rv) + clib_warning (0, "connect returned: %U", format_session_error, rv); + + vec_free (a); + return rv; +} + +static void +hcc_program_connect (vnet_connect_args_t *a) +{ + session_send_rpc_evt_to_thread_force (transport_cl_thread (), + hcc_connect_rpc, a); +} + static clib_error_t * hcc_connect () { - vnet_connect_args_t _a = {}, *a = &_a; + vnet_connect_args_t *a = 0; hcc_main_t *hcm = &hcc_main; hcc_worker_t *wrk; hcc_session_t *hs; + vec_validate (a, 0); + clib_memset (a, 0, sizeof (a[0])); + clib_memcpy (&a->sep_ext, &hcm->connect_sep, sizeof (hcm->connect_sep)); a->app_index = hcm->app_index; @@ -323,11 +347,7 @@ hcc_connect () hs = hcc_session_alloc (wrk); a->api_context = hs->session_index; - int rv = vnet_connect (a); - - if (rv) - return clib_error_return (0, "connect returned: %U", format_session_error, - rv); + hcc_program_connect (a); return 0; } @@ -457,7 +477,9 @@ hcc_command_fn (vlib_main_t *vm, unformat_input_t *input, goto done; } + vlib_worker_thread_barrier_sync (vm); vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */); + vlib_worker_thread_barrier_release (vm); err = hcc_run (vm); @@ -480,6 +502,7 @@ VLIB_CLI_COMMAND (hcc_command, static) = { .path = "http cli client", .short_help = "uri http://<ip-addr> query <query-string>", .function = hcc_command_fn, + .is_mp_safe = 1, }; static clib_error_t * |