X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fhs_apps%2Fsapi%2Fvpp_echo.c;h=0550006f949d2b917207ae727ddc9c80d0beb61a;hb=c4c4cf506;hp=84089c6b51257f825bb3cbfbcd1154da18c11b28;hpb=d849edf3841c1c9774c5ce209a2b903415f2370a;p=vpp.git 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"); @@ -708,6 +723,66 @@ session_reset_handler (session_reset_msg_t * mp) app_send_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt); } +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) { @@ -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: