From: Julien Desfossez Date: Fri, 31 Jan 2014 20:17:06 +0000 (-0500) Subject: Fix: Move static functions up in the code X-Git-Tag: v2.4.0-rc5~40 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0b0866112fc37525a03edcbebeda351a761b8482;p=lttng-tools.git Fix: Move static functions up in the code When we detect that the viewer is trying to get new streams for a session closed and for which it already got all the streams, we can delete and destroy the session, we know it won't be useful anymore. Signed-off-by: Julien Desfossez --- diff --git a/src/bin/lttng-relayd/live.c b/src/bin/lttng-relayd/live.c index 5b9e4248c..831d760ae 100644 --- a/src/bin/lttng-relayd/live.c +++ b/src/bin/lttng-relayd/live.c @@ -835,6 +835,72 @@ end: return found; } +/* + * Delete all streams for a specific session ID. + */ +static void destroy_viewer_streams_by_session(struct relay_session *session) +{ + struct relay_viewer_stream *stream; + struct lttng_ht_iter iter; + + assert(session); + + rcu_read_lock(); + cds_lfht_for_each_entry(viewer_streams_ht->ht, &iter.iter, stream, + stream_n.node) { + struct ctf_trace *ctf_trace; + + health_code_update(); + if (stream->session_id != session->id) { + continue; + } + + ctf_trace = ctf_trace_find_by_path(session->ctf_traces_ht, + stream->path_name); + assert(ctf_trace); + + viewer_stream_delete(stream); + + if (stream->metadata_flag) { + ctf_trace->metadata_sent = 0; + ctf_trace->viewer_metadata_stream = NULL; + } + + viewer_stream_destroy(ctf_trace, stream); + } + rcu_read_unlock(); +} + +static void try_destroy_streams(struct relay_session *session) +{ + struct ctf_trace *ctf_trace; + struct lttng_ht_iter iter; + + assert(session); + + cds_lfht_for_each_entry(session->ctf_traces_ht->ht, &iter.iter, ctf_trace, + node.node) { + /* Attempt to destroy the ctf trace of that session. */ + ctf_trace_try_destroy(session, ctf_trace); + } +} + +/* + * Cleanup a session. + */ +static void cleanup_session(struct relay_connection *conn, + struct relay_session *session) +{ + /* + * Very important that this is done before destroying the session so we + * can put back every viewer stream reference from the ctf_trace. + */ + destroy_viewer_streams_by_session(session); + try_destroy_streams(session); + cds_list_del(&session->viewer_session_list); + session_viewer_try_destroy(conn->sessions_ht, session); +} + /* * Send the viewer the list of current sessions. */ @@ -906,7 +972,7 @@ int viewer_get_new_streams(struct relay_connection *conn) * and try to destroy it. */ cds_list_del(&session->viewer_session_list); - session_viewer_try_destroy(conn->sessions_ht, session); + cleanup_session(conn, session); goto send_reply; } @@ -1677,56 +1743,6 @@ void cleanup_connection_pollfd(struct lttng_poll_event *events, int pollfd) } } -/* - * Delete all streams for a specific session ID. - */ -static void destroy_viewer_streams_by_session(struct relay_session *session) -{ - struct relay_viewer_stream *stream; - struct lttng_ht_iter iter; - - assert(session); - - rcu_read_lock(); - cds_lfht_for_each_entry(viewer_streams_ht->ht, &iter.iter, stream, - stream_n.node) { - struct ctf_trace *ctf_trace; - - health_code_update(); - if (stream->session_id != session->id) { - continue; - } - - ctf_trace = ctf_trace_find_by_path(session->ctf_traces_ht, - stream->path_name); - assert(ctf_trace); - - viewer_stream_delete(stream); - - if (stream->metadata_flag) { - ctf_trace->metadata_sent = 0; - ctf_trace->viewer_metadata_stream = NULL; - } - - viewer_stream_destroy(ctf_trace, stream); - } - rcu_read_unlock(); -} - -static void try_destroy_streams(struct relay_session *session) -{ - struct ctf_trace *ctf_trace; - struct lttng_ht_iter iter; - - assert(session); - - cds_lfht_for_each_entry(session->ctf_traces_ht->ht, &iter.iter, ctf_trace, - node.node) { - /* Attempt to destroy the ctf trace of that session. */ - ctf_trace_try_destroy(session, ctf_trace); - } -} - /* * Delete and destroy a connection. * @@ -1751,14 +1767,7 @@ static void destroy_connection(struct lttng_ht *relay_connections_ht, &conn->viewer_session->sessions_head, viewer_session_list) { DBG("Cleaning connection of session ID %" PRIu64, session->id); - /* - * Very important that this is done before destroying the session so we - * can put back every viewer stream reference from the ctf_trace. - */ - destroy_viewer_streams_by_session(session); - try_destroy_streams(session); - cds_list_del(&session->viewer_session_list); - session_viewer_try_destroy(conn->sessions_ht, session); + cleanup_session(conn, session); } rcu_read_unlock();