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 /* Back reference to trace. Protected by refcount on trace object. */
42 struct ctf_trace
*trace
;
45 * To protect from concurrent read/update. The viewer stream
46 * lock nests inside the stream lock. The stream lock nests
47 * inside the ctf_trace lock.
50 uint64_t prev_seq
; /* previous data sequence number encountered. */
51 uint64_t last_net_seq_num
; /* seq num to encounter before closing. */
53 /* FD on which to write the stream data. */
54 struct stream_fd
*stream_fd
;
55 /* index file on which to write the index data. */
56 struct lttng_index_file
*index_file
;
61 /* On-disk circular buffer of tracefiles. */
62 uint64_t tracefile_size
;
63 uint64_t tracefile_size_current
;
64 uint64_t tracefile_count
;
67 * Position in the tracefile where we have the full index also on disk.
69 uint64_t pos_after_last_complete_data_index
;
72 * Counts the number of received indexes. The "tag" associated
73 * with an index is taken before incrementing this seqcount.
74 * Therefore, the sequence tag associated with the last index
75 * received is always index_received_seqcount - 1.
77 uint64_t index_received_seqcount
;
80 * Tracefile array is an index of the stream trace files,
81 * indexed by position. It allows keeping track of the oldest
82 * available indexes when overwriting trace files in tracefile
85 struct tracefile_array
*tfa
;
87 bool closed
; /* Stream is closed. */
88 bool close_requested
; /* Close command has been received. */
91 * Counts number of indexes in indexes_ht. Redundant info.
92 * Protected by stream lock.
94 int indexes_in_flight
;
95 struct lttng_ht
*indexes_ht
;
98 * If the stream is inactive, this field is updated with the
99 * live beacon timestamp end, when it is active, this
102 uint64_t beacon_ts_end
;
104 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
105 uint64_t ctf_stream_id
;
107 /* Indicate if the stream was initialized for a data pending command. */
108 bool data_pending_check_done
;
110 /* Is this stream a metadata stream ? */
112 /* Amount of metadata received (bytes). */
113 uint64_t metadata_received
;
116 * Member of the stream list in struct ctf_trace.
117 * Updates are protected by the stream_list_lock.
118 * Traversals are protected by RCU.
120 struct cds_list_head stream_node
;
122 * Temporary list belonging to the connection until all streams
123 * are received for that connection.
124 * Member of the stream recv list in the connection.
125 * Updates are protected by the stream_recv_list_lock.
126 * Traversals are protected by RCU.
129 struct cds_list_head recv_node
;
130 bool published
; /* Protected by session lock. */
132 * Node of stream within global stream hash table.
134 struct lttng_ht_node_u64 node
;
135 bool in_stream_ht
; /* is stream in stream hash table. */
136 struct rcu_head rcu_node
; /* For call_rcu teardown. */
138 * When we have written the data and index corresponding to this
139 * seq_num, rotate the tracefile (session rotation). The path_name is
140 * already up-to-date.
141 * This is set to -1ULL when no rotation is pending.
143 * Always access with stream lock held.
145 uint64_t rotate_at_seq_num
;
147 * This is the id of the chunk where we are writing to if no rotation is
148 * pending (rotate_at_seq_num == -1ULL). If a rotation is pending, this
149 * is the chunk_id we will have after the rotation. It must be updated
150 * atomically with rotate_at_seq_num.
152 * Always access with stream lock held.
157 struct relay_stream
*stream_create(struct ctf_trace
*trace
,
158 uint64_t stream_handle
, char *path_name
,
159 char *channel_name
, uint64_t tracefile_size
,
160 uint64_t tracefile_count
);
162 struct relay_stream
*stream_get_by_id(uint64_t stream_id
);
163 bool stream_get(struct relay_stream
*stream
);
164 void stream_put(struct relay_stream
*stream
);
165 void try_stream_close(struct relay_stream
*stream
);
166 void stream_publish(struct relay_stream
*stream
);
167 void print_relay_streams(void);
169 #endif /* _STREAM_H */