-static void destroy_stream(struct relay_stream *stream)
-{
- int delret;
- struct relay_viewer_stream *vstream;
- struct lttng_ht_iter iter;
-
- assert(stream);
-
- delret = close(stream->fd);
- if (delret < 0) {
- PERROR("close stream");
- }
-
- if (stream->index_fd >= 0) {
- delret = close(stream->index_fd);
- if (delret < 0) {
- PERROR("close stream index_fd");
- }
- }
-
- vstream = live_find_viewer_stream_by_id(stream->stream_handle);
- if (vstream) {
- /*
- * Set the last good value into the viewer stream. This is done
- * right before the stream gets deleted from the hash table. The
- * lookup failure on the live thread side of a stream indicates
- * that the viewer stream index received value should be used.
- */
- pthread_mutex_lock(&stream->viewer_stream_rotation_lock);
- vstream->total_index_received = stream->total_index_received;
- vstream->tracefile_count_last = stream->tracefile_count_current;
- vstream->close_write_flag = 1;
- pthread_mutex_unlock(&stream->viewer_stream_rotation_lock);
- }
-
- /* Cleanup index of that stream. */
- relay_index_destroy_by_stream_id(stream->stream_handle);
-
- iter.iter.node = &stream->stream_n.node;
- delret = lttng_ht_del(relay_streams_ht, &iter);
- assert(!delret);
- iter.iter.node = &stream->ctf_trace_node.node;
- delret = lttng_ht_del(stream->ctf_traces_ht, &iter);
- assert(!delret);
-
- if (stream->ctf_trace) {
- ctf_trace_try_destroy(stream->ctf_trace);
- }
-
- call_rcu(&stream->rcu_node, deferred_free_stream);
- DBG("Closed tracefile %d from close stream", stream->fd);
-}
-
-/*
- * relay_delete_session: Free all memory associated with a session and
- * close all the FDs
- */
-static
-void relay_delete_session(struct relay_command *cmd,
- struct lttng_ht *sessions_ht)
-{
- struct lttng_ht_iter iter;
- struct lttng_ht_node_ulong *node;
- struct relay_stream *stream;
- int ret;
-
- if (!cmd->session) {
- return;
- }
-
- DBG("Relay deleting session %" PRIu64, cmd->session->id);
-
- rcu_read_lock();
- cds_lfht_for_each_entry(relay_streams_ht->ht, &iter.iter, node, node) {
- node = lttng_ht_iter_get_node_ulong(&iter);
- if (!node) {
- continue;
- }
- stream = caa_container_of(node, struct relay_stream, stream_n);
- if (stream->session == cmd->session) {
- destroy_stream(stream);
- cmd->session->stream_count--;
- assert(cmd->session->stream_count >= 0);
- }
- }
-
- /* Make this session not visible anymore. */
- iter.iter.node = &cmd->session->session_n.node;
- ret = lttng_ht_del(sessions_ht, &iter);
- assert(!ret);
- call_rcu(&cmd->session->rcu_node, deferred_free_session);
- rcu_read_unlock();
-}
-
-/*
- * Copy index data from the control port to a given index object.
- */
-static void copy_index_control_data(struct relay_index *index,