aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-08-24 18:17:34 -0700
committerFlorin Coras <florin.coras@gmail.com>2019-12-21 18:50:12 +0000
commitc4c4cf5066fbdceebd62a8819e3ecd0fc879f05d (patch)
tree2bd208ee7edb7e49440397b2fd44f3515c4e817d /src/plugins
parentd849edf3841c1c9774c5ce209a2b903415f2370a (diff)
session: move add/del segment msg to mq
Type: refactor Change-Id: I32234173ebd69f80acb1afa4039fffbd19157f6d Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo.c85
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_bapi.c81
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_common.c22
-rw-r--r--src/plugins/hs_apps/sapi/vpp_echo_common.h4
4 files changed, 95 insertions, 97 deletions
diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c
index 84089c6b512..0550006f949 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo.c
@@ -531,6 +531,21 @@ 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)
{
@@ -546,7 +561,7 @@ session_accepted_handler (session_accepted_msg_t * mp)
"Unknown listener handle 0x%lx", mp->listener_handle);
return;
}
- if (wait_for_segment_allocation (mp->segment_handle))
+ if (echo_segment_is_not_mapped (mp->segment_handle))
{
ECHO_FAIL (ECHO_FAIL_ACCEPTED_WAIT_FOR_SEG_ALLOC,
"accepted wait_for_segment_allocation errored");
@@ -615,7 +630,7 @@ session_connected_handler (session_connected_msg_t * mp)
}
session = echo_session_new (em);
- if (wait_for_segment_allocation (mp->segment_handle))
+ if (echo_segment_is_not_mapped (mp->segment_handle))
{
ECHO_FAIL (ECHO_FAIL_CONNECTED_WAIT_FOR_SEG_ALLOC,
"connected wait_for_segment_allocation errored");
@@ -709,6 +724,66 @@ session_reset_handler (session_reset_msg_t * mp)
}
static void
+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;
+
+ if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
+ {
+ vec_validate (fds, 1);
+ if (vl_socket_client_recv_fd_msg (fds, 1, 5))
+ {
+ ECHO_FAIL (ECHO_FAIL_VL_API_RECV_FD_MSG,
+ "vl_socket_client_recv_fd_msg failed");
+ goto failed;
+ }
+
+ if (echo_ssvm_segment_attach (seg_name, SSVM_SEGMENT_MEMFD, fds[0]))
+ {
+ ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
+ "svm_fifo_segment_attach ('%s') "
+ "failed on SSVM_SEGMENT_MEMFD", seg_name);
+ goto failed;
+ }
+ vec_free (fds);
+ }
+ else
+ {
+ clib_memset (a, 0, sizeof (*a));
+ a->segment_name = seg_name;
+ a->segment_size = mp->segment_size;
+ /* Attach to the segment vpp created */
+ if (fifo_segment_attach (sm, a))
+ {
+ ECHO_FAIL (ECHO_FAIL_VL_API_FIFO_SEG_ATTACH,
+ "fifo_segment_attach ('%s') failed", seg_name);
+ goto failed;
+ }
+ }
+ echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
+ ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
+ return;
+
+failed:
+ for (i = 0; i < vec_len (fds); i++)
+ close (fds[i]);
+ vec_free (fds);
+}
+
+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_LOG (2, "Unmaped segment 0x%lx", mp->segment_handle);
+}
+
+static void
handle_mq_event (session_event_t * e)
{
switch (e->event_type)
@@ -727,6 +802,12 @@ handle_mq_event (session_event_t * e)
case SESSION_CTRL_EVT_UNLISTEN_REPLY:
return session_unlisten_handler ((session_unlisten_reply_msg_t *)
e->data);
+ case SESSION_CTRL_EVT_APP_ADD_SEGMENT:
+ add_segment_handler ((session_app_add_segment_msg_t *) e->data);
+ break;
+ case SESSION_CTRL_EVT_APP_DEL_SEGMENT:
+ del_segment_handler ((session_app_del_segment_msg_t *) e->data);
+ break;
case SESSION_IO_EVT_RX:
break;
default:
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
index 04eba24156c..cff331a1482 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo_bapi.c
@@ -198,8 +198,8 @@ echo_send_disconnect_session (echo_main_t * em, void *args)
*
*/
-static int
-ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
+int
+echo_ssvm_segment_attach (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;
@@ -218,7 +218,7 @@ ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
return 0;
}
-static inline void
+void
echo_segment_handle_add_del (echo_main_t * em, u64 segment_handle, u8 add)
{
clib_spinlock_lock (&em->segment_handles_lock);
@@ -315,7 +315,7 @@ 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 (ssvm_segment_attach (0, SSVM_SEGMENT_MEMFD, fds[n_fds++]))
+ if (echo_ssvm_segment_attach (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");
@@ -323,8 +323,8 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
}
if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
- if (ssvm_segment_attach ((char *) mp->segment_name,
- SSVM_SEGMENT_MEMFD, fds[n_fds++]))
+ if (echo_ssvm_segment_attach ((char *) mp->segment_name,
+ SSVM_SEGMENT_MEMFD, fds[n_fds++]))
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
"svm_fifo_segment_attach ('%s') "
@@ -338,8 +338,8 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
}
else
{
- if (ssvm_segment_attach ((char *) mp->segment_name, SSVM_SEGMENT_SHM,
- -1))
+ if (echo_ssvm_segment_attach
+ ((char *) mp->segment_name, SSVM_SEGMENT_SHM, -1))
{
ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
"svm_fifo_segment_attach ('%s') "
@@ -371,74 +371,11 @@ vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
echo_main.state = STATE_DETACHED;
}
-static void
-vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
-{
- echo_main_t *em = &echo_main;
- u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
- echo_segment_handle_add_del (em, segment_handle, 0 /* add */ );
- ECHO_LOG (2, "Unmaped segment 0x%lx", segment_handle);
-}
-
-static void
-vl_api_map_another_segment_t_handler (vl_api_map_another_segment_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 = clib_net_to_host_u64 (mp->segment_handle);
-
- if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
- {
- vec_validate (fds, 1);
- if (vl_socket_client_recv_fd_msg (fds, 1, 5))
- {
- ECHO_FAIL (ECHO_FAIL_VL_API_RECV_FD_MSG,
- "vl_socket_client_recv_fd_msg failed");
- goto failed;
- }
-
- if (ssvm_segment_attach (seg_name, SSVM_SEGMENT_MEMFD, fds[0]))
- {
- ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
- "svm_fifo_segment_attach ('%s') "
- "failed on SSVM_SEGMENT_MEMFD", seg_name);
- goto failed;
- }
- vec_free (fds);
- }
- else
- {
- clib_memset (a, 0, sizeof (*a));
- a->segment_name = seg_name;
- a->segment_size = mp->segment_size;
- /* Attach to the segment vpp created */
- if (fifo_segment_attach (sm, a))
- {
- ECHO_FAIL (ECHO_FAIL_VL_API_FIFO_SEG_ATTACH,
- "fifo_segment_attach ('%s') failed", seg_name);
- goto failed;
- }
- }
- echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
- ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
- return;
-
-failed:
- for (i = 0; i < vec_len (fds); i++)
- close (fds[i]);
- vec_free (fds);
-}
-
#define foreach_quic_echo_msg \
_(APP_ATTACH_REPLY, app_attach_reply) \
_(APPLICATION_DETACH_REPLY, application_detach_reply) \
-_(MAP_ANOTHER_SEGMENT, map_another_segment) \
_(APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply) \
-_(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply) \
-_(UNMAP_SEGMENT, unmap_segment)
+_(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
void
echo_api_hookup (echo_main_t * em)
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.c b/src/plugins/hs_apps/sapi/vpp_echo_common.c
index 0642ee67429..e38b17cc013 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_common.c
+++ b/src/plugins/hs_apps/sapi/vpp_echo_common.c
@@ -593,28 +593,6 @@ echo_get_session_from_handle (echo_main_t * em, u64 handle)
}
int
-wait_for_segment_allocation (u64 segment_handle)
-{
- echo_main_t *em = &echo_main;
- f64 timeout;
- timeout = clib_time_now (&em->clib_time) + TIMEOUT;
- uword *segment_present;
- ECHO_LOG (3, "Waiting for segment 0x%lx...", segment_handle);
- while (clib_time_now (&em->clib_time) < timeout)
- {
- 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;
- if (em->time_to_stop == 1)
- return 0;
- }
- ECHO_LOG (2, "timeout wait_for_segment_allocation (0x%lx)", segment_handle);
- return -1;
-}
-
-int
wait_for_state_change (echo_main_t * em, connection_state_t state,
f64 timeout)
{
diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.h b/src/plugins/hs_apps/sapi/vpp_echo_common.h
index 264d1695af0..0c85b499e9c 100644
--- a/src/plugins/hs_apps/sapi/vpp_echo_common.h
+++ b/src/plugins/hs_apps/sapi/vpp_echo_common.h
@@ -432,7 +432,6 @@ void echo_session_handle_add_del (echo_main_t * em, u64 handle, u32 sid);
echo_session_t *echo_session_new (echo_main_t * em);
int echo_send_rpc (echo_main_t * em, void *fp, echo_rpc_args_t * args);
echo_session_t *echo_get_session_from_handle (echo_main_t * em, u64 handle);
-int wait_for_segment_allocation (u64 segment_handle);
int wait_for_state_change (echo_main_t * em, connection_state_t state,
f64 timeout);
void echo_notify_event (echo_main_t * em, echo_test_evt_t e);
@@ -440,6 +439,9 @@ 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);
/* Binary API */