summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/vcl/vcl_bapi.c82
-rw-r--r--src/vcl/vcl_private.c41
-rw-r--r--src/vcl/vcl_private.h4
-rw-r--r--src/vcl/vppcom.c94
-rw-r--r--src/vnet/session/application_interface.h23
-rw-r--r--src/vnet/session/application_worker.c5
-rw-r--r--src/vnet/session/session.api2
-rw-r--r--src/vnet/session/session_api.c113
-rw-r--r--src/vnet/session/session_types.h5
13 files changed, 354 insertions, 207 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 */
diff --git a/src/vcl/vcl_bapi.c b/src/vcl/vcl_bapi.c
index b91e928f3e9..efa5cc170ef 100644
--- a/src/vcl/vcl_bapi.c
+++ b/src/vcl/vcl_bapi.c
@@ -61,46 +61,6 @@ static void
vcm->app_state = STATE_APP_ENABLED;
}
-static int
-vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
- int fd)
-{
- fifo_segment_create_args_t _a, *a = &_a;
- int rv;
-
- memset (a, 0, sizeof (*a));
- a->segment_name = (char *) name;
- a->segment_type = type;
-
- if (type == SSVM_SEGMENT_MEMFD)
- a->memfd_fd = fd;
-
- if ((rv = fifo_segment_attach (&vcm->segment_main, a)))
- {
- clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
- return rv;
- }
- vcl_segment_table_add (segment_handle, a->new_segment_indices[0]);
- vec_reset_length (a->new_segment_indices);
- return 0;
-}
-
-static void
-vcl_segment_detach (u64 segment_handle)
-{
- fifo_segment_main_t *sm = &vcm->segment_main;
- fifo_segment_t *segment;
- u32 segment_index;
-
- segment_index = vcl_segment_table_lookup (segment_handle);
- if (segment_index == (u32) ~ 0)
- return;
- segment = fifo_segment_get_segment (sm, segment_index);
- fifo_segment_delete (sm, segment);
- vcl_segment_table_del (segment_handle);
- VDBG (0, "detached segment %u handle %u", segment_index, segment_handle);
-}
-
static u64
vcl_vpp_worker_segment_handle (u32 wrk_index)
{
@@ -260,46 +220,6 @@ failed:
}
static void
-vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
-{
- ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM;
- u64 segment_handle;
- int fd = -1;
-
- if (mp->fd_flags)
- {
- vl_socket_client_recv_fd_msg (&fd, 1, 5);
- seg_type = SSVM_SEGMENT_MEMFD;
- }
-
- segment_handle = clib_net_to_host_u64 (mp->segment_handle);
- if (segment_handle == VCL_INVALID_SEGMENT_HANDLE)
- {
- clib_warning ("invalid segment handle");
- return;
- }
-
- if (vcl_segment_attach (segment_handle, (char *) mp->segment_name,
- seg_type, fd))
- {
- clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
- getpid (), mp->segment_name);
- return;
- }
-
- VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (),
- mp->segment_name, mp->segment_size);
-}
-
-static void
-vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
-{
- u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
- vcl_segment_detach (segment_handle);
- VDBG (1, "Unmapped segment: %d", segment_handle);
-}
-
-static void
vl_api_application_tls_cert_add_reply_t_handler
(vl_api_application_tls_cert_add_reply_t * mp)
{
@@ -322,8 +242,6 @@ _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
_(APP_ATTACH_REPLY, app_attach_reply) \
_(APPLICATION_TLS_CERT_ADD_REPLY, application_tls_cert_add_reply) \
_(APPLICATION_TLS_KEY_ADD_REPLY, application_tls_key_add_reply) \
-_(MAP_ANOTHER_SEGMENT, map_another_segment) \
-_(UNMAP_SEGMENT, unmap_segment) \
_(APP_WORKER_ADD_DEL_REPLY, app_worker_add_del_reply) \
void
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index 6e887c878cd..f3cee5d6f8e 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -405,6 +405,47 @@ vcl_session_write_ready (vcl_session_t * session)
return svm_fifo_max_enqueue_prod (session->tx_fifo);
}
+int
+vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
+ int fd)
+{
+ fifo_segment_create_args_t _a, *a = &_a;
+ int rv;
+
+ memset (a, 0, sizeof (*a));
+ a->segment_name = (char *) name;
+ a->segment_type = type;
+
+ if (type == SSVM_SEGMENT_MEMFD)
+ a->memfd_fd = fd;
+
+ if ((rv = fifo_segment_attach (&vcm->segment_main, a)))
+ {
+ clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
+ return rv;
+ }
+ vcl_segment_table_add (segment_handle, a->new_segment_indices[0]);
+ vec_reset_length (a->new_segment_indices);
+ return 0;
+}
+
+void
+vcl_segment_detach (u64 segment_handle)
+{
+ fifo_segment_main_t *sm = &vcm->segment_main;
+ fifo_segment_t *segment;
+ u32 segment_index;
+
+ segment_index = vcl_segment_table_lookup (segment_handle);
+ if (segment_index == (u32) ~ 0)
+ return;
+ segment = fifo_segment_get_segment (sm, segment_index);
+ fifo_segment_delete (sm, segment);
+ vcl_segment_table_del (segment_handle);
+ VDBG (0, "detached segment %u handle %u", segment_index, segment_handle);
+}
+
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h
index 9116111afe2..db4bcd315b6 100644
--- a/src/vcl/vcl_private.h
+++ b/src/vcl/vcl_private.h
@@ -626,6 +626,10 @@ void vppcom_send_application_tls_key_add (vcl_session_t * session, char *key,
void vcl_send_app_worker_add_del (u8 is_add);
void vcl_send_child_worker_del (vcl_worker_t * wrk);
+int vcl_segment_attach (u64 segment_handle, char *name,
+ ssvm_segment_type_t type, int fd);
+void vcl_segment_detach (u64 segment_handle);
+
u32 vcl_max_nsid_len (void);
u8 *format_api_error (u8 * s, va_list * args);
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index a854011fa0d..4224a086a21 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -23,23 +23,17 @@
__thread uword __vcl_worker_index = ~0;
static int
-vcl_wait_for_segment (u64 segment_handle)
+vcl_segment_is_not_mounted (vcl_worker_t * wrk, u64 segment_handle)
{
- vcl_worker_t *wrk = vcl_worker_get_current ();
- u32 wait_for_seconds = 10, segment_index;
- f64 timeout;
+ u32 segment_index;
if (segment_handle == VCL_INVALID_SEGMENT_HANDLE)
return 0;
- timeout = clib_time_now (&wrk->clib_time) + wait_for_seconds;
- while (clib_time_now (&wrk->clib_time) < timeout)
- {
- segment_index = vcl_segment_table_lookup (segment_handle);
- if (segment_index != VCL_INVALID_SEGMENT_INDEX)
- return 0;
- usleep (10);
- }
+ segment_index = vcl_segment_table_lookup (segment_handle);
+ if (segment_index != VCL_INVALID_SEGMENT_INDEX)
+ return 0;
+
return 1;
}
@@ -371,9 +365,9 @@ vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp,
goto error;
}
- if (vcl_wait_for_segment (mp->segment_handle))
+ if (vcl_segment_is_not_mounted (wrk, mp->segment_handle))
{
- VDBG (0, "ERROR: segment for session %u couldn't be mounted!",
+ VDBG (0, "ERROR: segment for session %u is not mounted!",
session->session_index);
goto error;
}
@@ -459,9 +453,9 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
svm_msg_q_t *);
rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
- if (vcl_wait_for_segment (mp->segment_handle))
+ if (vcl_segment_is_not_mounted (wrk, mp->segment_handle))
{
- VDBG (0, "segment for session %u couldn't be mounted!",
+ VDBG (0, "segment for session %u is not mounted!",
session->session_index);
session->session_state = STATE_FAILED | STATE_DISCONNECT;
vcl_send_session_disconnect (wrk, session);
@@ -481,9 +475,9 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
{
session->ct_rx_fifo = uword_to_pointer (mp->ct_rx_fifo, svm_fifo_t *);
session->ct_tx_fifo = uword_to_pointer (mp->ct_tx_fifo, svm_fifo_t *);
- if (vcl_wait_for_segment (mp->ct_segment_handle))
+ if (vcl_segment_is_not_mounted (wrk, mp->ct_segment_handle))
{
- VDBG (0, "ct segment for session %u couldn't be mounted!",
+ VDBG (0, "ct segment for session %u is not mounted!",
session->session_index);
session->session_state = STATE_FAILED | STATE_DISCONNECT;
vcl_send_session_disconnect (wrk, session);
@@ -715,9 +709,9 @@ vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
VDBG (0, "unknown handle 0x%llx", msg->handle);
return;
}
- if (vcl_wait_for_segment (msg->segment_handle))
+ if (vcl_segment_is_not_mounted (wrk, msg->segment_handle))
{
- clib_warning ("segment for session %u couldn't be mounted!",
+ clib_warning ("segment for session %u is not mounted!",
s->session_index);
return;
}
@@ -737,6 +731,48 @@ vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
s->vpp_handle, wrk->wrk_index);
}
+static void
+vcl_session_app_add_segment_handler (vcl_worker_t * wrk, void *data)
+{
+ ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM;
+ session_app_add_segment_msg_t *msg;
+ u64 segment_handle;
+ int fd = -1;
+
+ msg = (session_app_add_segment_msg_t *) data;
+
+ if (msg->fd_flags)
+ {
+ vl_socket_client_recv_fd_msg2 (&wrk->bapi_sock_ctx, &fd, 1, 5);
+ seg_type = SSVM_SEGMENT_MEMFD;
+ }
+
+ segment_handle = msg->segment_handle;
+ if (segment_handle == VCL_INVALID_SEGMENT_HANDLE)
+ {
+ clib_warning ("invalid segment handle");
+ return;
+ }
+
+ if (vcl_segment_attach (segment_handle, (char *) msg->segment_name,
+ seg_type, fd))
+ {
+ VDBG (0, "vcl_segment_attach ('%s') failed", msg->segment_name);
+ return;
+ }
+
+ VDBG (1, "mapped new segment '%s' size %d", msg->segment_name,
+ msg->segment_size);
+}
+
+static void
+vcl_session_app_del_segment_handler (vcl_worker_t * wrk, void *data)
+{
+ session_app_del_segment_msg_t *msg = (session_app_del_segment_msg_t *) data;
+ vcl_segment_detach (msg->segment_handle);
+ VDBG (1, "Unmapped segment: %d", msg->segment_handle);
+}
+
static int
vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
{
@@ -782,6 +818,12 @@ vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY:
vcl_session_worker_update_reply_handler (wrk, e->data);
break;
+ case SESSION_CTRL_EVT_APP_ADD_SEGMENT:
+ vcl_session_app_add_segment_handler (wrk, e->data);
+ break;
+ case SESSION_CTRL_EVT_APP_DEL_SEGMENT:
+ vcl_session_app_del_segment_handler (wrk, e->data);
+ break;
default:
clib_warning ("unhandled %u", e->event_type);
}
@@ -2091,6 +2133,12 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
case SESSION_CTRL_EVT_REQ_WORKER_UPDATE:
vcl_session_req_worker_update_handler (wrk, e->data);
break;
+ case SESSION_CTRL_EVT_APP_ADD_SEGMENT:
+ vcl_session_app_add_segment_handler (wrk, e->data);
+ break;
+ case SESSION_CTRL_EVT_APP_DEL_SEGMENT:
+ vcl_session_app_del_segment_handler (wrk, e->data);
+ break;
default:
clib_warning ("unhandled: %u", e->event_type);
break;
@@ -2669,6 +2717,12 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY:
vcl_session_worker_update_reply_handler (wrk, e->data);
break;
+ case SESSION_CTRL_EVT_APP_ADD_SEGMENT:
+ vcl_session_app_add_segment_handler (wrk, e->data);
+ break;
+ case SESSION_CTRL_EVT_APP_DEL_SEGMENT:
+ vcl_session_app_del_segment_handler (wrk, e->data);
+ break;
default:
VDBG (0, "unhandled: %u", e->event_type);
break;
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index a40aa9d9a7f..2e850a98e57 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -29,13 +29,13 @@ typedef struct certificate_
u8 *cert;
} app_cert_key_pair_t;
-typedef struct _stream_session_cb_vft
+typedef struct session_cb_vft_
{
/** Notify server of new segment */
- int (*add_segment_callback) (u32 api_client_index, u64 segment_handle);
+ int (*add_segment_callback) (u32 app_wrk_index, u64 segment_handle);
/** Notify server of new segment */
- int (*del_segment_callback) (u32 api_client_index, u64 segment_handle);
+ int (*del_segment_callback) (u32 app_wrk_index, u64 segment_handle);
/** Notify server of newly accepted session */
int (*session_accept_callback) (session_t * new_session);
@@ -485,6 +485,23 @@ typedef struct session_app_detach_msg_
u32 context;
} session_app_detach_msg_t;
+typedef struct app_map_another_segment_msg_
+{
+ u32 client_index;
+ u32 context;
+ u8 fd_flags;
+ u32 segment_size;
+ u8 segment_name[128];
+ u64 segment_handle;
+} session_app_add_segment_msg_t;
+
+typedef struct app_unmap_segment_msg_
+{
+ u32 client_index;
+ u32 context;
+ u64 segment_handle;
+} session_app_del_segment_msg_t;
+
typedef struct app_session_event_
{
svm_msg_q_msg_t msg;
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index bb51cb71f03..1db6baab74e 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -526,7 +526,8 @@ int
app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
{
application_t *app = application_get (app_wrk->app_index);
- return app->cb_fns.add_segment_callback (app_wrk->api_client_index,
+
+ return app->cb_fns.add_segment_callback (app_wrk->wrk_index,
segment_handle);
}
@@ -534,7 +535,7 @@ int
app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle)
{
application_t *app = application_get (app_wrk->app_index);
- return app->cb_fns.del_segment_callback (app_wrk->api_client_index,
+ return app->cb_fns.del_segment_callback (app_wrk->wrk_index,
segment_handle);
}
diff --git a/src/vnet/session/session.api b/src/vnet/session/session.api
index 33e53419a8d..4f9ae12eeb3 100644
--- a/src/vnet/session/session.api
+++ b/src/vnet/session/session.api
@@ -187,6 +187,7 @@ autoreply define application_detach {
};
/** \brief vpp->client, please map an additional shared memory segment
+ ### WILL BE DEPRECATED POST 20.01 ###
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param fd_flags - set of flags that indicate which, if any, fds are
@@ -206,6 +207,7 @@ autoreply define map_another_segment {
};
/** \brief vpp->client unmap shared memory segment
+ ### WILL BE DEPRECATED POST 20.01 ###
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param segment_name - segment name
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 99e00a78bf3..153c528059c 100644
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -81,6 +81,7 @@ session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
return 0;
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static int
send_add_segment_callback (u32 api_client_index, u64 segment_handle)
{
@@ -130,6 +131,7 @@ send_add_segment_callback (u32 api_client_index, u64 segment_handle)
return 0;
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static int
send_del_segment_callback (u32 api_client_index, u64 segment_handle)
{
@@ -471,7 +473,103 @@ mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh)
clib_warning ("not supported");
}
-static session_cb_vft_t session_mq_cb_vft = {
+static int
+mq_send_add_segment_cb (u32 app_wrk_index, u64 segment_handle)
+{
+ int fds[SESSION_N_FD_TYPE], n_fds = 0;
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ session_app_add_segment_msg_t *mp;
+ vl_api_registration_t *reg;
+ app_worker_t *app_wrk;
+ session_event_t *evt;
+ svm_msg_q_t *app_mq;
+ fifo_segment_t *fs;
+ ssvm_private_t *sp;
+ u8 fd_flags = 0;
+
+ app_wrk = app_worker_get (app_wrk_index);
+
+ reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
+ if (!reg)
+ {
+ clib_warning ("no api registration for client: %u",
+ app_wrk->api_client_index);
+ return -1;
+ }
+
+ fs = segment_manager_get_segment_w_handle (segment_handle);
+ sp = &fs->ssvm;
+ if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
+ {
+ if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
+ {
+ clib_warning ("can't send memfd fd");
+ return -1;
+ }
+
+ fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
+ fds[n_fds] = sp->fd;
+ n_fds += 1;
+ }
+
+ app_mq = app_wrk->event_queue;
+ if (mq_try_lock_and_alloc_msg (app_mq, msg))
+ return -1;
+
+ if (n_fds)
+ session_send_fds (reg, fds, n_fds);
+
+ evt = svm_msg_q_msg_data (app_mq, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_APP_ADD_SEGMENT;
+ mp = (session_app_add_segment_msg_t *) evt->data;
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->segment_size = sp->ssvm_size;
+ mp->fd_flags = fd_flags;
+ mp->segment_handle = segment_handle;
+ strncpy ((char *) mp->segment_name, (char *) sp->name,
+ sizeof (mp->segment_name) - 1);
+
+ svm_msg_q_add_and_unlock (app_mq, msg);
+
+ return 0;
+}
+
+static int
+mq_send_del_segment_cb (u32 app_wrk_index, u64 segment_handle)
+{
+ svm_msg_q_msg_t _msg, *msg = &_msg;
+ session_app_del_segment_msg_t *mp;
+ vl_api_registration_t *reg;
+ app_worker_t *app_wrk;
+ session_event_t *evt;
+ svm_msg_q_t *app_mq;
+
+ app_wrk = app_worker_get (app_wrk_index);
+ reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
+ if (!reg)
+ {
+ clib_warning ("no registration: %u", app_wrk->api_client_index);
+ return -1;
+ }
+
+ app_mq = app_wrk->event_queue;
+ if (mq_try_lock_and_alloc_msg (app_mq, msg))
+ return -1;
+
+ evt = svm_msg_q_msg_data (app_mq, msg);
+ clib_memset (evt, 0, sizeof (*evt));
+ evt->event_type = SESSION_CTRL_EVT_APP_DEL_SEGMENT;
+ mp = (session_app_del_segment_msg_t *) evt->data;
+ clib_memset (mp, 0, sizeof (*mp));
+ mp->segment_handle = segment_handle;
+ svm_msg_q_add_and_unlock (app_mq, msg);
+
+ return 0;
+}
+
+/* ### WILL BE DEPRECATED POST 20.01 ### */
+static session_cb_vft_t session_mq_cb_vft_old = {
.session_accept_callback = mq_send_session_accepted_cb,
.session_disconnect_callback = mq_send_session_disconnected_cb,
.session_connected_callback = mq_send_session_connected_cb,
@@ -481,6 +579,16 @@ static session_cb_vft_t session_mq_cb_vft = {
.del_segment_callback = send_del_segment_callback,
};
+static session_cb_vft_t session_mq_cb_vft = {
+ .session_accept_callback = mq_send_session_accepted_cb,
+ .session_disconnect_callback = mq_send_session_disconnected_cb,
+ .session_connected_callback = mq_send_session_connected_cb,
+ .session_reset_callback = mq_send_session_reset_cb,
+ .session_migrate_callback = mq_send_session_migrate_cb,
+ .add_segment_callback = mq_send_add_segment_cb,
+ .del_segment_callback = mq_send_del_segment_cb,
+};
+
static void
vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
{
@@ -520,7 +628,7 @@ vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
clib_memset (a, 0, sizeof (*a));
a->api_client_index = mp->client_index;
a->options = mp->options;
- a->session_cb_vft = &session_mq_cb_vft;
+ a->session_cb_vft = &session_mq_cb_vft_old;
if (mp->namespace_id_len > 64)
{
rv = VNET_API_ERROR_INVALID_VALUE;
@@ -888,6 +996,7 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
}
}
+/* ### WILL BE DEPRECATED POST 20.01 ### */
static void
vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
* mp)
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index 16d48431572..ce593b0b38c 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -334,6 +334,8 @@ typedef enum
SESSION_CTRL_EVT_LISTEN_URI,
SESSION_CTRL_EVT_UNLISTEN,
SESSION_CTRL_EVT_APP_DETACH,
+ SESSION_CTRL_EVT_APP_ADD_SEGMENT,
+ SESSION_CTRL_EVT_APP_DEL_SEGMENT,
} session_evt_type_t;
#define foreach_session_ctrl_evt \
@@ -355,7 +357,8 @@ typedef enum
_(WORKER_UPDATE, worker_update) \
_(WORKER_UPDATE_REPLY, worker_update_reply) \
_(APP_DETACH, app_detach) \
-
+ _(APP_ADD_SEGMENT, app_add_segment) \
+ _(APP_DEL_SEGMENT, app_del_segment) \
/* Deprecated and will be removed. Use types above */
#define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX