Commit | Line | Data |
---|---|---|
7591bab1 MD |
1 | #ifndef _STREAM_H |
2 | #define _STREAM_H | |
3 | ||
2a174661 DG |
4 | /* |
5 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
6 | * David Goulet <dgoulet@efficios.com> | |
7591bab1 | 7 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2a174661 DG |
8 | * |
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. | |
12 | * | |
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 | |
16 | * more details. | |
17 | * | |
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. | |
21 | */ | |
22 | ||
2a174661 DG |
23 | #include <limits.h> |
24 | #include <inttypes.h> | |
25 | #include <pthread.h> | |
26 | #include <urcu/list.h> | |
27 | ||
28 | #include <common/hashtable/hashtable.h> | |
348a81dc | 29 | #include <common/trace-chunk.h> |
2a174661 DG |
30 | |
31 | #include "session.h" | |
7591bab1 | 32 | #include "stream-fd.h" |
a44ca2ca | 33 | #include "tracefile-array.h" |
2a174661 DG |
34 | |
35 | /* | |
36 | * Represents a stream in the relay | |
37 | */ | |
38 | struct relay_stream { | |
39 | uint64_t stream_handle; | |
7591bab1 | 40 | |
7591bab1 MD |
41 | struct urcu_ref ref; |
42 | /* Back reference to trace. Protected by refcount on trace object. */ | |
43 | struct ctf_trace *trace; | |
2a174661 | 44 | |
7591bab1 MD |
45 | /* |
46 | * To protect from concurrent read/update. The viewer stream | |
47 | * lock nests inside the stream lock. The stream lock nests | |
48 | * inside the ctf_trace lock. | |
49 | */ | |
50 | pthread_mutex_t lock; | |
a8f9f353 JG |
51 | /* previous data sequence number written to disk. */ |
52 | uint64_t prev_data_seq; | |
7a45c7e6 JG |
53 | /* previous index sequence number written to disk. */ |
54 | uint64_t prev_index_seq; | |
a8f9f353 JG |
55 | /* seq num to encounter before closing. */ |
56 | uint64_t last_net_seq_num; | |
7591bab1 MD |
57 | |
58 | /* FD on which to write the stream data. */ | |
59 | struct stream_fd *stream_fd; | |
f8f3885c MD |
60 | /* index file on which to write the index data. */ |
61 | struct lttng_index_file *index_file; | |
2a174661 DG |
62 | |
63 | char *path_name; | |
cb523e02 JG |
64 | /* |
65 | * prev_path_name is only used for session rotation support. | |
66 | * It is essentially used to work around the fact that index | |
67 | * files are always created from the 'data' connection. | |
68 | * | |
69 | * Hence, it is possible to receive a ROTATE_STREAM command | |
70 | * which affects the stream's path_name before the creation of | |
71 | * an index file. In this situation, the index file of the | |
72 | * 'previous' chunk would be created in the new destination folder. | |
73 | * | |
74 | * It would then be unlinked when the actual index of the new chunk | |
75 | * is created. | |
76 | */ | |
77 | char *prev_path_name; | |
2a174661 | 78 | char *channel_name; |
7591bab1 MD |
79 | |
80 | /* On-disk circular buffer of tracefiles. */ | |
2a174661 DG |
81 | uint64_t tracefile_size; |
82 | uint64_t tracefile_size_current; | |
83 | uint64_t tracefile_count; | |
7591bab1 | 84 | |
d3ecc550 JD |
85 | /* |
86 | * Position in the tracefile where we have the full index also on disk. | |
87 | */ | |
88 | uint64_t pos_after_last_complete_data_index; | |
89 | ||
a44ca2ca MD |
90 | /* |
91 | * Counts the number of received indexes. The "tag" associated | |
92 | * with an index is taken before incrementing this seqcount. | |
93 | * Therefore, the sequence tag associated with the last index | |
94 | * received is always index_received_seqcount - 1. | |
95 | */ | |
96 | uint64_t index_received_seqcount; | |
2a174661 | 97 | |
a44ca2ca MD |
98 | /* |
99 | * Tracefile array is an index of the stream trace files, | |
100 | * indexed by position. It allows keeping track of the oldest | |
101 | * available indexes when overwriting trace files in tracefile | |
102 | * rotation. | |
103 | */ | |
104 | struct tracefile_array *tfa; | |
2a174661 | 105 | |
bda7c7b9 JG |
106 | bool closed; /* Stream is closed. */ |
107 | bool close_requested; /* Close command has been received. */ | |
2a174661 DG |
108 | |
109 | /* | |
7591bab1 MD |
110 | * Counts number of indexes in indexes_ht. Redundant info. |
111 | * Protected by stream lock. | |
6e7241fe JD |
112 | */ |
113 | int indexes_in_flight; | |
7591bab1 MD |
114 | struct lttng_ht *indexes_ht; |
115 | ||
528f2ffa | 116 | /* |
7591bab1 MD |
117 | * If the stream is inactive, this field is updated with the |
118 | * live beacon timestamp end, when it is active, this | |
119 | * field == -1ULL. | |
528f2ffa | 120 | */ |
7591bab1 MD |
121 | uint64_t beacon_ts_end; |
122 | ||
123 | /* CTF stream ID, -1ULL when unset (first packet not received yet). */ | |
528f2ffa | 124 | uint64_t ctf_stream_id; |
2a174661 | 125 | |
7591bab1 MD |
126 | /* Indicate if the stream was initialized for a data pending command. */ |
127 | bool data_pending_check_done; | |
128 | ||
129 | /* Is this stream a metadata stream ? */ | |
130 | int32_t is_metadata; | |
131 | /* Amount of metadata received (bytes). */ | |
132 | uint64_t metadata_received; | |
133 | ||
2a174661 | 134 | /* |
7591bab1 MD |
135 | * Member of the stream list in struct ctf_trace. |
136 | * Updates are protected by the stream_list_lock. | |
137 | * Traversals are protected by RCU. | |
2a174661 | 138 | */ |
7591bab1 | 139 | struct cds_list_head stream_node; |
2a174661 | 140 | /* |
7591bab1 MD |
141 | * Temporary list belonging to the connection until all streams |
142 | * are received for that connection. | |
143 | * Member of the stream recv list in the connection. | |
144 | * Updates are protected by the stream_recv_list_lock. | |
145 | * Traversals are protected by RCU. | |
2a174661 | 146 | */ |
7591bab1 MD |
147 | bool in_recv_list; |
148 | struct cds_list_head recv_node; | |
149 | bool published; /* Protected by session lock. */ | |
2a174661 | 150 | /* |
7591bab1 | 151 | * Node of stream within global stream hash table. |
2a174661 | 152 | */ |
7591bab1 | 153 | struct lttng_ht_node_u64 node; |
77f7bd85 | 154 | bool in_stream_ht; /* is stream in stream hash table. */ |
7591bab1 | 155 | struct rcu_head rcu_node; /* For call_rcu teardown. */ |
d3ecc550 JD |
156 | /* |
157 | * When we have written the data and index corresponding to this | |
158 | * seq_num, rotate the tracefile (session rotation). The path_name is | |
159 | * already up-to-date. | |
160 | * This is set to -1ULL when no rotation is pending. | |
161 | * | |
162 | * Always access with stream lock held. | |
163 | */ | |
164 | uint64_t rotate_at_seq_num; | |
c6db3843 JG |
165 | /* |
166 | * When rotate_at_seq_num != -1ULL, meaning that a rotation is ongoing, | |
167 | * data_rotated and index_rotated respectively indicate if the stream's | |
168 | * data and index have been rotated. A rotation is considered completed | |
169 | * when both rotations have occurred. | |
170 | */ | |
171 | bool data_rotated; | |
172 | bool index_rotated; | |
d3ecc550 | 173 | /* |
348a81dc JG |
174 | * `trace_chunk` is the trace chunk to which the file currently |
175 | * being produced (if any) belongs. | |
d3ecc550 | 176 | */ |
348a81dc | 177 | struct lttng_trace_chunk *trace_chunk; |
2a174661 DG |
178 | }; |
179 | ||
7591bab1 MD |
180 | struct relay_stream *stream_create(struct ctf_trace *trace, |
181 | uint64_t stream_handle, char *path_name, | |
182 | char *channel_name, uint64_t tracefile_size, | |
348a81dc | 183 | uint64_t tracefile_count); |
7591bab1 MD |
184 | |
185 | struct relay_stream *stream_get_by_id(uint64_t stream_id); | |
186 | bool stream_get(struct relay_stream *stream); | |
187 | void stream_put(struct relay_stream *stream); | |
bda7c7b9 | 188 | void try_stream_close(struct relay_stream *stream); |
7591bab1 MD |
189 | void stream_publish(struct relay_stream *stream); |
190 | void print_relay_streams(void); | |
2a174661 DG |
191 | |
192 | #endif /* _STREAM_H */ |