summaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
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/vpp_echo_bapi.c
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/vpp_echo_bapi.c')
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_bapi.c64
1 files changed, 51 insertions, 13 deletions
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;