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