5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <urcu/list.h>
28 #include <common/hashtable/hashtable.h>
31 #include "stream-fd.h"
32 #include "tracefile-array.h"
34 struct relay_stream_chunk_id
{
40 * Represents a stream in the relay
43 uint64_t stream_handle
;
46 /* Back reference to trace. Protected by refcount on trace object. */
47 struct ctf_trace
*trace
;
50 * To protect from concurrent read/update. The viewer stream
51 * lock nests inside the stream lock. The stream lock nests
52 * inside the ctf_trace lock.
55 uint64_t prev_seq
; /* previous data sequence number encountered. */
56 uint64_t last_net_seq_num
; /* seq num to encounter before closing. */
58 /* FD on which to write the stream data. */
59 struct stream_fd
*stream_fd
;
60 /* index file on which to write the index data. */
61 struct lttng_index_file
*index_file
;
66 /* On-disk circular buffer of tracefiles. */
67 uint64_t tracefile_size
;
68 uint64_t tracefile_size_current
;
69 uint64_t tracefile_count
;
72 * Position in the tracefile where we have the full index also on disk.
74 uint64_t pos_after_last_complete_data_index
;
77 * Counts the number of received indexes. The "tag" associated
78 * with an index is taken before incrementing this seqcount.
79 * Therefore, the sequence tag associated with the last index
80 * received is always index_received_seqcount - 1.
82 uint64_t index_received_seqcount
;
85 * Tracefile array is an index of the stream trace files,
86 * indexed by position. It allows keeping track of the oldest
87 * available indexes when overwriting trace files in tracefile
90 struct tracefile_array
*tfa
;
92 bool closed
; /* Stream is closed. */
93 bool close_requested
; /* Close command has been received. */
96 * Counts number of indexes in indexes_ht. Redundant info.
97 * Protected by stream lock.
99 int indexes_in_flight
;
100 struct lttng_ht
*indexes_ht
;
103 * If the stream is inactive, this field is updated with the
104 * live beacon timestamp end, when it is active, this
107 uint64_t beacon_ts_end
;
109 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
110 uint64_t ctf_stream_id
;
112 /* Indicate if the stream was initialized for a data pending command. */
113 bool data_pending_check_done
;
115 /* Is this stream a metadata stream ? */
117 /* Amount of metadata received (bytes). */
118 uint64_t metadata_received
;
121 * Member of the stream list in struct ctf_trace.
122 * Updates are protected by the stream_list_lock.
123 * Traversals are protected by RCU.
125 struct cds_list_head stream_node
;
127 * Temporary list belonging to the connection until all streams
128 * are received for that connection.
129 * Member of the stream recv list in the connection.
130 * Updates are protected by the stream_recv_list_lock.
131 * Traversals are protected by RCU.
134 struct cds_list_head recv_node
;
135 bool published
; /* Protected by session lock. */
137 * Node of stream within global stream hash table.
139 struct lttng_ht_node_u64 node
;
140 bool in_stream_ht
; /* is stream in stream hash table. */
141 struct rcu_head rcu_node
; /* For call_rcu teardown. */
143 * When we have written the data and index corresponding to this
144 * seq_num, rotate the tracefile (session rotation). The path_name is
145 * already up-to-date.
146 * This is set to -1ULL when no rotation is pending.
148 * Always access with stream lock held.
150 uint64_t rotate_at_seq_num
;
152 * This is the id of the chunk where we are writing to if no rotation is
153 * pending (rotate_at_seq_num == -1ULL). If a rotation is pending, this
154 * is the chunk_id we will have after the rotation. It must be updated
155 * atomically with rotate_at_seq_num.
157 * Always access with stream lock held.
159 * This attribute is not set if the stream is created by a pre-2.11
162 struct relay_stream_chunk_id current_chunk_id
;
165 struct relay_stream
*stream_create(struct ctf_trace
*trace
,
166 uint64_t stream_handle
, char *path_name
,
167 char *channel_name
, uint64_t tracefile_size
,
168 uint64_t tracefile_count
, const struct relay_stream_chunk_id
*chunk_id
);
170 struct relay_stream
*stream_get_by_id(uint64_t stream_id
);
171 bool stream_get(struct relay_stream
*stream
);
172 void stream_put(struct relay_stream
*stream
);
173 void try_stream_close(struct relay_stream
*stream
);
174 void stream_publish(struct relay_stream
*stream
);
175 void print_relay_streams(void);
177 #endif /* _STREAM_H */