SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / src / common / sessiond-comm / sessiond-comm.h
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 */
9
10 /*
11 * This header is meant for liblttng and libust internal use ONLY. These
12 * declarations should NOT be considered stable API.
13 */
14
15 #ifndef _LTTNG_SESSIOND_COMM_H
16 #define _LTTNG_SESSIOND_COMM_H
17
18 #include <limits.h>
19 #include <lttng/lttng.h>
20 #include <lttng/snapshot-internal.h>
21 #include <lttng/save-internal.h>
22 #include <lttng/channel-internal.h>
23 #include <lttng/trigger/trigger-internal.h>
24 #include <lttng/rotate-internal.h>
25 #include <common/compat/socket.h>
26 #include <common/uri.h>
27 #include <common/defaults.h>
28 #include <common/uuid.h>
29 #include <common/macros.h>
30 #include <common/optional.h>
31
32 #include <arpa/inet.h>
33 #include <netinet/in.h>
34 #include <sys/un.h>
35
36 #include "inet.h"
37 #include "inet6.h"
38 #include <common/unix.h>
39
40 /* Queue size of listen(2) */
41 #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
42
43 /* Maximum number of FDs that can be sent over a Unix socket */
44 #define LTTCOMM_MAX_SEND_FDS 4
45
46 /*
47 * Get the error code index from 0 since LTTCOMM_OK start at 1000
48 */
49 #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_CONSUMERD_COMMAND_SOCK_READY)
50
51 enum lttcomm_sessiond_command {
52 /* Tracer command */
53 LTTNG_ADD_CONTEXT = 0,
54 /* LTTNG_CALIBRATE used to be here */
55 LTTNG_DISABLE_CHANNEL = 2,
56 LTTNG_DISABLE_EVENT = 3,
57 LTTNG_LIST_SYSCALLS = 4,
58 LTTNG_ENABLE_CHANNEL = 5,
59 LTTNG_ENABLE_EVENT = 6,
60 /* 7 */
61 /* Session daemon command */
62 /* 8 */
63 LTTNG_DESTROY_SESSION = 9,
64 LTTNG_LIST_CHANNELS = 10,
65 LTTNG_LIST_DOMAINS = 11,
66 LTTNG_LIST_EVENTS = 12,
67 LTTNG_LIST_SESSIONS = 13,
68 LTTNG_LIST_TRACEPOINTS = 14,
69 LTTNG_REGISTER_CONSUMER = 15,
70 LTTNG_START_TRACE = 16,
71 LTTNG_STOP_TRACE = 17,
72 LTTNG_LIST_TRACEPOINT_FIELDS = 18,
73
74 /* Consumer */
75 LTTNG_DISABLE_CONSUMER = 19,
76 LTTNG_ENABLE_CONSUMER = 20,
77 LTTNG_SET_CONSUMER_URI = 21,
78 /* 22 */
79 /* 23 */
80 LTTNG_DATA_PENDING = 24,
81 LTTNG_SNAPSHOT_ADD_OUTPUT = 25,
82 LTTNG_SNAPSHOT_DEL_OUTPUT = 26,
83 LTTNG_SNAPSHOT_LIST_OUTPUT = 27,
84 LTTNG_SNAPSHOT_RECORD = 28,
85 /* 29 */
86 /* 30 */
87 LTTNG_SAVE_SESSION = 31,
88 LTTNG_TRACK_ID = 32,
89 LTTNG_UNTRACK_ID = 33,
90 LTTNG_LIST_TRACKER_IDS = 34,
91 LTTNG_SET_SESSION_SHM_PATH = 40,
92 LTTNG_REGENERATE_METADATA = 41,
93 LTTNG_REGENERATE_STATEDUMP = 42,
94 LTTNG_REGISTER_TRIGGER = 43,
95 LTTNG_UNREGISTER_TRIGGER = 44,
96 LTTNG_ROTATE_SESSION = 45,
97 LTTNG_ROTATION_GET_INFO = 46,
98 LTTNG_ROTATION_SET_SCHEDULE = 47,
99 LTTNG_SESSION_LIST_ROTATION_SCHEDULES = 48,
100 LTTNG_CREATE_SESSION_EXT = 49,
101 LTTNG_CLEAR_SESSION = 50,
102 LTTNG_LIST_TRIGGERS = 51,
103 };
104
105 enum lttcomm_relayd_command {
106 RELAYD_ADD_STREAM = 1,
107 RELAYD_CREATE_SESSION = 2,
108 RELAYD_START_DATA = 3,
109 RELAYD_UPDATE_SYNC_INFO = 4,
110 RELAYD_VERSION = 5,
111 RELAYD_SEND_METADATA = 6,
112 RELAYD_CLOSE_STREAM = 7,
113 RELAYD_DATA_PENDING = 8,
114 RELAYD_QUIESCENT_CONTROL = 9,
115 RELAYD_BEGIN_DATA_PENDING = 10,
116 RELAYD_END_DATA_PENDING = 11,
117 RELAYD_ADD_INDEX = 12,
118 RELAYD_SEND_INDEX = 13,
119 RELAYD_CLOSE_INDEX = 14,
120 /* Live-reading commands (2.4+). */
121 RELAYD_LIST_SESSIONS = 15,
122 /* All streams of the channel have been sent to the relayd (2.4+). */
123 RELAYD_STREAMS_SENT = 16,
124 /* Ask the relay to reset the metadata trace file (2.8+) */
125 RELAYD_RESET_METADATA = 17,
126 /* Ask the relay to rotate a set of stream files (2.11+) */
127 RELAYD_ROTATE_STREAMS = 18,
128 /* Ask the relay to create a trace chunk (2.11+) */
129 RELAYD_CREATE_TRACE_CHUNK = 19,
130 /* Ask the relay to close a trace chunk (2.11+) */
131 RELAYD_CLOSE_TRACE_CHUNK = 20,
132 /* Ask the relay whether a trace chunk exists (2.11+) */
133 RELAYD_TRACE_CHUNK_EXISTS = 21,
134 /* Get the current configuration of a relayd peer (2.12+) */
135 RELAYD_GET_CONFIGURATION = 22,
136
137 /* Feature branch specific commands start at 10000. */
138 };
139
140 /*
141 * lttcomm error code.
142 */
143 enum lttcomm_return_code {
144 LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */
145 /*
146 * Some code paths use -1 to express an error, others
147 * negate this consumer return code. Starting codes at
148 * 100 ensures there is no mix-up between this error value
149 * and legitimate status codes.
150 */
151 LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 100, /* Command socket ready */
152 LTTCOMM_CONSUMERD_SUCCESS_RECV_FD, /* Success on receiving fds */
153 LTTCOMM_CONSUMERD_ERROR_RECV_FD, /* Error on receiving fds */
154 LTTCOMM_CONSUMERD_ERROR_RECV_CMD, /* Error on receiving command */
155 LTTCOMM_CONSUMERD_POLL_ERROR, /* Error in polling thread */
156 LTTCOMM_CONSUMERD_POLL_NVAL, /* Poll on closed fd */
157 LTTCOMM_CONSUMERD_POLL_HUP, /* All fds have hungup */
158 LTTCOMM_CONSUMERD_EXIT_SUCCESS, /* Consumerd exiting normally */
159 LTTCOMM_CONSUMERD_EXIT_FAILURE, /* Consumerd exiting on error */
160 LTTCOMM_CONSUMERD_OUTFD_ERROR, /* Error opening the tracefile */
161 LTTCOMM_CONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */
162 LTTCOMM_CONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */
163 LTTCOMM_CONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
164 LTTCOMM_CONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
165 LTTCOMM_CONSUMERD_ENOMEM, /* Consumer is out of memory */
166 LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */
167 LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */
168 LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */
169 LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
170 LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
171 LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
172 LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
173 LTTCOMM_CONSUMERD_SNAPSHOT_FAILED, /* snapshot has failed. */
174 LTTCOMM_CONSUMERD_CREATE_TRACE_CHUNK_FAILED,/* Trace chunk creation failed. */
175 LTTCOMM_CONSUMERD_CLOSE_TRACE_CHUNK_FAILED, /* Trace chunk creation failed. */
176 LTTCOMM_CONSUMERD_INVALID_PARAMETERS, /* Invalid parameters. */
177 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_LOCAL, /* Trace chunk exists on consumer daemon. */
178 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_REMOTE,/* Trace chunk exists on relay daemon. */
179 LTTCOMM_CONSUMERD_UNKNOWN_TRACE_CHUNK, /* Unknown trace chunk. */
180 LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED, /* Relayd does not accept clear command. */
181
182 /* MUST be last element */
183 LTTCOMM_NR, /* Last element */
184 };
185
186 /* lttng socket protocol. */
187 enum lttcomm_sock_proto {
188 LTTCOMM_SOCK_UDP,
189 LTTCOMM_SOCK_TCP,
190 };
191
192 /*
193 * Index in the net_families array below. Please keep in sync!
194 */
195 enum lttcomm_sock_domain {
196 LTTCOMM_INET = 0,
197 LTTCOMM_INET6 = 1,
198 };
199
200 enum lttcomm_metadata_command {
201 LTTCOMM_METADATA_REQUEST = 1,
202 };
203
204 /*
205 * Commands sent from the consumerd to the sessiond to request if new metadata
206 * is available. This message is used to find the per UID _or_ per PID registry
207 * for the channel key. For per UID lookup, the triplet
208 * bits_per_long/uid/session_id is used. On lookup failure, we search for the
209 * per PID registry indexed by session id ignoring the other values.
210 */
211 struct lttcomm_metadata_request_msg {
212 uint64_t session_id; /* Tracing session id */
213 uint64_t session_id_per_pid; /* Tracing session id for per-pid */
214 uint32_t bits_per_long; /* Consumer ABI */
215 uint32_t uid;
216 uint64_t key; /* Metadata channel key. */
217 } LTTNG_PACKED;
218
219 struct lttcomm_sockaddr {
220 enum lttcomm_sock_domain type;
221 union {
222 struct sockaddr_in sin;
223 struct sockaddr_in6 sin6;
224 } addr;
225 } LTTNG_PACKED;
226
227 struct lttcomm_sock {
228 int32_t fd;
229 enum lttcomm_sock_proto proto;
230 struct lttcomm_sockaddr sockaddr;
231 const struct lttcomm_proto_ops *ops;
232 } LTTNG_PACKED;
233
234 /*
235 * Relayd sock. Adds the protocol version to use for the communications with
236 * the relayd.
237 */
238 struct lttcomm_relayd_sock {
239 struct lttcomm_sock sock;
240 uint32_t major;
241 uint32_t minor;
242 } LTTNG_PACKED;
243
244 struct lttcomm_net_family {
245 int family;
246 int (*create) (struct lttcomm_sock *sock, int type, int proto);
247 };
248
249 struct lttcomm_proto_ops {
250 int (*bind) (struct lttcomm_sock *sock);
251 int (*close) (struct lttcomm_sock *sock);
252 int (*connect) (struct lttcomm_sock *sock);
253 struct lttcomm_sock *(*accept) (struct lttcomm_sock *sock);
254 int (*listen) (struct lttcomm_sock *sock, int backlog);
255 ssize_t (*recvmsg) (struct lttcomm_sock *sock, void *buf, size_t len,
256 int flags);
257 ssize_t (*sendmsg) (struct lttcomm_sock *sock, const void *buf,
258 size_t len, int flags);
259 };
260
261 /*
262 * Data structure received from lttng client to session daemon.
263 */
264 struct lttcomm_session_msg {
265 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
266 struct lttng_session session;
267 struct lttng_domain domain;
268 union {
269 /* Event data */
270 struct {
271 char channel_name[LTTNG_SYMBOL_NAME_LEN];
272 struct lttng_event event LTTNG_PACKED;
273 /* Length of following filter expression. */
274 uint32_t expression_len;
275 /* Length of following bytecode for filter. */
276 uint32_t bytecode_len;
277 /* Exclusion count (fixed-size strings). */
278 uint32_t exclusion_count;
279 /* Userspace probe location size. */
280 uint32_t userspace_probe_location_len;
281 /*
282 * After this structure, the following variable-length
283 * items are transmitted:
284 * - char exclusion_names[LTTNG_SYMBOL_NAME_LEN][exclusion_count]
285 * - char filter_expression[expression_len]
286 * - unsigned char filter_bytecode[bytecode_len]
287 */
288 } LTTNG_PACKED enable;
289 struct {
290 char channel_name[LTTNG_SYMBOL_NAME_LEN];
291 struct lttng_event event LTTNG_PACKED;
292 /* Length of following filter expression. */
293 uint32_t expression_len;
294 /* Length of following bytecode for filter. */
295 uint32_t bytecode_len;
296 /*
297 * After this structure, the following variable-length
298 * items are transmitted:
299 * - unsigned char filter_expression[expression_len]
300 * - unsigned char filter_bytecode[bytecode_len]
301 */
302 } LTTNG_PACKED disable;
303 /* Create channel */
304 struct {
305 struct lttng_channel chan LTTNG_PACKED;
306 /* struct lttng_channel_extended is already packed. */
307 struct lttng_channel_extended extended;
308 } LTTNG_PACKED channel;
309 /* Context */
310 struct {
311 char channel_name[LTTNG_SYMBOL_NAME_LEN];
312 struct lttng_event_context ctx LTTNG_PACKED;
313 uint32_t provider_name_len;
314 uint32_t context_name_len;
315 } LTTNG_PACKED context;
316 /* Use by register_consumer */
317 struct {
318 char path[PATH_MAX];
319 } LTTNG_PACKED reg;
320 /* List */
321 struct {
322 char channel_name[LTTNG_SYMBOL_NAME_LEN];
323 } LTTNG_PACKED list;
324 struct lttng_calibrate calibrate;
325 /* Used by the set_consumer_url and used by create_session also call */
326 struct {
327 /* Number of lttng_uri following */
328 uint32_t size;
329 } LTTNG_PACKED uri;
330 struct {
331 struct lttng_snapshot_output output LTTNG_PACKED;
332 } LTTNG_PACKED snapshot_output;
333 struct {
334 uint32_t wait;
335 struct lttng_snapshot_output output LTTNG_PACKED;
336 } LTTNG_PACKED snapshot_record;
337 struct {
338 uint32_t nb_uri;
339 unsigned int timer_interval; /* usec */
340 } LTTNG_PACKED session_live;
341 struct {
342 struct lttng_save_session_attr attr; /* struct already packed */
343 } LTTNG_PACKED save_session;
344 struct {
345 char shm_path[PATH_MAX];
346 } LTTNG_PACKED set_shm_path;
347 struct {
348 uint32_t tracker_type; /* enum lttng_tracker_type */
349 uint32_t id_type; /* enum lttng_tracker_id_type */
350 union {
351 int32_t value;
352 uint32_t var_len;
353 } u;
354 /*
355 * for LTTNG_ID_STRING, followed by a variable length
356 * zero-terminated string of length "var_len", which
357 * includes the final \0.
358 */
359 } LTTNG_PACKED id_tracker;
360 struct {
361 uint32_t tracker_type; /* enum lttng_tracker_type */
362 } LTTNG_PACKED id_tracker_list;
363 struct {
364 uint32_t length;
365 } LTTNG_PACKED trigger;
366 struct {
367 uint64_t rotation_id;
368 } LTTNG_PACKED get_rotation_info;
369 struct {
370 /* enum lttng_rotation_schedule_type */
371 uint8_t type;
372 /*
373 * If set == 1, set schedule to value, if set == 0,
374 * clear this schedule type.
375 */
376 uint8_t set;
377 uint64_t value;
378 } LTTNG_PACKED rotation_set_schedule;
379 struct {
380 /*
381 * Includes the null-terminator.
382 * Must be an absolute path.
383 *
384 * Size bounded by LTTNG_PATH_MAX.
385 */
386 uint16_t home_dir_size;
387 uint64_t session_descriptor_size;
388 /* An lttng_session_descriptor follows. */
389 } LTTNG_PACKED create_session;
390 } u;
391 } LTTNG_PACKED;
392
393 #define LTTNG_FILTER_MAX_LEN 65536
394 #define LTTNG_SESSION_DESCRIPTOR_MAX_LEN 65536
395
396 /*
397 * Filter bytecode data. The reloc table is located at the end of the
398 * bytecode. It is made of tuples: (uint16_t, var. len. string). It
399 * starts at reloc_table_offset.
400 */
401 #define LTTNG_FILTER_PADDING 32
402 struct lttng_filter_bytecode {
403 uint32_t len; /* len of data */
404 uint32_t reloc_table_offset;
405 uint64_t seqnum;
406 char padding[LTTNG_FILTER_PADDING];
407 char data[0];
408 } LTTNG_PACKED;
409
410 /*
411 * Event exclusion data. At the end of the structure, there will actually
412 * by zero or more names, where the actual number of names is given by
413 * the 'count' item of the structure.
414 */
415 #define LTTNG_EVENT_EXCLUSION_PADDING 32
416 struct lttng_event_exclusion {
417 uint32_t count;
418 char padding[LTTNG_EVENT_EXCLUSION_PADDING];
419 char names[0][LTTNG_SYMBOL_NAME_LEN];
420 } LTTNG_PACKED;
421
422 #define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) \
423 (&(_exclusion)->names[_i][0])
424
425 /*
426 * Event command header.
427 */
428 struct lttcomm_event_command_header {
429 /* Number of events */
430 uint32_t nb_events;
431 } LTTNG_PACKED;
432
433 /*
434 * Event extended info header. This is the structure preceding each
435 * extended info data.
436 */
437 struct lttcomm_event_extended_header {
438 /*
439 * Size of filter string immediately following this header.
440 * This size includes the terminal null character.
441 */
442 uint32_t filter_len;
443
444 /*
445 * Number of exclusion names, immediately following the filter
446 * string. Each exclusion name has a fixed length of
447 * LTTNG_SYMBOL_NAME_LEN bytes, including the terminal null
448 * character.
449 */
450 uint32_t nb_exclusions;
451
452 /*
453 * Size of the event's userspace probe location (if applicable).
454 */
455 uint32_t userspace_probe_location_len;
456 } LTTNG_PACKED;
457
458 /*
459 * Command header of the reply to an LTTNG_DESTROY_SESSION command.
460 */
461 struct lttcomm_session_destroy_command_header {
462 /* enum lttng_session */
463 int32_t rotation_state;
464 };
465
466 /*
467 * tracker command header.
468 */
469 struct lttcomm_tracker_command_header {
470 uint32_t nb_tracker_id;
471 } LTTNG_PACKED;
472
473 struct lttcomm_tracker_id_header {
474 uint32_t type; /* enum lttng_tracker_id_type */
475 union {
476 int32_t value;
477 uint32_t var_data_len;
478 } u;
479 } LTTNG_PACKED;
480
481 /*
482 * Data structure for the response from sessiond to the lttng client.
483 */
484 struct lttcomm_lttng_msg {
485 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
486 uint32_t ret_code; /* enum lttcomm_return_code */
487 uint32_t pid; /* pid_t */
488 uint32_t cmd_header_size;
489 uint32_t data_size;
490 } LTTNG_PACKED;
491
492 struct lttcomm_lttng_output_id {
493 uint32_t id;
494 } LTTNG_PACKED;
495
496 /*
497 * lttcomm_consumer_msg is the message sent from sessiond to consumerd
498 * to either add a channel, add a stream, update a stream, or stop
499 * operation.
500 */
501 struct lttcomm_consumer_msg {
502 uint32_t cmd_type; /* enum lttng_consumer_command */
503 union {
504 struct {
505 uint64_t channel_key;
506 uint64_t session_id;
507 /* ID of the session's current trace chunk. */
508 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
509 char pathname[PATH_MAX];
510 uint64_t relayd_id;
511 /* nb_init_streams is the number of streams open initially. */
512 uint32_t nb_init_streams;
513 char name[LTTNG_SYMBOL_NAME_LEN];
514 /* Use splice or mmap to consume this fd */
515 enum lttng_event_output output;
516 int type; /* Per cpu or metadata. */
517 uint64_t tracefile_size; /* bytes */
518 uint32_t tracefile_count; /* number of tracefiles */
519 /* If the channel's streams have to be monitored or not. */
520 uint32_t monitor;
521 /* timer to check the streams usage in live mode (usec). */
522 unsigned int live_timer_interval;
523 /* timer to sample a channel's positions (usec). */
524 unsigned int monitor_timer_interval;
525 } LTTNG_PACKED channel; /* Only used by Kernel. */
526 struct {
527 uint64_t stream_key;
528 uint64_t channel_key;
529 int32_t cpu; /* On which CPU this stream is assigned. */
530 /* Tells the consumer if the stream should be or not monitored. */
531 uint32_t no_monitor;
532 } LTTNG_PACKED stream; /* Only used by Kernel. */
533 struct {
534 uint64_t net_index;
535 enum lttng_stream_type type;
536 /* Open socket to the relayd */
537 struct lttcomm_relayd_sock sock;
538 /* Tracing session id associated to the relayd. */
539 uint64_t session_id;
540 /* Relayd session id, only used with control socket. */
541 uint64_t relayd_session_id;
542 } LTTNG_PACKED relayd_sock;
543 struct {
544 uint64_t net_seq_idx;
545 } LTTNG_PACKED destroy_relayd;
546 struct {
547 uint64_t session_id;
548 } LTTNG_PACKED data_pending;
549 struct {
550 uint64_t subbuf_size; /* bytes */
551 uint64_t num_subbuf; /* power of 2 */
552 int32_t overwrite; /* 1: overwrite, 0: discard */
553 uint32_t switch_timer_interval; /* usec */
554 uint32_t read_timer_interval; /* usec */
555 unsigned int live_timer_interval; /* usec */
556 uint32_t monitor_timer_interval; /* usec */
557 int32_t output; /* splice, mmap */
558 int32_t type; /* metadata or per_cpu */
559 uint64_t session_id; /* Tracing session id */
560 char pathname[PATH_MAX]; /* Channel file path. */
561 char name[LTTNG_SYMBOL_NAME_LEN]; /* Channel name. */
562 /* Credentials used to open the UST buffer shared mappings. */
563 struct {
564 uint32_t uid;
565 uint32_t gid;
566 } LTTNG_PACKED buffer_credentials;
567 uint64_t relayd_id; /* Relayd id if apply. */
568 uint64_t key; /* Unique channel key. */
569 /* ID of the session's current trace chunk. */
570 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
571 unsigned char uuid[LTTNG_UUID_LEN]; /* uuid for ust tracer. */
572 uint32_t chan_id; /* Channel ID on the tracer side. */
573 uint64_t tracefile_size; /* bytes */
574 uint32_t tracefile_count; /* number of tracefiles */
575 uint64_t session_id_per_pid; /* Per-pid session ID. */
576 /* Tells the consumer if the stream should be or not monitored. */
577 uint32_t monitor;
578 /*
579 * For UST per UID buffers, this is the application UID of the
580 * channel. This can be different from the user UID requesting the
581 * channel creation and used for the rights on the stream file
582 * because the application can be in the tracing for instance.
583 */
584 uint32_t ust_app_uid;
585 int64_t blocking_timeout;
586 char root_shm_path[PATH_MAX];
587 char shm_path[PATH_MAX];
588 } LTTNG_PACKED ask_channel;
589 struct {
590 uint64_t key;
591 } LTTNG_PACKED get_channel;
592 struct {
593 uint64_t key;
594 } LTTNG_PACKED destroy_channel;
595 struct {
596 uint64_t key; /* Metadata channel key. */
597 uint64_t target_offset; /* Offset in the consumer */
598 uint64_t len; /* Length of metadata to be received. */
599 uint64_t version; /* Version of the metadata. */
600 } LTTNG_PACKED push_metadata;
601 struct {
602 uint64_t key; /* Metadata channel key. */
603 } LTTNG_PACKED close_metadata;
604 struct {
605 uint64_t key; /* Metadata channel key. */
606 } LTTNG_PACKED setup_metadata;
607 struct {
608 uint64_t key; /* Channel key. */
609 } LTTNG_PACKED flush_channel;
610 struct {
611 uint64_t key; /* Channel key. */
612 } LTTNG_PACKED clear_quiescent_channel;
613 struct {
614 char pathname[PATH_MAX];
615 /* Indicate if the snapshot goes on the relayd or locally. */
616 uint32_t use_relayd;
617 uint32_t metadata; /* This a metadata snapshot. */
618 uint64_t relayd_id; /* Relayd id if apply. */
619 uint64_t key;
620 uint64_t nb_packets_per_stream;
621 } LTTNG_PACKED snapshot_channel;
622 struct {
623 uint64_t channel_key;
624 uint64_t net_seq_idx;
625 } LTTNG_PACKED sent_streams;
626 struct {
627 uint64_t session_id;
628 uint64_t channel_key;
629 } LTTNG_PACKED discarded_events;
630 struct {
631 uint64_t session_id;
632 uint64_t channel_key;
633 } LTTNG_PACKED lost_packets;
634 struct {
635 uint64_t session_id;
636 } LTTNG_PACKED regenerate_metadata;
637 struct {
638 uint32_t metadata; /* This is a metadata channel. */
639 uint64_t relayd_id; /* Relayd id if apply. */
640 uint64_t key;
641 } LTTNG_PACKED rotate_channel;
642 struct {
643 uint64_t session_id;
644 uint64_t chunk_id;
645 } LTTNG_PACKED check_rotation_pending_local;
646 struct {
647 uint64_t relayd_id;
648 uint64_t session_id;
649 uint64_t chunk_id;
650 } LTTNG_PACKED check_rotation_pending_relay;
651 struct {
652 /*
653 * Relayd id, if applicable (remote).
654 *
655 * A directory file descriptor referring to the chunk's
656 * output folder is transmitted if the chunk is local
657 * (relayd_id unset).
658 *
659 * `override_name` is left NULL (all-zeroes) if the
660 * chunk's name is not overridden.
661 */
662 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
663 char override_name[LTTNG_NAME_MAX];
664 uint64_t session_id;
665 uint64_t chunk_id;
666 uint64_t creation_timestamp;
667 LTTNG_OPTIONAL_COMM(struct {
668 uint32_t uid;
669 uint32_t gid;
670 } LTTNG_PACKED ) LTTNG_PACKED credentials;
671 } LTTNG_PACKED create_trace_chunk;
672 struct {
673 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
674 uint64_t session_id;
675 uint64_t chunk_id;
676 uint64_t close_timestamp;
677 /* enum lttng_trace_chunk_command_type */
678 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
679 } LTTNG_PACKED close_trace_chunk;
680 struct {
681 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
682 uint64_t session_id;
683 uint64_t chunk_id;
684 } LTTNG_PACKED trace_chunk_exists;
685 struct {
686 lttng_uuid sessiond_uuid;
687 } LTTNG_PACKED init;
688 struct {
689 uint64_t key;
690 } LTTNG_PACKED clear_channel;
691 } u;
692 } LTTNG_PACKED;
693
694 /*
695 * Channel monitoring message returned to the session daemon on every
696 * monitor timer expiration.
697 */
698 struct lttcomm_consumer_channel_monitor_msg {
699 /* Key of the sampled channel. */
700 uint64_t key;
701 /*
702 * Lowest and highest usage (bytes) at the moment the sample was taken.
703 */
704 uint64_t lowest, highest;
705 /*
706 * Sum of all the consumed positions for a channel.
707 */
708 uint64_t total_consumed;
709 } LTTNG_PACKED;
710
711 /*
712 * Status message returned to the sessiond after a received command.
713 */
714 struct lttcomm_consumer_status_msg {
715 enum lttcomm_return_code ret_code;
716 } LTTNG_PACKED;
717
718 struct lttcomm_consumer_status_channel {
719 enum lttcomm_return_code ret_code;
720 uint64_t key;
721 unsigned int stream_count;
722 } LTTNG_PACKED;
723
724 struct lttcomm_consumer_close_trace_chunk_reply {
725 enum lttcomm_return_code ret_code;
726 uint32_t path_length;
727 char path[];
728 };
729
730 #ifdef HAVE_LIBLTTNG_UST_CTL
731
732 #include <lttng/ust-abi.h>
733
734 /*
735 * Data structure for the commands sent from sessiond to UST.
736 */
737 struct lttcomm_ust_msg {
738 uint32_t handle;
739 uint32_t cmd;
740 union {
741 struct lttng_ust_channel channel;
742 struct lttng_ust_stream stream;
743 struct lttng_ust_event event;
744 struct lttng_ust_context context;
745 struct lttng_ust_tracer_version version;
746 } u;
747 } LTTNG_PACKED;
748
749 /*
750 * Data structure for the response from UST to the session daemon.
751 * cmd_type is sent back in the reply for validation.
752 */
753 struct lttcomm_ust_reply {
754 uint32_t handle;
755 uint32_t cmd;
756 uint32_t ret_code; /* enum lttcomm_return_code */
757 uint32_t ret_val; /* return value */
758 union {
759 struct {
760 uint64_t memory_map_size;
761 } LTTNG_PACKED channel;
762 struct {
763 uint64_t memory_map_size;
764 } LTTNG_PACKED stream;
765 struct lttng_ust_tracer_version version;
766 } u;
767 } LTTNG_PACKED;
768
769 #endif /* HAVE_LIBLTTNG_UST_CTL */
770
771 LTTNG_HIDDEN const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
772
773 LTTNG_HIDDEN int lttcomm_init_inet_sockaddr(struct lttcomm_sockaddr *sockaddr,
774 const char *ip, unsigned int port);
775 LTTNG_HIDDEN int lttcomm_init_inet6_sockaddr(struct lttcomm_sockaddr *sockaddr,
776 const char *ip, unsigned int port);
777
778 LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto);
779 LTTNG_HIDDEN int lttcomm_create_sock(struct lttcomm_sock *sock);
780 LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_sock_from_uri(struct lttng_uri *uri);
781 LTTNG_HIDDEN void lttcomm_destroy_sock(struct lttcomm_sock *sock);
782 LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_copy_sock(struct lttcomm_sock *src);
783 LTTNG_HIDDEN void lttcomm_copy_sock(struct lttcomm_sock *dst,
784 struct lttcomm_sock *src);
785
786 /* Relayd socket object. */
787 LTTNG_HIDDEN struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock(
788 struct lttng_uri *uri, uint32_t major, uint32_t minor);
789
790 LTTNG_HIDDEN int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
791 LTTNG_HIDDEN int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
792
793 LTTNG_HIDDEN int lttcomm_sock_get_port(const struct lttcomm_sock *sock,
794 uint16_t *port);
795 /*
796 * Set a port to an lttcomm_sock. This will have no effect is the socket is
797 * already bound.
798 */
799 LTTNG_HIDDEN int lttcomm_sock_set_port(struct lttcomm_sock *sock, uint16_t port);
800
801 LTTNG_HIDDEN void lttcomm_init(void);
802 /* Get network timeout, in milliseconds */
803 LTTNG_HIDDEN unsigned long lttcomm_get_network_timeout(void);
804
805 #endif /* _LTTNG_SESSIOND_COMM_H */
This page took 0.046336 seconds and 5 git commands to generate.