Build fix: POD static_assert check fails on lttng_event_exclusions
[lttng-tools.git] / src / common / sessiond-comm / relayd.hpp
1 /*
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2012 Julien Desfossez <julien.desfossez@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef _RELAYD_COMM
10 #define _RELAYD_COMM
11
12 #include <limits.h>
13 #include <stdint.h>
14
15 #include <lttng/lttng.h>
16 #include <common/compiler.hpp>
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>
22
23 #define RELAYD_VERSION_COMM_MAJOR VERSION_MAJOR
24 #define RELAYD_VERSION_COMM_MINOR VERSION_MINOR
25
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
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 */
38 uint32_t cmd; /* enum lttcomm_relayd_command */
39 uint32_t cmd_version; /* command version */
40 } LTTNG_PACKED;
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 */
49 uint64_t net_seq_num; /* Network sequence number, per stream. */
50 uint32_t data_size; /* data size following this header */
51 uint32_t padding_size; /* Size of 0 padding the data */
52 } LTTNG_PACKED;
53
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;
60 } LTTNG_PACKED;
61
62 /*
63 * Used to add a stream on the relay daemon.
64 */
65 struct lttcomm_relayd_add_stream {
66 char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN];
67 char pathname[RELAYD_COMM_LTTNG_PATH_MAX];
68 } LTTNG_PACKED;
69
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 {
75 char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN];
76 char pathname[RELAYD_COMM_LTTNG_PATH_MAX];
77 uint64_t tracefile_size;
78 uint64_t tracefile_count;
79 } LTTNG_PACKED;
80
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;
86 uint64_t trace_chunk_id;
87 char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
88 } LTTNG_PACKED;
89
90 /*
91 * Answer from an add stream command.
92 */
93 struct lttcomm_relayd_status_stream {
94 uint64_t handle;
95 uint32_t ret_code;
96 } LTTNG_PACKED;
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;
103 } LTTNG_PACKED;
104
105 /*
106 * Version command.
107 */
108 struct lttcomm_relayd_version {
109 uint32_t major;
110 uint32_t minor;
111 } LTTNG_PACKED;
112
113 /*
114 * Metadata payload used when metadata command is sent.
115 */
116 struct lttcomm_relayd_metadata_payload {
117 uint64_t stream_id;
118 uint32_t padding_size;
119 char payload[];
120 } LTTNG_PACKED;
121
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 */
128 } LTTNG_PACKED;
129
130 /*
131 * Used to test if for a given stream id the data is pending on the relayd side
132 * for reading.
133 */
134 struct lttcomm_relayd_data_pending {
135 uint64_t stream_id;
136 uint64_t last_net_seq_num; /* Sequence number of the last packet */
137 } LTTNG_PACKED;
138
139 struct lttcomm_relayd_begin_data_pending {
140 uint64_t session_id;
141 } LTTNG_PACKED;
142
143 struct lttcomm_relayd_end_data_pending {
144 uint64_t session_id;
145 } LTTNG_PACKED;
146
147 struct lttcomm_relayd_quiescent_control {
148 uint64_t stream_id;
149 } LTTNG_PACKED;
150
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;
163 /* 2.8+ */
164 uint64_t stream_instance_id;
165 uint64_t packet_seq_num;
166 } LTTNG_PACKED;
167
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
187 /*
188 * Create session in 2.4 adds additionnal parameters for live reading.
189 */
190 struct lttcomm_relayd_create_session_2_4 {
191 char session_name[RELAYD_COMM_LTTNG_NAME_MAX_2_4];
192 char hostname[RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4];
193 uint32_t live_timer;
194 uint32_t snapshot;
195 } LTTNG_PACKED;
196
197 struct lttcomm_relayd_create_session_2_11 {
198 uint32_t session_name_len;
199 uint32_t hostname_len;
200 /* Optional, set to 0 to indicate it is not user-specified. */
201 uint32_t base_path_len;
202 uint32_t live_timer;
203 uint8_t snapshot;
204 uint8_t session_name_contains_creation_time;
205 /* Sessiond instance UUID */
206 uint8_t sessiond_uuid[LTTNG_UUID_LEN];
207 /* Sessiond session id */
208 uint64_t session_id;
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;
212 /* Contains the session_name, hostname, base_path. */
213 char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
214 } LTTNG_PACKED;
215
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;
220 char output_path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
221 } LTTNG_PACKED;
222
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
232 struct lttcomm_relayd_stream_rotation_position {
233 uint64_t stream_id;
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 */
240 uint64_t rotate_at_seq_num;
241 } LTTNG_PACKED;
242
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 */
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.
268 *
269 * Improperly packed, but left as-is for backwards compatibility
270 * with unpatched relay daemons.
271 */
272 LTTNG_OPTIONAL_COMM(uint64_t) new_chunk_id;
273 /* `stream_count` positions follow. */
274 struct lttcomm_relayd_stream_rotation_position rotation_positions[];
275 } LTTNG_PACKED;
276
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
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;
313 char override_name[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
314 } LTTNG_PACKED;
315
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
324 struct lttcomm_relayd_close_trace_chunk_reply {
325 struct lttcomm_relayd_generic_reply generic;
326 /* Includes trailing NULL. */
327 uint32_t path_length;
328 char path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
329 } LTTNG_PACKED;
330
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
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. */
358 char payload[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH];
359 } LTTNG_PACKED;
360
361 #endif /* _RELAYD_COMM */
This page took 0.036376 seconds and 4 git commands to generate.