Commit | Line | Data |
---|---|---|
b8aa1682 JD |
1 | /* |
2 | * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com> | |
3 | * David Goulet <dgoulet@efficios.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
7717e361 MD |
19 | #ifndef LTTNG_RELAYD_H |
20 | #define LTTNG_RELAYD_H | |
b8aa1682 JD |
21 | |
22 | #define _LGPL_SOURCE | |
d3e2ba59 | 23 | #include <limits.h> |
b8aa1682 JD |
24 | #include <urcu.h> |
25 | #include <urcu/wfqueue.h> | |
a4baae1b | 26 | #include <urcu/list.h> |
d3e2ba59 | 27 | |
0f907de1 | 28 | #include <common/hashtable/hashtable.h> |
50adc264 | 29 | #include <common/index/ctf-index.h> |
b8aa1682 | 30 | |
d3e2ba59 JD |
31 | #include "ctf-trace.h" |
32 | ||
b8aa1682 JD |
33 | /* |
34 | * Queue used to enqueue relay requests | |
35 | */ | |
36 | struct relay_cmd_queue { | |
b8aa1682 | 37 | struct cds_wfq_queue queue; |
7717e361 | 38 | int32_t futex; |
b8aa1682 JD |
39 | }; |
40 | ||
41 | enum connection_type { | |
d5200de1 DG |
42 | RELAY_DATA = 1, |
43 | RELAY_CONTROL = 2, | |
44 | RELAY_VIEWER_COMMAND = 3, | |
45 | RELAY_VIEWER_NOTIFICATION = 4, | |
b8aa1682 JD |
46 | }; |
47 | ||
a4baae1b JD |
48 | /* |
49 | * When we receive a stream, it gets stored in a list (on a per connection | |
50 | * basis) until we have all the streams of the same channel and the metadata | |
51 | * associated with it, then it gets flagged with viewer_ready. | |
52 | */ | |
53 | struct relay_stream_recv_handle { | |
54 | uint64_t id; /* stream handle */ | |
55 | struct cds_list_head node; | |
56 | }; | |
57 | ||
b8aa1682 JD |
58 | /* |
59 | * Represents a session for the relay point of view | |
60 | */ | |
61 | struct relay_session { | |
f7079f67 DG |
62 | /* |
63 | * This session id is used to identify a set of stream to a tracing session | |
64 | * but also make sure we have a unique session id associated with a session | |
65 | * daemon which can provide multiple data source. | |
66 | */ | |
b8aa1682 JD |
67 | uint64_t id; |
68 | struct lttcomm_sock *sock; | |
d3e2ba59 JD |
69 | char session_name[NAME_MAX]; |
70 | char hostname[HOST_NAME_MAX]; | |
71 | uint32_t live_timer; | |
72 | struct lttng_ht_node_ulong session_n; | |
73 | struct rcu_head rcu_node; | |
74 | uint32_t viewer_attached; | |
75 | uint32_t stream_count; | |
7d2f7452 DG |
76 | /* Tell if this session is for a snapshot or not. */ |
77 | unsigned int snapshot:1; | |
78 | ||
79 | /* | |
80 | * Indicate version protocol for this session. This is especially useful | |
81 | * for the data thread that has no idea which version it operates on since | |
82 | * linking control/data sockets is non trivial. | |
83 | */ | |
84 | uint64_t minor; | |
85 | uint64_t major; | |
4a9daf17 JD |
86 | /* |
87 | * Flag checked and exchanged with uatomic_cmpxchg to tell the | |
88 | * viewer-side if new streams got added since the last check. | |
89 | */ | |
90 | unsigned long new_streams; | |
80e8027a JD |
91 | |
92 | /* | |
93 | * Used to synchronize the process where we flag every streams readiness | |
94 | * for the viewer when the streams_sent message is received and the viewer | |
95 | * process of sending those streams. | |
96 | */ | |
97 | pthread_mutex_t viewer_ready_lock; | |
b8aa1682 JD |
98 | }; |
99 | ||
100 | /* | |
101 | * Represents a stream in the relay | |
102 | */ | |
103 | struct relay_stream { | |
104 | uint64_t stream_handle; | |
173af62f | 105 | uint64_t prev_seq; /* previous data sequence number encountered */ |
7717e361 | 106 | struct lttng_ht_node_ulong stream_n; |
b8aa1682 | 107 | struct relay_session *session; |
9d1bbf21 | 108 | struct rcu_head rcu_node; |
7717e361 | 109 | int fd; |
1c20f0e2 | 110 | /* FD on which to write the index data. */ |
309167d2 | 111 | int index_fd; |
d3e2ba59 JD |
112 | /* FD on which to read the index data for the viewer. */ |
113 | int read_index_fd; | |
173af62f | 114 | |
0f907de1 JD |
115 | char *path_name; |
116 | char *channel_name; | |
117 | /* on-disk circular buffer of tracefiles */ | |
118 | uint64_t tracefile_size; | |
119 | uint64_t tracefile_size_current; | |
120 | uint64_t tracefile_count; | |
121 | uint64_t tracefile_count_current; | |
6b6b9a5a JD |
122 | /* To inform the viewer up to where it can go back in time. */ |
123 | uint64_t oldest_tracefile_id; | |
0f907de1 | 124 | |
d3e2ba59 JD |
125 | uint64_t total_index_received; |
126 | struct relay_viewer_stream *viewer_stream; | |
127 | uint64_t last_net_seq_num; | |
c07d8a78 DG |
128 | |
129 | /* | |
130 | * This node is added to the *control* connection hash table and the | |
131 | * pointer is copied in here so we can access it when deleting this object. | |
132 | * When deleting this, the ctf trace ht MUST NOT be destroyed. This happens | |
133 | * at connection deletion. | |
134 | */ | |
d3e2ba59 | 135 | struct lttng_ht_node_str ctf_trace_node; |
c07d8a78 | 136 | struct lttng_ht *ctf_traces_ht; |
d3e2ba59 JD |
137 | |
138 | /* | |
139 | * To protect from concurrent read/update between the | |
140 | * streaming-side and the viewer-side. | |
141 | * This lock must be held, we reading/updating the | |
142 | * ctf_trace pointer. | |
143 | */ | |
144 | pthread_mutex_t lock; | |
145 | ||
146 | struct ctf_trace *ctf_trace; | |
147 | /* | |
148 | * If the stream is inactive, this field is updated with the live beacon | |
149 | * timestamp end, when it is active, this field == -1ULL. | |
150 | */ | |
151 | uint64_t beacon_ts_end; | |
6b6b9a5a JD |
152 | /* |
153 | * To protect the update of the close_write_flag and the checks of | |
154 | * the tracefile_count_current. | |
155 | * It is taken before checking whenever we need to know if the | |
156 | * writer and reader are working in the same tracefile. | |
157 | */ | |
158 | pthread_mutex_t viewer_stream_rotation_lock; | |
d3e2ba59 | 159 | |
173af62f DG |
160 | /* Information telling us when to close the stream */ |
161 | unsigned int close_flag:1; | |
f7079f67 DG |
162 | /* Indicate if the stream was initialized for a data pending command. */ |
163 | unsigned int data_pending_check_done:1; | |
d3e2ba59 | 164 | unsigned int metadata_flag:1; |
6b6b9a5a JD |
165 | /* |
166 | * To detect when we start overwriting old data, it is used to | |
167 | * update the oldest_tracefile_id. | |
168 | */ | |
169 | unsigned int tracefile_overwrite:1; | |
a4baae1b JD |
170 | /* |
171 | * Can this stream be used by a viewer or are we waiting for additional | |
172 | * information. | |
173 | */ | |
174 | unsigned int viewer_ready:1; | |
d3e2ba59 JD |
175 | }; |
176 | ||
177 | /* | |
178 | * Shadow copy of the relay_stream structure for the viewer side. The only | |
179 | * fields updated by the writer (streaming side) after allocation are : | |
180 | * total_index_received and close_flag. Everything else is updated by the | |
181 | * reader (viewer side). | |
182 | */ | |
183 | struct relay_viewer_stream { | |
184 | uint64_t stream_handle; | |
185 | uint64_t session_id; | |
186 | int read_fd; | |
187 | int index_read_fd; | |
188 | char *path_name; | |
189 | char *channel_name; | |
190 | uint64_t last_sent_index; | |
191 | uint64_t total_index_received; | |
d3e2ba59 JD |
192 | uint64_t tracefile_count; |
193 | uint64_t tracefile_count_current; | |
a020f610 JD |
194 | /* Stop after reading this tracefile. */ |
195 | uint64_t tracefile_count_last; | |
d3e2ba59 JD |
196 | struct lttng_ht_node_u64 stream_n; |
197 | struct rcu_head rcu_node; | |
198 | struct ctf_trace *ctf_trace; | |
cef0f7d5 JD |
199 | /* |
200 | * This lock blocks only when the writer is about to start overwriting | |
201 | * a file currently read by the reader. | |
d39add63 DG |
202 | * |
203 | * This is nested INSIDE the viewer_stream_rotation_lock. | |
cef0f7d5 JD |
204 | */ |
205 | pthread_mutex_t overwrite_lock; | |
d3e2ba59 JD |
206 | /* Information telling us if the stream is a metadata stream. */ |
207 | unsigned int metadata_flag:1; | |
6b6b9a5a JD |
208 | /* |
209 | * Information telling us that the stream is closed in write, so | |
210 | * we don't expect new indexes and we can read up to EOF. | |
211 | */ | |
212 | unsigned int close_write_flag:1; | |
213 | /* | |
214 | * If the streaming side closes a FD in use in the viewer side, | |
215 | * it sets this flag to inform that it is a normal error. | |
216 | */ | |
217 | unsigned int abort_flag:1; | |
80e8027a JD |
218 | /* Indicates if this stream has been sent to a viewer client. */ |
219 | unsigned int sent_flag:1; | |
b8aa1682 JD |
220 | }; |
221 | ||
222 | /* | |
223 | * Internal structure to map a socket with the corresponding session. | |
224 | * A hashtable indexed on the socket FD is used for the lookups. | |
225 | */ | |
226 | struct relay_command { | |
227 | struct lttcomm_sock *sock; | |
7717e361 | 228 | struct relay_session *session; |
b8aa1682 JD |
229 | struct cds_wfq_node node; |
230 | struct lttng_ht_node_ulong sock_n; | |
9d1bbf21 | 231 | struct rcu_head rcu_node; |
b8aa1682 | 232 | enum connection_type type; |
0f907de1 JD |
233 | /* protocol version to use for this session */ |
234 | uint32_t major; | |
235 | uint32_t minor; | |
d3e2ba59 | 236 | struct lttng_ht *ctf_traces_ht; /* indexed by path name */ |
b92fdc2b | 237 | uint64_t session_id; |
a4baae1b JD |
238 | struct cds_list_head recv_head; |
239 | unsigned int version_check_done:1; | |
d3e2ba59 JD |
240 | }; |
241 | ||
242 | struct relay_local_data { | |
243 | struct lttng_ht *sessions_ht; | |
b8aa1682 JD |
244 | }; |
245 | ||
0f907de1 JD |
246 | extern char *opt_output_path; |
247 | ||
d3e2ba59 | 248 | extern struct lttng_ht *relay_streams_ht; |
92c6ca54 | 249 | extern struct lttng_ht *viewer_streams_ht; |
0a6518b0 | 250 | extern struct lttng_ht *indexes_ht; |
d3e2ba59 | 251 | |
65931c8b MD |
252 | extern const char *tracing_group_name; |
253 | ||
cd60b05a JG |
254 | extern const char * const config_section_name; |
255 | ||
0b242f62 MD |
256 | extern int thread_quit_pipe[2]; |
257 | ||
d3e2ba59 | 258 | struct relay_stream *relay_stream_find_by_id(uint64_t stream_id); |
3fd27398 | 259 | void lttng_relay_notify_ready(void); |
d3e2ba59 | 260 | |
7717e361 | 261 | #endif /* LTTNG_RELAYD_H */ |