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> | |
d3e2ba59 | 26 | |
0f907de1 | 27 | #include <common/hashtable/hashtable.h> |
1c20f0e2 | 28 | #include <common/index/lttng-index.h> |
b8aa1682 | 29 | |
d3e2ba59 JD |
30 | #include "ctf-trace.h" |
31 | ||
b8aa1682 JD |
32 | /* |
33 | * Queue used to enqueue relay requests | |
34 | */ | |
35 | struct relay_cmd_queue { | |
b8aa1682 | 36 | struct cds_wfq_queue queue; |
7717e361 | 37 | int32_t futex; |
b8aa1682 JD |
38 | }; |
39 | ||
40 | enum connection_type { | |
d5200de1 DG |
41 | RELAY_DATA = 1, |
42 | RELAY_CONTROL = 2, | |
43 | RELAY_VIEWER_COMMAND = 3, | |
44 | RELAY_VIEWER_NOTIFICATION = 4, | |
b8aa1682 JD |
45 | }; |
46 | ||
47 | /* | |
48 | * Represents a session for the relay point of view | |
49 | */ | |
50 | struct relay_session { | |
f7079f67 DG |
51 | /* |
52 | * This session id is used to identify a set of stream to a tracing session | |
53 | * but also make sure we have a unique session id associated with a session | |
54 | * daemon which can provide multiple data source. | |
55 | */ | |
b8aa1682 JD |
56 | uint64_t id; |
57 | struct lttcomm_sock *sock; | |
d3e2ba59 JD |
58 | char session_name[NAME_MAX]; |
59 | char hostname[HOST_NAME_MAX]; | |
60 | uint32_t live_timer; | |
61 | struct lttng_ht_node_ulong session_n; | |
62 | struct rcu_head rcu_node; | |
63 | uint32_t viewer_attached; | |
64 | uint32_t stream_count; | |
7d2f7452 DG |
65 | /* Tell if this session is for a snapshot or not. */ |
66 | unsigned int snapshot:1; | |
67 | ||
68 | /* | |
69 | * Indicate version protocol for this session. This is especially useful | |
70 | * for the data thread that has no idea which version it operates on since | |
71 | * linking control/data sockets is non trivial. | |
72 | */ | |
73 | uint64_t minor; | |
74 | uint64_t major; | |
b8aa1682 JD |
75 | }; |
76 | ||
77 | /* | |
78 | * Represents a stream in the relay | |
79 | */ | |
80 | struct relay_stream { | |
81 | uint64_t stream_handle; | |
173af62f | 82 | uint64_t prev_seq; /* previous data sequence number encountered */ |
7717e361 | 83 | struct lttng_ht_node_ulong stream_n; |
b8aa1682 | 84 | struct relay_session *session; |
9d1bbf21 | 85 | struct rcu_head rcu_node; |
7717e361 | 86 | int fd; |
1c20f0e2 | 87 | /* FD on which to write the index data. */ |
309167d2 | 88 | int index_fd; |
d3e2ba59 JD |
89 | /* FD on which to read the index data for the viewer. */ |
90 | int read_index_fd; | |
173af62f | 91 | |
0f907de1 JD |
92 | char *path_name; |
93 | char *channel_name; | |
94 | /* on-disk circular buffer of tracefiles */ | |
95 | uint64_t tracefile_size; | |
96 | uint64_t tracefile_size_current; | |
97 | uint64_t tracefile_count; | |
98 | uint64_t tracefile_count_current; | |
6b6b9a5a JD |
99 | /* To inform the viewer up to where it can go back in time. */ |
100 | uint64_t oldest_tracefile_id; | |
0f907de1 | 101 | |
d3e2ba59 JD |
102 | uint64_t total_index_received; |
103 | struct relay_viewer_stream *viewer_stream; | |
104 | uint64_t last_net_seq_num; | |
c07d8a78 DG |
105 | |
106 | /* | |
107 | * This node is added to the *control* connection hash table and the | |
108 | * pointer is copied in here so we can access it when deleting this object. | |
109 | * When deleting this, the ctf trace ht MUST NOT be destroyed. This happens | |
110 | * at connection deletion. | |
111 | */ | |
d3e2ba59 | 112 | struct lttng_ht_node_str ctf_trace_node; |
c07d8a78 | 113 | struct lttng_ht *ctf_traces_ht; |
d3e2ba59 JD |
114 | |
115 | /* | |
116 | * To protect from concurrent read/update between the | |
117 | * streaming-side and the viewer-side. | |
118 | * This lock must be held, we reading/updating the | |
119 | * ctf_trace pointer. | |
120 | */ | |
121 | pthread_mutex_t lock; | |
122 | ||
123 | struct ctf_trace *ctf_trace; | |
124 | /* | |
125 | * If the stream is inactive, this field is updated with the live beacon | |
126 | * timestamp end, when it is active, this field == -1ULL. | |
127 | */ | |
128 | uint64_t beacon_ts_end; | |
6b6b9a5a JD |
129 | /* |
130 | * To protect the update of the close_write_flag and the checks of | |
131 | * the tracefile_count_current. | |
132 | * It is taken before checking whenever we need to know if the | |
133 | * writer and reader are working in the same tracefile. | |
134 | */ | |
135 | pthread_mutex_t viewer_stream_rotation_lock; | |
d3e2ba59 | 136 | |
173af62f DG |
137 | /* Information telling us when to close the stream */ |
138 | unsigned int close_flag:1; | |
f7079f67 DG |
139 | /* Indicate if the stream was initialized for a data pending command. */ |
140 | unsigned int data_pending_check_done:1; | |
d3e2ba59 | 141 | unsigned int metadata_flag:1; |
6b6b9a5a JD |
142 | /* |
143 | * To detect when we start overwriting old data, it is used to | |
144 | * update the oldest_tracefile_id. | |
145 | */ | |
146 | unsigned int tracefile_overwrite:1; | |
d3e2ba59 JD |
147 | }; |
148 | ||
149 | /* | |
150 | * Shadow copy of the relay_stream structure for the viewer side. The only | |
151 | * fields updated by the writer (streaming side) after allocation are : | |
152 | * total_index_received and close_flag. Everything else is updated by the | |
153 | * reader (viewer side). | |
154 | */ | |
155 | struct relay_viewer_stream { | |
156 | uint64_t stream_handle; | |
157 | uint64_t session_id; | |
158 | int read_fd; | |
159 | int index_read_fd; | |
160 | char *path_name; | |
161 | char *channel_name; | |
162 | uint64_t last_sent_index; | |
163 | uint64_t total_index_received; | |
d3e2ba59 JD |
164 | uint64_t tracefile_count; |
165 | uint64_t tracefile_count_current; | |
166 | struct lttng_ht_node_u64 stream_n; | |
167 | struct rcu_head rcu_node; | |
168 | struct ctf_trace *ctf_trace; | |
cef0f7d5 JD |
169 | /* |
170 | * This lock blocks only when the writer is about to start overwriting | |
171 | * a file currently read by the reader. | |
172 | */ | |
173 | pthread_mutex_t overwrite_lock; | |
d3e2ba59 JD |
174 | /* Information telling us if the stream is a metadata stream. */ |
175 | unsigned int metadata_flag:1; | |
6b6b9a5a JD |
176 | /* |
177 | * Information telling us that the stream is closed in write, so | |
178 | * we don't expect new indexes and we can read up to EOF. | |
179 | */ | |
180 | unsigned int close_write_flag:1; | |
181 | /* | |
182 | * If the streaming side closes a FD in use in the viewer side, | |
183 | * it sets this flag to inform that it is a normal error. | |
184 | */ | |
185 | unsigned int abort_flag:1; | |
b8aa1682 JD |
186 | }; |
187 | ||
188 | /* | |
189 | * Internal structure to map a socket with the corresponding session. | |
190 | * A hashtable indexed on the socket FD is used for the lookups. | |
191 | */ | |
192 | struct relay_command { | |
193 | struct lttcomm_sock *sock; | |
7717e361 | 194 | struct relay_session *session; |
b8aa1682 JD |
195 | struct cds_wfq_node node; |
196 | struct lttng_ht_node_ulong sock_n; | |
9d1bbf21 | 197 | struct rcu_head rcu_node; |
b8aa1682 | 198 | enum connection_type type; |
c5b6f4f0 | 199 | unsigned int version_check_done:1; |
0f907de1 JD |
200 | /* protocol version to use for this session */ |
201 | uint32_t major; | |
202 | uint32_t minor; | |
d3e2ba59 | 203 | struct lttng_ht *ctf_traces_ht; /* indexed by path name */ |
b92fdc2b | 204 | uint64_t session_id; |
d3e2ba59 JD |
205 | }; |
206 | ||
207 | struct relay_local_data { | |
208 | struct lttng_ht *sessions_ht; | |
b8aa1682 JD |
209 | }; |
210 | ||
0f907de1 JD |
211 | extern char *opt_output_path; |
212 | ||
d3e2ba59 | 213 | extern struct lttng_ht *relay_streams_ht; |
92c6ca54 | 214 | extern struct lttng_ht *viewer_streams_ht; |
0a6518b0 | 215 | extern struct lttng_ht *indexes_ht; |
d3e2ba59 | 216 | |
65931c8b MD |
217 | extern const char *tracing_group_name; |
218 | ||
d3e2ba59 JD |
219 | struct relay_stream *relay_stream_find_by_id(uint64_t stream_id); |
220 | ||
7717e361 | 221 | #endif /* LTTNG_RELAYD_H */ |