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"
35 * Represents a stream in the relay
38 uint64_t stream_handle
;
41 * reflock used to synchronize the closing of this stream.
42 * stream reflock nests inside viewer stream reflock.
43 * stream reflock nests inside index reflock.
45 pthread_mutex_t reflock
;
47 /* Back reference to trace. Protected by refcount on trace object. */
48 struct ctf_trace
*trace
;
51 * To protect from concurrent read/update. The viewer stream
52 * lock nests inside the stream lock. The stream lock nests
53 * inside the ctf_trace lock.
56 uint64_t prev_seq
; /* previous data sequence number encountered. */
57 uint64_t prev_index_seq
; /* previous index sequence number encountered. */
58 uint64_t last_net_seq_num
; /* seq num to encounter before closing. */
60 /* FD on which to write the stream data. */
61 struct stream_fd
*stream_fd
;
62 /* index file on which to write the index data. */
63 struct lttng_index_file
*index_file
;
68 /* On-disk circular buffer of tracefiles. */
69 uint64_t tracefile_size
;
70 uint64_t tracefile_size_current
;
71 uint64_t tracefile_count
;
72 uint64_t tracefile_count_current
;
75 * Counts the number of received indexes. The "tag" associated
76 * with an index is taken before incrementing this seqcount.
77 * Therefore, the sequence tag associated with the last index
78 * received is always index_received_seqcount - 1.
80 uint64_t index_received_seqcount
;
84 * Index sequence number for the position at which clear needs to be
87 uint64_t clear_position_index_seqcount
;
88 uint64_t clear_position_data_seqcount
;
91 * Tracefile array is an index of the stream trace files,
92 * indexed by position. It allows keeping track of the oldest
93 * available indexes when overwriting trace files in tracefile
96 struct tracefile_array
*tfa
;
98 bool closed
; /* Stream is closed. */
99 bool close_requested
; /* Close command has been received. */
102 * Counts number of indexes in indexes_ht. Redundant info.
103 * Protected by stream lock.
105 int indexes_in_flight
;
106 struct lttng_ht
*indexes_ht
;
109 * If the stream is inactive, this field is updated with the
110 * live beacon timestamp end, when it is active, this
113 uint64_t beacon_ts_end
;
115 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
116 uint64_t ctf_stream_id
;
118 /* Indicate if the stream was initialized for a data pending command. */
119 bool data_pending_check_done
;
121 /* Is this stream a metadata stream ? */
123 /* Amount of metadata received (bytes). */
124 uint64_t metadata_received
;
127 * Member of the stream list in struct ctf_trace.
128 * Updates are protected by the stream_list_lock.
129 * Traversals are protected by RCU.
131 struct cds_list_head stream_node
;
133 * Temporary list belonging to the connection until all streams
134 * are received for that connection.
135 * Member of the stream recv list in the connection.
136 * Updates are protected by the stream_recv_list_lock.
137 * Traversals are protected by RCU.
140 struct cds_list_head recv_node
;
141 bool published
; /* Protected by session lock. */
143 * Node of stream within global stream hash table.
145 struct lttng_ht_node_u64 node
;
146 bool in_stream_ht
; /* is stream in stream hash table. */
147 struct rcu_head rcu_node
; /* For call_rcu teardown. */
150 struct relay_stream
*stream_create(struct ctf_trace
*trace
,
151 uint64_t stream_handle
, char *path_name
,
152 char *channel_name
, uint64_t tracefile_size
,
153 uint64_t tracefile_count
);
155 struct relay_stream
*stream_get_by_id(uint64_t stream_id
);
156 bool stream_get(struct relay_stream
*stream
);
157 void stream_put(struct relay_stream
*stream
);
158 void try_stream_close(struct relay_stream
*stream
);
159 void stream_publish(struct relay_stream
*stream
);
160 void print_relay_streams(void);
161 int stream_clear(struct relay_stream
*stream
);
162 int try_stream_clear_index_data(struct relay_stream
*stream
);
164 #endif /* _STREAM_H */