X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession%2Fsession.c;h=3eaf9846709e48fb95c88f124f7544771d456fcc;hb=568ebc76b594f8f29bb131b252031d72c055e0b0;hp=952a5a90141fa7f06afd690f449ef8c72c776b17;hpb=ab2f6dbf9f7b7164a9810f4c80c8abf8463e42ad;p=vpp.git diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c index 952a5a90141..3eaf9846709 100644 --- a/src/vnet/session/session.c +++ b/src/vnet/session/session.c @@ -152,6 +152,14 @@ session_free (stream_session_t * s) memset (s, 0xFA, sizeof (*s)); } +static void +session_free_w_fifos (stream_session_t * s) +{ + segment_manager_dealloc_fifos (s->svm_segment_index, s->server_rx_fifo, + s->server_tx_fifo); + session_free (s); +} + int session_alloc_fifos (segment_manager_t * sm, stream_session_t * s) { @@ -390,7 +398,7 @@ session_enqueue_stream_connection (transport_connection_t * tc, { s->enqueue_epoch = enqueue_epoch; vec_add1 (smm->session_to_enqueue[tc->proto][thread_index], - s - smm->sessions[thread_index]); + s->session_index); } } @@ -431,7 +439,7 @@ session_enqueue_dgram_connection (stream_session_t * s, { s->enqueue_epoch = enqueue_epoch; vec_add1 (smm->session_to_enqueue[proto][thread_index], - s - smm->sessions[thread_index]); + s->session_index); } } return enqueued; @@ -486,7 +494,7 @@ stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes) * @return 0 on success or negative number if failed to send notification. */ static inline int -session_enqueue_notify (stream_session_t * s, u8 lock) +session_enqueue_notify (stream_session_t * s) { app_worker_t *app; @@ -504,10 +512,7 @@ session_enqueue_notify (stream_session_t * s, u8 lock) })); /* *INDENT-ON* */ - if (lock) - return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_RX); - - return app_worker_send_event (app, s, FIFO_EVENT_APP_RX); + return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_RX); } int @@ -519,10 +524,7 @@ session_dequeue_notify (stream_session_t * s) if (PREDICT_FALSE (!app)) return -1; - if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) - return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_RX); - - return app_worker_send_event (app, s, FIFO_EVENT_APP_TX); + return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_TX); } /** @@ -537,14 +539,11 @@ int session_manager_flush_enqueue_events (u8 transport_proto, u32 thread_index) { session_manager_main_t *smm = &session_manager_main; - transport_service_type_t tp_service; - int i, errors = 0, lock; stream_session_t *s; + int i, errors = 0; u32 *indices; indices = smm->session_to_enqueue[transport_proto][thread_index]; - tp_service = transport_protocol_service_type (transport_proto); - lock = tp_service == TRANSPORT_SERVICE_CL; for (i = 0; i < vec_len (indices); i++) { @@ -554,7 +553,7 @@ session_manager_flush_enqueue_events (u8 transport_proto, u32 thread_index) errors++; continue; } - if (PREDICT_FALSE (session_enqueue_notify (s, lock))) + if (PREDICT_FALSE (session_enqueue_notify (s))) errors++; } @@ -760,7 +759,7 @@ stream_session_disconnect_notify (transport_connection_t * tc) stream_session_t *s; s = session_get (tc->s_index, tc->thread_index); - s->session_state = SESSION_STATE_CLOSING; + s->session_state = SESSION_STATE_TRANSPORT_CLOSING; app_wrk = app_worker_get_if_valid (s->app_wrk_index); if (!app_wrk) return; @@ -782,10 +781,7 @@ stream_session_delete (stream_session_t * s) if ((rv = session_lookup_del_session (s))) clib_warning ("hash delete error, rv %d", rv); - /* Cleanup fifo segments */ - segment_manager_dealloc_fifos (s->svm_segment_index, s->server_rx_fifo, - s->server_tx_fifo); - session_free (s); + session_free_w_fifos (s); } /** @@ -802,10 +798,30 @@ stream_session_delete_notify (transport_connection_t * tc) stream_session_t *s; /* App might've been removed already */ - s = session_get_if_valid (tc->s_index, tc->thread_index); - if (!s) + if (!(s = session_get_if_valid (tc->s_index, tc->thread_index))) return; - stream_session_delete (s); + + /* Make sure we don't try to send anything more */ + svm_fifo_dequeue_drop_all (s->server_tx_fifo); + + switch (s->session_state) + { + case SESSION_STATE_TRANSPORT_CLOSING: + /* If transport finishes or times out before we get a reply + * from the app, do the whole disconnect since we might still + * have lingering events */ + stream_session_disconnect (s); + break; + case SESSION_STATE_CLOSING: + /* Cleanup lookup table. Transport needs to still be valid */ + session_lookup_del_session (s); + break; + case SESSION_STATE_CLOSED: + stream_session_delete (s); + break; + } + + s->session_state = SESSION_STATE_CLOSED; } /** @@ -838,7 +854,7 @@ stream_session_accept (transport_connection_t * tc, u32 listener_index, /* Find the server */ listener = listen_session_get (listener_index); - app_wrk = app_worker_get (listener->app_wrk_index); + app_wrk = application_listener_select_worker (listener, 0); sm = app_worker_get_listen_segment_manager (app_wrk, listener); if ((rv = session_alloc_and_init (sm, tc, 1, &s))) @@ -984,21 +1000,23 @@ session_listen (stream_session_t * ls, session_endpoint_extended_t * sep) { transport_connection_t *tc; transport_endpoint_t *tep; - u32 tc_index; + u32 tc_index, s_index; /* Transport bind/listen */ tep = session_endpoint_to_transport (sep); - tc_index = tp_vfts[sep->transport_proto].bind (ls->session_index, tep); + s_index = ls->session_index; + tc_index = tp_vfts[sep->transport_proto].bind (s_index, tep); if (tc_index == (u32) ~ 0) return -1; /* Attach transport to session */ + ls = listen_session_get (s_index); ls->connection_index = tc_index; /* Add to the main lookup table after transport was initialized */ tc = tp_vfts[sep->transport_proto].get_listener (tc_index); - session_lookup_add_connection (tc, ls->session_index); + session_lookup_add_connection (tc, s_index); return 0; } @@ -1057,11 +1075,9 @@ stream_session_disconnect (stream_session_t * s) s->session_state = SESSION_STATE_CLOSING; /* If we are in the handler thread, or being called with the worker barrier - * held (api/cli), just append a new event to pending disconnects vector. */ - if ((thread_index == 0 && !vlib_get_current_process (vlib_get_main ())) - || thread_index == s->thread_index) + * held, just append a new event to pending disconnects vector. */ + if (vlib_thread_is_main_w_barrier () || thread_index == s->thread_index) { - ASSERT (s->thread_index == thread_index || thread_index == 0); vec_add2 (smm->pending_disconnects[s->thread_index], evt, 1); memset (evt, 0, sizeof (*evt)); evt->session_handle = session_handle (s); @@ -1081,6 +1097,12 @@ stream_session_disconnect (stream_session_t * s) void stream_session_disconnect_transport (stream_session_t * s) { + /* If transport is already closed, just free the session */ + if (s->session_state == SESSION_STATE_CLOSED) + { + session_free_w_fifos (s); + return; + } s->session_state = SESSION_STATE_CLOSED; tp_vfts[session_get_transport_proto (s)].close (s->connection_index, s->thread_index); @@ -1104,9 +1126,7 @@ stream_session_cleanup (stream_session_t * s) s->thread_index); /* Since we called cleanup, no delete notification will come. So, make * sure the session is properly freed. */ - segment_manager_dealloc_fifos (s->svm_segment_index, s->server_rx_fifo, - s->server_tx_fifo); - session_free (s); + session_free_w_fifos (s); } transport_service_type_t