aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/sapi
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-12-23 12:32:41 -0800
committerFlorin Coras <fcoras@cisco.com>2020-12-23 12:41:42 -0800
commit8219f1f361083cc63022b70d11b08f52833d4789 (patch)
tree666192d2552de6bc17c35654f285986f7cbabd70 /src/plugins/hs_apps/sapi
parent7b0fa5569516992aa81c626aa2b426a81eb0ecab (diff)
hsa: detach fifo segments in echo app
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I6a982f4aa3c1816160ff1c0a663ec6df6ec4cf0a
Diffstat (limited to 'src/plugins/hs_apps/sapi')
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo.c27
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_bapi.c64
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_common.h7
3 files changed, 60 insertions, 38 deletions
diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c
index 03a3577103e..4cce41edf95 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo.c
@@ -537,21 +537,6 @@ session_bound_handler (session_bound_msg_t * mp)
em->proto_cb_vft->bound_uri_cb (mp, listen_session);
}
-static int
-echo_segment_is_not_mapped (u64 segment_handle)
-{
- echo_main_t *em = &echo_main;
- uword *segment_present;
- ECHO_LOG (3, "Check if segment mapped 0x%lx...", segment_handle);
- clib_spinlock_lock (&em->segment_handles_lock);
- segment_present = hash_get (em->shared_segment_handles, segment_handle);
- clib_spinlock_unlock (&em->segment_handles_lock);
- if (segment_present != 0)
- return 0;
- ECHO_LOG (2, "Segment not mapped (0x%lx)", segment_handle);
- return -1;
-}
-
static void
session_accepted_handler (session_accepted_msg_t * mp)
{
@@ -567,7 +552,7 @@ session_accepted_handler (session_accepted_msg_t * mp)
"Unknown listener handle 0x%lx", mp->listener_handle);
return;
}
- if (echo_segment_is_not_mapped (mp->segment_handle))
+ if (echo_segment_lookup (mp->segment_handle) == ~0)
{
ECHO_FAIL (ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC,
"accepted wait_for_segment_allocation errored");
@@ -636,7 +621,7 @@ session_connected_handler (session_connected_msg_t * mp)
}
session = echo_session_new (em);
- if (echo_segment_is_not_mapped (mp->segment_handle))
+ if (echo_segment_lookup (mp->segment_handle) == ~0)
{
ECHO_FAIL (ECHO_FAIL_CONNECTED_WAIT_FOR_SEG_ALLOC,
"connected wait_for_segment_allocation errored");
@@ -734,7 +719,6 @@ add_segment_handler (session_app_add_segment_msg_t * mp)
{
fifo_segment_main_t *sm = &echo_main.segment_main;
fifo_segment_create_args_t _a, *a = &_a;
- echo_main_t *em = &echo_main;
int *fds = 0, i;
char *seg_name = (char *) mp->segment_name;
u64 segment_handle = mp->segment_handle;
@@ -749,7 +733,8 @@ add_segment_handler (session_app_add_segment_msg_t * mp)
goto failed;
}
- if (echo_ssvm_segment_attach (seg_name, SSVM_SEGMENT_MEMFD, fds[0]))
+ if (echo_segment_attach (segment_handle, seg_name, SSVM_SEGMENT_MEMFD,
+ fds[0]))
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
"svm_fifo_segment_attach ('%s') "
@@ -771,7 +756,6 @@ add_segment_handler (session_app_add_segment_msg_t * mp)
goto failed;
}
}
- echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
return;
@@ -784,8 +768,7 @@ failed:
static void
del_segment_handler (session_app_del_segment_msg_t * mp)
{
- echo_main_t *em = &echo_main;
- echo_segment_handle_add_del (em, mp->segment_handle, 0 /* add */ );
+ echo_segment_detach (mp->segment_handle);
ECHO_LOG (2, "Unmaped segment 0x%lx", mp->segment_handle);
}
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
index 784d74160d0..e71c0e9adba 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
@@ -197,10 +197,12 @@ echo_send_disconnect_session (echo_main_t * em, void *args)
*/
int
-echo_ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
+echo_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
+ int fd)
{
fifo_segment_create_args_t _a, *a = &_a;
- fifo_segment_main_t *sm = &echo_main.segment_main;
+ echo_main_t *em = &echo_main;
+ fifo_segment_main_t *sm;
int rv;
clib_memset (a, 0, sizeof (*a));
@@ -210,20 +212,53 @@ echo_ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
if (type == SSVM_SEGMENT_MEMFD)
a->memfd_fd = fd;
+ sm = &em->segment_main;
+
if ((rv = fifo_segment_attach (sm, a)))
return rv;
- vec_reset_length (a->new_segment_indices);
+
+ clib_spinlock_lock (&em->segment_handles_lock);
+ hash_set (em->shared_segment_handles, segment_handle,
+ a->new_segment_indices[0]);
+ clib_spinlock_unlock (&em->segment_handles_lock);
+
+ vec_free (a->new_segment_indices);
return 0;
}
+u32
+echo_segment_lookup (u64 segment_handle)
+{
+ echo_main_t *em = &echo_main;
+ uword *segment_idxp;
+
+ ECHO_LOG (3, "Check if segment mapped 0x%lx...", segment_handle);
+
+ clib_spinlock_lock (&em->segment_handles_lock);
+ segment_idxp = hash_get (em->shared_segment_handles, segment_handle);
+ clib_spinlock_unlock (&em->segment_handles_lock);
+ if (!segment_idxp)
+ return ~0;
+
+ ECHO_LOG (2, "Segment not mapped (0x%lx)", segment_handle);
+ return ((u32) *segment_idxp);
+}
+
void
-echo_segment_handle_add_del (echo_main_t * em, u64 segment_handle, u8 add)
+echo_segment_detach (u64 segment_handle)
{
+ echo_main_t *em = &echo_main;
+ fifo_segment_main_t *sm;
+
+ u32 segment_index = echo_segment_lookup (segment_handle);
+ if (segment_index == (u32) ~0)
+ return;
+
+ sm = &em->segment_main;
+
clib_spinlock_lock (&em->segment_handles_lock);
- if (add)
- hash_set (em->shared_segment_handles, segment_handle, 1);
- else
- hash_unset (em->shared_segment_handles, segment_handle);
+ fifo_segment_delete (sm, fifo_segment_get_segment (sm, segment_index));
+ hash_unset (em->shared_segment_handles, segment_handle);
clib_spinlock_unlock (&em->segment_handles_lock);
}
@@ -270,6 +305,8 @@ static void
em->state = STATE_CLEANED_CERT_KEY;
}
+#define ECHO_MQ_SEG_HANDLE ((u64) ~0 - 1)
+
static void
vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
{
@@ -308,7 +345,8 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
}
if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT)
- if (echo_ssvm_segment_attach (0, SSVM_SEGMENT_MEMFD, fds[n_fds++]))
+ if (echo_segment_attach (ECHO_MQ_SEG_HANDLE, 0, SSVM_SEGMENT_MEMFD,
+ fds[n_fds++]))
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
"svm_fifo_segment_attach failed on SSVM_SEGMENT_MEMFD");
@@ -318,8 +356,8 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
{
segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
- rv = echo_ssvm_segment_attach (segment_name,
- SSVM_SEGMENT_MEMFD, fds[n_fds++]);
+ rv = echo_segment_attach (segment_handle, segment_name,
+ SSVM_SEGMENT_MEMFD, fds[n_fds++]);
if (rv != 0)
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
@@ -339,7 +377,8 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
else
{
segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
- rv = echo_ssvm_segment_attach (segment_name, SSVM_SEGMENT_SHM, -1);
+ rv = echo_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_SHM,
+ -1);
if (rv != 0)
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
@@ -350,7 +389,6 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
}
vec_free (segment_name);
}
- echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
em->state = STATE_ATTACHED_NO_CERT;
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.h b/src/plugins/hs_apps/sapi/vpp_echo_common.h
index 1c874c2a4c8..0def7adab36 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_common.h
+++ b/src/plugins/hs_apps/sapi/vpp_echo_common.h
@@ -439,9 +439,10 @@ void echo_session_print_stats (echo_main_t * em, echo_session_t * session);
u8 *echo_format_crypto_engine (u8 * s, va_list * args);
uword echo_unformat_crypto_engine (unformat_input_t * input, va_list * args);
u8 *echo_format_bytes_per_sec (u8 * s, va_list * args);
-int echo_ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd);
-void echo_segment_handle_add_del (echo_main_t * em, u64 segment_handle,
- u8 add);
+int echo_segment_attach (u64 segment_handle, char *name,
+ ssvm_segment_type_t type, int fd);
+u32 echo_segment_lookup (u64 segment_handle);
+void echo_segment_detach (u64 segment_handle);
/* Binary API */