+ /* Network sequence number. Indicating on which relayd socket it goes. */
+ uint64_t net_seq_idx;
+ /*
+ * Indicate if this stream was successfully sent to a relayd. This is set
+ * after the refcount of the relayd is incremented and is checked when the
+ * stream is closed before decrementing the refcount in order to avoid an
+ * unbalanced state.
+ */
+ unsigned int sent_to_relayd;
+
+ /* Identify if the stream is the metadata */
+ unsigned int metadata_flag;
+ /* Used when the stream is set for network streaming */
+ uint64_t relayd_stream_id;
+ /*
+ * When sending a stream packet to a relayd, this number is used to track
+ * the packet sent by the consumer and seen by the relayd. When sending the
+ * data header to the relayd, this number is sent and if the transmission
+ * was successful, it is incremented.
+ *
+ * Even if the full data is not fully transmitted it won't matter since
+ * only two possible error can happen after that where either the relayd
+ * died or a read error is detected on the stream making this value useless
+ * after that.
+ *
+ * This value SHOULD be read/updated atomically or with the lock acquired.
+ */
+ uint64_t next_net_seq_num;
+ /*
+ * Lock to use the stream FDs since they are used between threads.
+ *
+ * This is nested INSIDE the consumer_data lock.
+ * This is nested INSIDE the metadata cache lock.
+ * This is nested INSIDE the channel lock.
+ * This is nested OUTSIDE consumer_relayd_sock_pair lock.
+ */
+ pthread_mutex_t lock;
+ /* Tracing session id */
+ uint64_t session_id;
+ /*
+ * Indicates if the stream end point is still active or not (network
+ * streaming or local file system). The thread "owning" the stream is
+ * handling this status and can be notified of a state change through the
+ * consumer data appropriate pipe.
+ */
+ enum consumer_endpoint_status endpoint_status;
+ /* Stream name. Format is: <channel_name>_<cpu_number> */
+ char name[LTTNG_SYMBOL_NAME_LEN];
+ /* Internal state of libustctl. */
+ struct ustctl_consumer_stream *ustream;
+ struct cds_list_head send_node;
+ /* On-disk circular buffer */
+ uint64_t tracefile_size_current;
+ uint64_t tracefile_count_current;
+ /*
+ * Monitor or not the streams of this channel meaning this indicates if the
+ * streams should be sent to the data/metadata thread or added to the no
+ * monitor list of the channel.
+ */
+ unsigned int monitor;
+ /*
+ * Indicate if the stream is globally visible meaning that it has been
+ * added to the multiple hash tables. If *not* set, NO lock should be
+ * acquired in the destroy path.
+ */
+ unsigned int globally_visible;
+ /*
+ * Pipe to wake up the metadata poll thread when the UST metadata
+ * cache is updated.
+ */
+ int ust_metadata_poll_pipe[2];
+ /*
+ * How much metadata was read from the metadata cache and sent
+ * to the channel.
+ */
+ uint64_t ust_metadata_pushed;
+};
+
+/*
+ * Internal representation of a relayd socket pair.
+ */
+struct consumer_relayd_sock_pair {
+ /* Network sequence number. */
+ uint64_t net_seq_idx;
+ /* Number of stream associated with this relayd */
+ unsigned int refcount;
+
+ /*
+ * This flag indicates whether or not we should destroy this object. The
+ * destruction should ONLY occurs when this flag is set and the refcount is
+ * set to zero.
+ */
+ unsigned int destroy_flag;
+
+ /*
+ * Mutex protecting the control socket to avoid out of order packets
+ * between threads sending data to the relayd. Since metadata data is sent
+ * over that socket, at least two sendmsg() are needed (header + data)
+ * creating a race for packets to overlap between threads using it.
+ *
+ * This is nested INSIDE the consumer_data lock.
+ * This is nested INSIDE the stream lock.
+ */
+ pthread_mutex_t ctrl_sock_mutex;
+
+ /* Control socket. Command and metadata are passed over it */
+ struct lttcomm_relayd_sock control_sock;
+
+ /*
+ * We don't need a mutex at this point since we only splice or write single
+ * large chunk of data with a header appended at the begining. Moreover,
+ * this socket is for now only used in a single thread.
+ */
+ struct lttcomm_relayd_sock data_sock;
+ struct lttng_ht_node_u64 node;
+
+ /* Session id on both sides for the sockets. */
+ uint64_t relayd_session_id;
+ uint64_t sessiond_session_id;