-struct relay_stream *relay_stream_find_by_id(uint64_t stream_id)
-{
- struct lttng_ht_node_ulong *node;
- struct lttng_ht_iter iter;
- struct relay_stream *ret;
-
- lttng_ht_lookup(relay_streams_ht,
- (void *)((unsigned long) stream_id),
- &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
- if (node == NULL) {
- DBG("Relay stream %" PRIu64 " not found", stream_id);
- ret = NULL;
- goto end;
- }
-
- ret = caa_container_of(node, struct relay_stream, stream_n);
-
-end:
- return ret;
-}
-
-static
-void deferred_free_stream(struct rcu_head *head)
-{
- struct relay_stream *stream =
- caa_container_of(head, struct relay_stream, rcu_node);
-
- ctf_trace_try_destroy(stream->ctf_trace);
-
- free(stream->path_name);
- free(stream->channel_name);
- free(stream);
-}
-
-static
-void deferred_free_session(struct rcu_head *head)
-{
- struct relay_session *session =
- caa_container_of(head, struct relay_session, rcu_node);
- free(session);
-}
-
-/*
- * Close a given stream. The stream is freed using a call RCU.
- *
- * RCU read side lock MUST be acquired. If NO close_stream_check() was called
- * BEFORE the stream lock MUST be acquired.
- */
-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.
- */
- vstream->total_index_received = stream->total_index_received;
- }
-
- /* 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);
- 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);
- }
- }
-
- /* 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,