Commit | Line | Data |
---|---|---|
b8aa1682 | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
3 | * Copyright (C) 2012 Julien Desfossez <julien.desfossez@efficios.com> | |
b8aa1682 | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
b8aa1682 | 6 | * |
b8aa1682 JD |
7 | */ |
8 | ||
9 | #ifndef _RELAYD_COMM | |
10 | #define _RELAYD_COMM | |
11 | ||
b8aa1682 JD |
12 | #include <limits.h> |
13 | #include <stdint.h> | |
14 | ||
15 | #include <lttng/lttng.h> | |
40ebe219 | 16 | #include <common/compiler.hpp> |
c9e313bc SM |
17 | #include <common/defaults.hpp> |
18 | #include <common/index/ctf-index.hpp> | |
19 | #include <common/macros.hpp> | |
20 | #include <common/uuid.hpp> | |
21 | #include <common/optional.hpp> | |
b8aa1682 | 22 | |
6947778e MD |
23 | #define RELAYD_VERSION_COMM_MAJOR VERSION_MAJOR |
24 | #define RELAYD_VERSION_COMM_MINOR VERSION_MINOR | |
0a6b5085 | 25 | |
1c17e424 JR |
26 | #define RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4 64 |
27 | #define RELAYD_COMM_LTTNG_NAME_MAX_2_4 255 | |
28 | #define RELAYD_COMM_LTTNG_PATH_MAX 4096 | |
29 | #define RELAYD_COMM_DEFAULT_STREAM_NAME_LEN 264 /* 256 + 8 */ | |
30 | ||
b8aa1682 JD |
31 | /* |
32 | * lttng-relayd communication header. | |
33 | */ | |
34 | struct lttcomm_relayd_hdr { | |
35 | /* Circuit ID not used for now so always ignored */ | |
36 | uint64_t circuit_id; | |
37 | uint64_t data_size; /* data size following this header */ | |
7c9534d6 | 38 | uint32_t cmd; /* enum lttcomm_relayd_command */ |
b8aa1682 | 39 | uint32_t cmd_version; /* command version */ |
a9e87764 | 40 | } LTTNG_PACKED; |
b8aa1682 JD |
41 | |
42 | /* | |
43 | * lttng-relayd data header. | |
44 | */ | |
45 | struct lttcomm_relayd_data_hdr { | |
46 | /* Circuit ID not used for now so always ignored */ | |
47 | uint64_t circuit_id; | |
48 | uint64_t stream_id; /* Stream ID known by the relayd */ | |
173af62f | 49 | uint64_t net_seq_num; /* Network sequence number, per stream. */ |
b8aa1682 | 50 | uint32_t data_size; /* data size following this header */ |
1d4dfdef | 51 | uint32_t padding_size; /* Size of 0 padding the data */ |
a9e87764 | 52 | } LTTNG_PACKED; |
b8aa1682 | 53 | |
c5b6f4f0 DG |
54 | /* |
55 | * Reply from a create session command. | |
56 | */ | |
57 | struct lttcomm_relayd_status_session { | |
58 | uint64_t session_id; | |
59 | uint32_t ret_code; | |
a9e87764 | 60 | } LTTNG_PACKED; |
c5b6f4f0 | 61 | |
b8aa1682 JD |
62 | /* |
63 | * Used to add a stream on the relay daemon. | |
64 | */ | |
65 | struct lttcomm_relayd_add_stream { | |
1c17e424 JR |
66 | char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN]; |
67 | char pathname[RELAYD_COMM_LTTNG_PATH_MAX]; | |
a9e87764 | 68 | } LTTNG_PACKED; |
b8aa1682 | 69 | |
0f907de1 JD |
70 | /* |
71 | * Used to add a stream on the relay daemon. | |
72 | * Protocol version 2.2 | |
73 | */ | |
74 | struct lttcomm_relayd_add_stream_2_2 { | |
1c17e424 JR |
75 | char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN]; |
76 | char pathname[RELAYD_COMM_LTTNG_PATH_MAX]; | |
0f907de1 JD |
77 | uint64_t tracefile_size; |
78 | uint64_t tracefile_count; | |
79 | } LTTNG_PACKED; | |
80 | ||
2f21a469 JR |
81 | struct lttcomm_relayd_add_stream_2_11 { |
82 | uint32_t channel_name_len; | |
83 | uint32_t pathname_len; | |
84 | uint64_t tracefile_size; | |
85 | uint64_t tracefile_count; | |
348a81dc | 86 | uint64_t trace_chunk_id; |
40ebe219 | 87 | char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
2f21a469 JR |
88 | } LTTNG_PACKED; |
89 | ||
b8aa1682 JD |
90 | /* |
91 | * Answer from an add stream command. | |
92 | */ | |
93 | struct lttcomm_relayd_status_stream { | |
94 | uint64_t handle; | |
95 | uint32_t ret_code; | |
a9e87764 | 96 | } LTTNG_PACKED; |
b8aa1682 JD |
97 | |
98 | /* | |
99 | * Used to return command code for command not needing special data. | |
100 | */ | |
101 | struct lttcomm_relayd_generic_reply { | |
102 | uint32_t ret_code; | |
a9e87764 | 103 | } LTTNG_PACKED; |
b8aa1682 | 104 | |
b8aa1682 JD |
105 | /* |
106 | * Version command. | |
107 | */ | |
108 | struct lttcomm_relayd_version { | |
109 | uint32_t major; | |
110 | uint32_t minor; | |
a9e87764 | 111 | } LTTNG_PACKED; |
b8aa1682 JD |
112 | |
113 | /* | |
114 | * Metadata payload used when metadata command is sent. | |
115 | */ | |
116 | struct lttcomm_relayd_metadata_payload { | |
117 | uint64_t stream_id; | |
1d4dfdef | 118 | uint32_t padding_size; |
b8aa1682 | 119 | char payload[]; |
a9e87764 | 120 | } LTTNG_PACKED; |
b8aa1682 | 121 | |
173af62f DG |
122 | /* |
123 | * Used to indicate that a specific stream id can now be closed. | |
124 | */ | |
125 | struct lttcomm_relayd_close_stream { | |
126 | uint64_t stream_id; | |
127 | uint64_t last_net_seq_num; /* sequence number of last packet */ | |
a9e87764 | 128 | } LTTNG_PACKED; |
173af62f | 129 | |
c8f59ee5 | 130 | /* |
6d805429 DG |
131 | * Used to test if for a given stream id the data is pending on the relayd side |
132 | * for reading. | |
c8f59ee5 | 133 | */ |
6d805429 | 134 | struct lttcomm_relayd_data_pending { |
c8f59ee5 DG |
135 | uint64_t stream_id; |
136 | uint64_t last_net_seq_num; /* Sequence number of the last packet */ | |
a9e87764 | 137 | } LTTNG_PACKED; |
c8f59ee5 | 138 | |
f7079f67 DG |
139 | struct lttcomm_relayd_begin_data_pending { |
140 | uint64_t session_id; | |
a9e87764 | 141 | } LTTNG_PACKED; |
f7079f67 DG |
142 | |
143 | struct lttcomm_relayd_end_data_pending { | |
144 | uint64_t session_id; | |
a9e87764 | 145 | } LTTNG_PACKED; |
f7079f67 | 146 | |
ad7051c0 DG |
147 | struct lttcomm_relayd_quiescent_control { |
148 | uint64_t stream_id; | |
149 | } LTTNG_PACKED; | |
150 | ||
1c20f0e2 JD |
151 | /* |
152 | * Index data. | |
153 | */ | |
154 | struct lttcomm_relayd_index { | |
155 | uint64_t relay_stream_id; | |
156 | uint64_t net_seq_num; | |
157 | uint64_t packet_size; | |
158 | uint64_t content_size; | |
159 | uint64_t timestamp_begin; | |
160 | uint64_t timestamp_end; | |
161 | uint64_t events_discarded; | |
162 | uint64_t stream_id; | |
f8f3885c | 163 | /* 2.8+ */ |
234cd636 JD |
164 | uint64_t stream_instance_id; |
165 | uint64_t packet_seq_num; | |
1c20f0e2 JD |
166 | } LTTNG_PACKED; |
167 | ||
f8f3885c MD |
168 | static inline size_t lttcomm_relayd_index_len(uint32_t major, uint32_t minor) |
169 | { | |
170 | if (major == 1) { | |
171 | switch (minor) { | |
172 | case 0: | |
173 | return offsetof(struct lttcomm_relayd_index, stream_id) | |
174 | + member_sizeof(struct lttcomm_relayd_index, | |
175 | stream_id); | |
176 | case 1: | |
177 | return offsetof(struct lttcomm_relayd_index, packet_seq_num) | |
178 | + member_sizeof(struct lttcomm_relayd_index, | |
179 | packet_seq_num); | |
180 | default: | |
181 | abort(); | |
182 | } | |
183 | } | |
184 | abort(); | |
185 | } | |
186 | ||
d3e2ba59 JD |
187 | /* |
188 | * Create session in 2.4 adds additionnal parameters for live reading. | |
189 | */ | |
190 | struct lttcomm_relayd_create_session_2_4 { | |
1c17e424 JR |
191 | char session_name[RELAYD_COMM_LTTNG_NAME_MAX_2_4]; |
192 | char hostname[RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4]; | |
d3e2ba59 | 193 | uint32_t live_timer; |
7d2f7452 | 194 | uint32_t snapshot; |
d3e2ba59 JD |
195 | } LTTNG_PACKED; |
196 | ||
f86f6389 JR |
197 | struct lttcomm_relayd_create_session_2_11 { |
198 | uint32_t session_name_len; | |
199 | uint32_t hostname_len; | |
6fa5fe7c MD |
200 | /* Optional, set to 0 to indicate it is not user-specified. */ |
201 | uint32_t base_path_len; | |
f86f6389 JR |
202 | uint32_t live_timer; |
203 | uint8_t snapshot; | |
46ef2188 | 204 | uint8_t session_name_contains_creation_time; |
658f12fa | 205 | /* Sessiond instance UUID */ |
328c2fe7 | 206 | uint8_t sessiond_uuid[LTTNG_UUID_LEN]; |
658f12fa | 207 | /* Sessiond session id */ |
d3219302 | 208 | uint64_t session_id; |
db1da059 JG |
209 | /* Session creation time, in seconds since UNIX Epoch. */ |
210 | uint64_t creation_time; | |
211 | LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id; | |
6fa5fe7c | 212 | /* Contains the session_name, hostname, base_path. */ |
40ebe219 | 213 | char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
f86f6389 JR |
214 | } LTTNG_PACKED; |
215 | ||
ecd1a12f MD |
216 | struct lttcomm_relayd_create_session_reply_2_11 { |
217 | struct lttcomm_relayd_status_session generic; | |
218 | /* Includes the '\0' terminator. */ | |
219 | uint32_t output_path_length; | |
40ebe219 | 220 | char output_path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
ecd1a12f MD |
221 | } LTTNG_PACKED; |
222 | ||
93ec662e JD |
223 | /* |
224 | * Used to ask the relay to reset the metadata trace file (regeneration). | |
225 | * Send the new version of the metadata (starts at 0). | |
226 | */ | |
227 | struct lttcomm_relayd_reset_metadata { | |
228 | uint64_t stream_id; | |
229 | uint64_t version; | |
230 | } LTTNG_PACKED; | |
231 | ||
c35f9726 | 232 | struct lttcomm_relayd_stream_rotation_position { |
d3ecc550 | 233 | uint64_t stream_id; |
c35f9726 JG |
234 | /* |
235 | * Sequence number of the first packet belonging to the new | |
236 | * "destination" trace chunk to which the stream is rotating. | |
237 | * | |
238 | * Ignored for metadata streams. | |
239 | */ | |
d3ecc550 | 240 | uint64_t rotate_at_seq_num; |
c35f9726 JG |
241 | } LTTNG_PACKED; |
242 | ||
ce9dbd47 JG |
243 | /* |
244 | * For certain releases, the LTTNG_PACKED annotation was missing on the | |
245 | * `new_chunk_id` field which causes padding to be added between the | |
246 | * "optional" structure's `is_set` and `value` fields. | |
247 | * | |
248 | * Three alignment cases are handled: | |
249 | * - `value` is aligned to the next byte boundary after `is_set` | |
250 | * no padding is produced, see | |
251 | * `struct lttcomm_relayd_rotate_streams_packed`, | |
252 | * - `value` is aligned to the next 4-byte boundary after `is_set` | |
253 | * (e.g. x86), 3 bytes of padding are produced, see | |
254 | * `struct lttcomm_relayd_rotate_streams_3_bytes_padding`, | |
255 | * - `value` is aligned to the next 8-byte boundary after `is_set` | |
256 | * (e.g. x86-64), 7 bytes of padding are produced, see | |
257 | * `struct lttcomm_relayd_rotate_streams_7_bytes_padding`. | |
258 | * | |
259 | * Note that since this structure's advertised size is used to determine | |
260 | * the size of the padding it includes, it can't be extended with new | |
261 | * optional fields. A new command would be needed. | |
262 | */ | |
c35f9726 JG |
263 | struct lttcomm_relayd_rotate_streams { |
264 | uint32_t stream_count; | |
265 | /* | |
266 | * Streams can be rotated outside of a chunk but not be parented to | |
267 | * a new chunk. | |
ce9dbd47 JG |
268 | * |
269 | * Improperly packed, but left as-is for backwards compatibility | |
270 | * with unpatched relay daemons. | |
c35f9726 JG |
271 | */ |
272 | LTTNG_OPTIONAL_COMM(uint64_t) new_chunk_id; | |
273 | /* `stream_count` positions follow. */ | |
274 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; | |
d3ecc550 JD |
275 | } LTTNG_PACKED; |
276 | ||
ce9dbd47 JG |
277 | struct lttcomm_relayd_rotate_streams_packed { |
278 | uint32_t stream_count; | |
279 | LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED new_chunk_id; | |
280 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; | |
281 | } LTTNG_PACKED; | |
282 | ||
283 | struct lttcomm_relayd_rotate_streams_3_bytes_padding { | |
284 | uint32_t stream_count; | |
285 | struct { | |
286 | union { | |
287 | uint8_t is_set; | |
288 | uint32_t padding; | |
289 | }; | |
290 | uint64_t value; | |
291 | } LTTNG_PACKED new_chunk_id; | |
292 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; | |
293 | } LTTNG_PACKED; | |
294 | ||
295 | struct lttcomm_relayd_rotate_streams_7_bytes_padding { | |
296 | uint32_t stream_count; | |
297 | struct { | |
298 | union { | |
299 | uint8_t is_set; | |
300 | uint64_t padding; | |
301 | }; | |
302 | uint64_t value; | |
303 | } LTTNG_PACKED new_chunk_id; | |
304 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; | |
305 | } LTTNG_PACKED; | |
306 | ||
e5add6d0 JG |
307 | struct lttcomm_relayd_create_trace_chunk { |
308 | uint64_t chunk_id; | |
309 | /* Seconds since EPOCH. */ | |
310 | uint64_t creation_timestamp; | |
311 | /* Includes trailing NULL. */ | |
312 | uint32_t override_name_length; | |
40ebe219 | 313 | char override_name[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
e5add6d0 JG |
314 | } LTTNG_PACKED; |
315 | ||
bbc4768c JG |
316 | struct lttcomm_relayd_close_trace_chunk { |
317 | uint64_t chunk_id; | |
318 | /* Seconds since EPOCH. */ | |
319 | uint64_t close_timestamp; | |
320 | /* enum lttng_trace_chunk_command_type */ | |
321 | LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command; | |
322 | } LTTNG_PACKED; | |
323 | ||
ecd1a12f MD |
324 | struct lttcomm_relayd_close_trace_chunk_reply { |
325 | struct lttcomm_relayd_generic_reply generic; | |
326 | /* Includes trailing NULL. */ | |
327 | uint32_t path_length; | |
40ebe219 | 328 | char path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
ecd1a12f MD |
329 | } LTTNG_PACKED; |
330 | ||
c35f9726 JG |
331 | struct lttcomm_relayd_trace_chunk_exists { |
332 | uint64_t chunk_id; | |
333 | } LTTNG_PACKED; | |
334 | ||
335 | struct lttcomm_relayd_trace_chunk_exists_reply { | |
336 | struct lttcomm_relayd_generic_reply generic; | |
337 | uint8_t trace_chunk_exists; | |
338 | } LTTNG_PACKED; | |
339 | ||
8614e600 MD |
340 | enum lttcomm_relayd_configuration_flag { |
341 | /* The relay daemon (2.12) is configured to allow clear operations. */ | |
342 | LTTCOMM_RELAYD_CONFIGURATION_FLAG_CLEAR_ALLOWED = (1 << 0), | |
343 | }; | |
344 | ||
345 | struct lttcomm_relayd_get_configuration { | |
346 | uint64_t query_flags; | |
347 | } LTTNG_PACKED; | |
348 | ||
349 | /* | |
350 | * Used to return a relay daemon's configuration in reply to the | |
351 | * RELAYD_GET_CONFIGURATION command. | |
352 | */ | |
353 | struct lttcomm_relayd_get_configuration_reply { | |
354 | struct lttcomm_relayd_generic_reply generic; | |
355 | /* Set of lttcomm_relayd_configuration_flag. */ | |
356 | uint64_t relayd_configuration_flags; | |
357 | /* Optional variable-length payload. */ | |
40ebe219 | 358 | char payload[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
8614e600 MD |
359 | } LTTNG_PACKED; |
360 | ||
b8aa1682 | 361 | #endif /* _RELAYD_COMM */ |