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 /* previous data sequence number written to disk. */
56 uint64_t prev_data_seq
;
57 /* previous index sequence number written to disk. */
58 uint64_t prev_index_seq
;
59 /* seq num to encounter before closing. */
60 uint64_t last_net_seq_num
;
62 /* FD on which to write the stream data. */
63 struct stream_fd
*stream_fd
;
64 /* index file on which to write the index data. */
65 struct lttng_index_file
*index_file
;
69 * prev_path_name is only used for session rotation support.
70 * It is essentially used to work around the fact that index
71 * files are always created from the 'data' connection.
73 * Hence, it is possible to receive a ROTATE_STREAM command
74 * which affects the stream's path_name before the creation of
75 * an index file. In this situation, the index file of the
76 * 'previous' chunk would be created in the new destination folder.
78 * It would then be unlinked when the actual index of the new chunk
84 /* On-disk circular buffer of tracefiles. */
85 uint64_t tracefile_size
;
86 uint64_t tracefile_size_current
;
87 uint64_t tracefile_count
;
90 * Position in the tracefile where we have the full index also on disk.
92 uint64_t pos_after_last_complete_data_index
;
95 * Counts the number of received indexes. The "tag" associated
96 * with an index is taken before incrementing this seqcount.
97 * Therefore, the sequence tag associated with the last index
98 * received is always index_received_seqcount - 1.
100 uint64_t index_received_seqcount
;
103 * Tracefile array is an index of the stream trace files,
104 * indexed by position. It allows keeping track of the oldest
105 * available indexes when overwriting trace files in tracefile
108 struct tracefile_array
*tfa
;
110 bool closed
; /* Stream is closed. */
111 bool close_requested
; /* Close command has been received. */
114 * Counts number of indexes in indexes_ht. Redundant info.
115 * Protected by stream lock.
117 int indexes_in_flight
;
118 struct lttng_ht
*indexes_ht
;
121 * If the stream is inactive, this field is updated with the
122 * live beacon timestamp end, when it is active, this
125 uint64_t beacon_ts_end
;
127 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
128 uint64_t ctf_stream_id
;
130 /* Indicate if the stream was initialized for a data pending command. */
131 bool data_pending_check_done
;
133 /* Is this stream a metadata stream ? */
135 /* Amount of metadata received (bytes). */
136 uint64_t metadata_received
;
139 * Member of the stream list in struct ctf_trace.
140 * Updates are protected by the stream_list_lock.
141 * Traversals are protected by RCU.
143 struct cds_list_head stream_node
;
145 * Temporary list belonging to the connection until all streams
146 * are received for that connection.
147 * Member of the stream recv list in the connection.
148 * Updates are protected by the stream_recv_list_lock.
149 * Traversals are protected by RCU.
152 struct cds_list_head recv_node
;
153 bool published
; /* Protected by session lock. */
155 * Node of stream within global stream hash table.
157 struct lttng_ht_node_u64 node
;
158 bool in_stream_ht
; /* is stream in stream hash table. */
159 struct rcu_head rcu_node
; /* For call_rcu teardown. */
161 * When we have written the data and index corresponding to this
162 * seq_num, rotate the tracefile (session rotation). The path_name is
163 * already up-to-date.
164 * This is set to -1ULL when no rotation is pending.
166 * Always access with stream lock held.
168 uint64_t rotate_at_seq_num
;
170 * When rotate_at_seq_num != -1ULL, meaning that a rotation is ongoing,
171 * data_rotated and index_rotated respectively indicate if the stream's
172 * data and index have been rotated. A rotation is considered completed
173 * when both rotations have occurred.
178 * This is the id of the chunk where we are writing to if no rotation is
179 * pending (rotate_at_seq_num == -1ULL). If a rotation is pending, this
180 * is the chunk_id we will have after the rotation. It must be updated
181 * atomically with rotate_at_seq_num.
183 * Always access with stream lock held.
185 * This attribute is not set if the stream is created by a pre-2.11
188 struct relay_stream_chunk_id current_chunk_id
;
191 struct relay_stream
*stream_create(struct ctf_trace
*trace
,
192 uint64_t stream_handle
, char *path_name
,
193 char *channel_name
, uint64_t tracefile_size
,
194 uint64_t tracefile_count
, const struct relay_stream_chunk_id
*chunk_id
);
196 struct relay_stream
*stream_get_by_id(uint64_t stream_id
);
197 bool stream_get(struct relay_stream
*stream
);
198 void stream_put(struct relay_stream
*stream
);
199 void try_stream_close(struct relay_stream
*stream
);
200 void stream_publish(struct relay_stream
*stream
);
201 void print_relay_streams(void);
203 #endif /* _STREAM_H */