2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2012 Julien Desfossez <julien.desfossez@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
15 #include <lttng/lttng.h>
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>
22 #define RELAYD_VERSION_COMM_MAJOR VERSION_MAJOR
23 /* FIXME: remove, SPOOFING VERSION as 2.15 */
24 //#define RELAYD_VERSION_COMM_MINOR VERSION_MINOR
25 #define RELAYD_VERSION_COMM_MINOR 15
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 */
33 * lttng-relayd communication header.
35 struct lttcomm_relayd_hdr {
36 /* Circuit ID not used for now so always ignored */
38 uint64_t data_size; /* data size following this header */
39 uint32_t cmd; /* enum lttcomm_relayd_command */
40 uint32_t cmd_version; /* command version */
44 * lttng-relayd data header.
46 struct lttcomm_relayd_data_hdr {
47 /* Circuit ID not used for now so always ignored */
49 uint64_t stream_id; /* Stream ID known by the relayd */
50 uint64_t net_seq_num; /* Network sequence number, per stream. */
51 uint32_t data_size; /* data size following this header */
52 uint32_t padding_size; /* Size of 0 padding the data */
56 * Reply from a create session command.
58 struct lttcomm_relayd_status_session {
64 * Used to add a stream on the relay daemon.
66 struct lttcomm_relayd_add_stream {
67 char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN];
68 char pathname[RELAYD_COMM_LTTNG_PATH_MAX];
72 * Used to add a stream on the relay daemon.
73 * Protocol version 2.2
75 struct lttcomm_relayd_add_stream_2_2 {
76 char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN];
77 char pathname[RELAYD_COMM_LTTNG_PATH_MAX];
78 uint64_t tracefile_size;
79 uint64_t tracefile_count;
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;
87 uint64_t trace_chunk_id;
92 * Answer from an add stream command.
94 struct lttcomm_relayd_status_stream {
100 * Used to return command code for command not needing special data.
102 struct lttcomm_relayd_generic_reply {
109 struct lttcomm_relayd_version {
115 * Metadata payload used when metadata command is sent.
117 struct lttcomm_relayd_metadata_payload {
119 uint32_t padding_size;
124 * Used to indicate that a specific stream id can now be closed.
126 struct lttcomm_relayd_close_stream {
128 uint64_t last_net_seq_num; /* sequence number of last packet */
132 * Used to test if for a given stream id the data is pending on the relayd side
135 struct lttcomm_relayd_data_pending {
137 uint64_t last_net_seq_num; /* Sequence number of the last packet */
140 struct lttcomm_relayd_begin_data_pending {
144 struct lttcomm_relayd_end_data_pending {
148 struct lttcomm_relayd_quiescent_control {
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;
165 uint64_t stream_instance_id;
166 uint64_t packet_seq_num;
169 static inline size_t lttcomm_relayd_index_len(uint32_t major, uint32_t minor)
174 return offsetof(struct lttcomm_relayd_index, stream_id)
175 + member_sizeof(struct lttcomm_relayd_index,
178 return offsetof(struct lttcomm_relayd_index, packet_seq_num)
179 + member_sizeof(struct lttcomm_relayd_index,
189 * Create session in 2.4 adds additionnal parameters for live reading.
191 struct lttcomm_relayd_create_session_2_4 {
192 char session_name[RELAYD_COMM_LTTNG_NAME_MAX_2_4];
193 char hostname[RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4];
198 struct lttcomm_relayd_create_session_2_11 {
199 uint32_t session_name_len;
200 uint32_t hostname_len;
201 /* Optional, set to 0 to indicate it is not user-specified. */
202 uint32_t base_path_len;
205 uint8_t session_name_contains_creation_time;
206 /* Sessiond instance UUID */
207 uint8_t sessiond_uuid[LTTNG_UUID_LEN];
208 /* Sessiond session id */
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;
213 /* Contains the session_name, hostname, base_path. */
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;
225 * Used to ask the relay to reset the metadata trace file (regeneration).
226 * Send the new version of the metadata (starts at 0).
228 struct lttcomm_relayd_reset_metadata {
233 struct lttcomm_relayd_stream_rotation_position {
236 * Sequence number of the first packet belonging to the new
237 * "destination" trace chunk to which the stream is rotating.
239 * Ignored for metadata streams.
241 uint64_t rotate_at_seq_num;
245 * For certain releases, the LTTNG_PACKED annotation was missing on the
246 * `new_chunk_id` field which causes padding to be added between the
247 * "optional" structure's `is_set` and `value` fields.
249 * Three alignment cases are handled:
250 * - `value` is aligned to the next byte boundary after `is_set`
251 * no padding is produced, see
252 * `struct lttcomm_relayd_rotate_streams_packed`,
253 * - `value` is aligned to the next 4-byte boundary after `is_set`
254 * (e.g. x86), 3 bytes of padding are produced, see
255 * `struct lttcomm_relayd_rotate_streams_3_bytes_padding`,
256 * - `value` is aligned to the next 8-byte boundary after `is_set`
257 * (e.g. x86-64), 7 bytes of padding are produced, see
258 * `struct lttcomm_relayd_rotate_streams_7_bytes_padding`.
260 * Note that since this structure's advertised size is used to determine
261 * the size of the padding it includes, it can't be extended with new
262 * optional fields. A new command would be needed.
264 struct lttcomm_relayd_rotate_streams {
265 uint32_t stream_count;
267 * Streams can be rotated outside of a chunk but not be parented to
270 * Improperly packed, but left as-is for backwards compatibility
271 * with unpatched relay daemons.
273 LTTNG_OPTIONAL_COMM(uint64_t) new_chunk_id;
274 /* `stream_count` positions follow. */
275 struct lttcomm_relayd_stream_rotation_position rotation_positions[];
278 struct lttcomm_relayd_rotate_streams_packed {
279 uint32_t stream_count;
280 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED new_chunk_id;
281 struct lttcomm_relayd_stream_rotation_position rotation_positions[];
284 struct lttcomm_relayd_rotate_streams_3_bytes_padding {
285 uint32_t stream_count;
292 } LTTNG_PACKED new_chunk_id;
293 struct lttcomm_relayd_stream_rotation_position rotation_positions[];
296 struct lttcomm_relayd_rotate_streams_7_bytes_padding {
297 uint32_t stream_count;
304 } LTTNG_PACKED new_chunk_id;
305 struct lttcomm_relayd_stream_rotation_position rotation_positions[];
308 struct lttcomm_relayd_create_trace_chunk {
310 /* Seconds since EPOCH. */
311 uint64_t creation_timestamp;
312 /* Includes trailing NULL. */
313 uint32_t override_name_length;
314 char override_name[];
317 struct lttcomm_relayd_close_trace_chunk {
319 /* Seconds since EPOCH. */
320 uint64_t close_timestamp;
321 /* enum lttng_trace_chunk_command_type */
322 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
325 struct lttcomm_relayd_close_trace_chunk_reply {
326 struct lttcomm_relayd_generic_reply generic;
327 /* Includes trailing NULL. */
328 uint32_t path_length;
332 struct lttcomm_relayd_trace_chunk_exists {
336 struct lttcomm_relayd_trace_chunk_exists_reply {
337 struct lttcomm_relayd_generic_reply generic;
338 uint8_t trace_chunk_exists;
341 enum lttcomm_relayd_configuration_flag {
342 /* The relay daemon (2.12) is configured to allow clear operations. */
343 LTTCOMM_RELAYD_CONFIGURATION_FLAG_CLEAR_ALLOWED = (1 << 0),
346 enum lttcomm_relayd_configuration_query_flag {
347 LTTCOMM_RELAYD_CONFIGURATION_QUERY_FLAG_SUPPORTED_TRACE_FORMAT = (1 << 0),
348 LTTCOMM_RELAYD_CONFIGURATION_QUERY_FLAG_MASK = 0x01
351 enum lttcomm_relayd_configuration_trace_format_flag {
352 LTTCOMM_RELAYD_CONFIGURATION_TRACE_FORMAT_SUPPORTED_CTF1 = (1 << 0),
353 LTTCOMM_RELAYD_CONFIGURATION_TRACE_FORMAT_SUPPORTED_CTF2 = (1 << 1)
356 struct lttcomm_relayd_get_configuration {
357 uint64_t query_flags;
360 struct lttcomm_relayd_get_configuration_specialized_query_reply {
361 uint64_t query_flag; // Single flag, enum lttcomm_relayd_configuration_trace_format_flag
362 uint64_t payload_len;
364 * Payload dependant on type
365 * LTTCOMM_RELAYD_CONFIGURATION_QUERY_FLAG_SUPPORTED_TRACE_FORMAT:
366 * uint64_t, bitfield of lttcomm_relayd_configuration_trace_format_flag.
371 * Used to return a relay daemon's configuration in reply to the
372 * RELAYD_GET_CONFIGURATION command.
374 struct lttcomm_relayd_get_configuration_reply {
375 struct lttcomm_relayd_generic_reply generic;
376 /* Set of lttcomm_relayd_configuration_flag. */
377 uint64_t relayd_configuration_flags;
379 * Optional variable-length payload.
380 * When N query flags are used, it is expected that N dynamic sized
381 * lttcomm_relayd_get_configuration_specialized_query_reply be present.
386 #endif /* _RELAYD_COMM */