Tests: Fix: Use '.logfile' instead of '.log' for test app output
[lttng-tools.git] / src / common / sessiond-comm / sessiond-comm.hpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 /*
10 * This header is meant for liblttng and libust internal use ONLY. These
11 * declarations should NOT be considered stable API.
12 */
13
14 #ifndef _LTTNG_SESSIOND_COMM_H
15 #define _LTTNG_SESSIOND_COMM_H
16
17 #include "inet.hpp"
18 #include "inet6.hpp"
19
20 #include <common/compat/socket.hpp>
21 #include <common/compiler.hpp>
22 #include <common/defaults.hpp>
23 #include <common/macros.hpp>
24 #include <common/optional.hpp>
25 #include <common/unix.hpp>
26 #include <common/uri.hpp>
27 #include <common/uuid.hpp>
28
29 #include <lttng/channel-internal.hpp>
30 #include <lttng/lttng.h>
31 #include <lttng/rotate-internal.hpp>
32 #include <lttng/save-internal.hpp>
33 #include <lttng/snapshot-internal.hpp>
34 #include <lttng/trigger/trigger-internal.hpp>
35
36 #include <arpa/inet.h>
37 #include <limits.h>
38 #include <netinet/in.h>
39 #include <stdint.h>
40 #include <sys/un.h>
41
42 /* Queue size of listen(2) */
43 #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
44
45 /* Maximum number of FDs that can be sent over a Unix socket */
46 #if defined(__linux__)
47 /* Based on the kernel's SCM_MAX_FD which is 253 since 2.6.38 (255 before) */
48 #define LTTCOMM_MAX_SEND_FDS 253
49 #else
50 #define LTTCOMM_MAX_SEND_FDS 16
51 #endif
52
53 enum lttcomm_sessiond_command {
54 LTTCOMM_SESSIOND_COMMAND_MIN,
55 LTTCOMM_SESSIOND_COMMAND_ADD_CONTEXT,
56 LTTCOMM_SESSIOND_COMMAND_DISABLE_CHANNEL,
57 LTTCOMM_SESSIOND_COMMAND_DISABLE_EVENT,
58 LTTCOMM_SESSIOND_COMMAND_LIST_SYSCALLS,
59 LTTCOMM_SESSIOND_COMMAND_ENABLE_CHANNEL,
60 LTTCOMM_SESSIOND_COMMAND_ENABLE_EVENT,
61 LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION,
62 LTTCOMM_SESSIOND_COMMAND_LIST_CHANNELS,
63 LTTCOMM_SESSIOND_COMMAND_LIST_DOMAINS,
64 LTTCOMM_SESSIOND_COMMAND_LIST_EVENTS,
65 LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS,
66 LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS,
67 LTTCOMM_SESSIOND_COMMAND_REGISTER_CONSUMER,
68 LTTCOMM_SESSIOND_COMMAND_START_TRACE,
69 LTTCOMM_SESSIOND_COMMAND_STOP_TRACE,
70 LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINT_FIELDS,
71 LTTCOMM_SESSIOND_COMMAND_DISABLE_CONSUMER,
72 LTTCOMM_SESSIOND_COMMAND_ENABLE_CONSUMER,
73 LTTCOMM_SESSIOND_COMMAND_SET_CONSUMER_URI,
74 LTTCOMM_SESSIOND_COMMAND_DATA_PENDING,
75 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_ADD_OUTPUT,
76 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_DEL_OUTPUT,
77 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_LIST_OUTPUT,
78 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_RECORD,
79 LTTCOMM_SESSIOND_COMMAND_SAVE_SESSION,
80 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE,
81 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE,
82 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_POLICY,
83 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_SET_POLICY,
84 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET,
85 LTTCOMM_SESSIOND_COMMAND_SET_SESSION_SHM_PATH,
86 LTTCOMM_SESSIOND_COMMAND_REGENERATE_METADATA,
87 LTTCOMM_SESSIOND_COMMAND_REGENERATE_STATEDUMP,
88 LTTCOMM_SESSIOND_COMMAND_REGISTER_TRIGGER,
89 LTTCOMM_SESSIOND_COMMAND_UNREGISTER_TRIGGER,
90 LTTCOMM_SESSIOND_COMMAND_ROTATE_SESSION,
91 LTTCOMM_SESSIOND_COMMAND_ROTATION_GET_INFO,
92 LTTCOMM_SESSIOND_COMMAND_ROTATION_SET_SCHEDULE,
93 LTTCOMM_SESSIOND_COMMAND_SESSION_LIST_ROTATION_SCHEDULES,
94 LTTCOMM_SESSIOND_COMMAND_CREATE_SESSION_EXT,
95 LTTCOMM_SESSIOND_COMMAND_CLEAR_SESSION,
96 LTTCOMM_SESSIOND_COMMAND_LIST_TRIGGERS,
97 LTTCOMM_SESSIOND_COMMAND_EXECUTE_ERROR_QUERY,
98 LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS,
99 LTTCOMM_SESSIOND_COMMAND_MAX,
100 };
101
102 static inline bool lttcomm_sessiond_command_is_valid(enum lttcomm_sessiond_command cmd)
103 {
104 return cmd > LTTCOMM_SESSIOND_COMMAND_MIN && cmd < LTTCOMM_SESSIOND_COMMAND_MAX;
105 }
106
107 static inline const char *lttcomm_sessiond_command_str(enum lttcomm_sessiond_command cmd)
108 {
109 switch (cmd) {
110 case LTTCOMM_SESSIOND_COMMAND_ADD_CONTEXT:
111 return "ADD_CONTEXT";
112 case LTTCOMM_SESSIOND_COMMAND_DISABLE_CHANNEL:
113 return "DISABLE_CHANNEL";
114 case LTTCOMM_SESSIOND_COMMAND_DISABLE_EVENT:
115 return "DISABLE_EVENT";
116 case LTTCOMM_SESSIOND_COMMAND_LIST_SYSCALLS:
117 return "LIST_SYSCALLS";
118 case LTTCOMM_SESSIOND_COMMAND_ENABLE_CHANNEL:
119 return "ENABLE_CHANNEL";
120 case LTTCOMM_SESSIOND_COMMAND_ENABLE_EVENT:
121 return "ENABLE_EVENT";
122 case LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION:
123 return "DESTROY_SESSION";
124 case LTTCOMM_SESSIOND_COMMAND_LIST_CHANNELS:
125 return "LIST_CHANNELS";
126 case LTTCOMM_SESSIOND_COMMAND_LIST_DOMAINS:
127 return "LIST_DOMAINS";
128 case LTTCOMM_SESSIOND_COMMAND_LIST_EVENTS:
129 return "LIST_EVENTS";
130 case LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS:
131 return "LIST_SESSIONS";
132 case LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS:
133 return "LIST_TRACEPOINTS";
134 case LTTCOMM_SESSIOND_COMMAND_REGISTER_CONSUMER:
135 return "REGISTER_CONSUMER";
136 case LTTCOMM_SESSIOND_COMMAND_START_TRACE:
137 return "START_TRACE";
138 case LTTCOMM_SESSIOND_COMMAND_STOP_TRACE:
139 return "STOP_TRACE";
140 case LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINT_FIELDS:
141 return "LIST_TRACEPOINT_FIELDS";
142 case LTTCOMM_SESSIOND_COMMAND_DISABLE_CONSUMER:
143 return "DISABLE_CONSUMER";
144 case LTTCOMM_SESSIOND_COMMAND_ENABLE_CONSUMER:
145 return "ENABLE_CONSUMER";
146 case LTTCOMM_SESSIOND_COMMAND_SET_CONSUMER_URI:
147 return "SET_CONSUMER_URI";
148 case LTTCOMM_SESSIOND_COMMAND_DATA_PENDING:
149 return "DATA_PENDING";
150 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_ADD_OUTPUT:
151 return "SNAPSHOT_ADD_OUTPUT";
152 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_DEL_OUTPUT:
153 return "SNAPSHOT_DEL_OUTPUT";
154 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_LIST_OUTPUT:
155 return "SNAPSHOT_LIST_OUTPUT";
156 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_RECORD:
157 return "SNAPSHOT_RECORD";
158 case LTTCOMM_SESSIOND_COMMAND_SAVE_SESSION:
159 return "SAVE_SESSION";
160 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE:
161 return "PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE";
162 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE:
163 return "PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE";
164 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_POLICY:
165 return "PROCESS_ATTR_TRACKER_GET_POLICY";
166 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_SET_POLICY:
167 return "PROCESS_ATTR_TRACKER_SET_POLICY";
168 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET:
169 return "PROCESS_ATTR_TRACKER_GET_INCLUSION_SET";
170 case LTTCOMM_SESSIOND_COMMAND_SET_SESSION_SHM_PATH:
171 return "SET_SESSION_SHM_PATH";
172 case LTTCOMM_SESSIOND_COMMAND_REGENERATE_METADATA:
173 return "REGENERATE_METADATA";
174 case LTTCOMM_SESSIOND_COMMAND_REGENERATE_STATEDUMP:
175 return "REGENERATE_STATEDUMP";
176 case LTTCOMM_SESSIOND_COMMAND_REGISTER_TRIGGER:
177 return "REGISTER_TRIGGER";
178 case LTTCOMM_SESSIOND_COMMAND_UNREGISTER_TRIGGER:
179 return "UNREGISTER_TRIGGER";
180 case LTTCOMM_SESSIOND_COMMAND_ROTATE_SESSION:
181 return "ROTATE_SESSION";
182 case LTTCOMM_SESSIOND_COMMAND_ROTATION_GET_INFO:
183 return "ROTATION_GET_INFO";
184 case LTTCOMM_SESSIOND_COMMAND_ROTATION_SET_SCHEDULE:
185 return "ROTATION_SET_SCHEDULE";
186 case LTTCOMM_SESSIOND_COMMAND_SESSION_LIST_ROTATION_SCHEDULES:
187 return "SESSION_LIST_ROTATION_SCHEDULES";
188 case LTTCOMM_SESSIOND_COMMAND_CREATE_SESSION_EXT:
189 return "CREATE_SESSION_EXT";
190 case LTTCOMM_SESSIOND_COMMAND_CLEAR_SESSION:
191 return "CLEAR_SESSION";
192 case LTTCOMM_SESSIOND_COMMAND_LIST_TRIGGERS:
193 return "LIST_TRIGGERS";
194 case LTTCOMM_SESSIOND_COMMAND_EXECUTE_ERROR_QUERY:
195 return "EXECUTE_ERROR_QUERY";
196 case LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS:
197 return "KERNEL_TRACER_STATUS";
198 default:
199 abort();
200 }
201 }
202
203 enum lttcomm_relayd_command {
204 RELAYD_ADD_STREAM = 1,
205 RELAYD_CREATE_SESSION = 2,
206 RELAYD_START_DATA = 3,
207 RELAYD_UPDATE_SYNC_INFO = 4,
208 RELAYD_VERSION = 5,
209 RELAYD_SEND_METADATA = 6,
210 RELAYD_CLOSE_STREAM = 7,
211 RELAYD_DATA_PENDING = 8,
212 RELAYD_QUIESCENT_CONTROL = 9,
213 RELAYD_BEGIN_DATA_PENDING = 10,
214 RELAYD_END_DATA_PENDING = 11,
215 RELAYD_ADD_INDEX = 12,
216 RELAYD_SEND_INDEX = 13,
217 RELAYD_CLOSE_INDEX = 14,
218 /* Live-reading commands (2.4+). */
219 RELAYD_LIST_SESSIONS = 15,
220 /* All streams of the channel have been sent to the relayd (2.4+). */
221 RELAYD_STREAMS_SENT = 16,
222 /* Ask the relay to reset the metadata trace file (2.8+) */
223 RELAYD_RESET_METADATA = 17,
224 /* Ask the relay to rotate a set of stream files (2.11+) */
225 RELAYD_ROTATE_STREAMS = 18,
226 /* Ask the relay to create a trace chunk (2.11+) */
227 RELAYD_CREATE_TRACE_CHUNK = 19,
228 /* Ask the relay to close a trace chunk (2.11+) */
229 RELAYD_CLOSE_TRACE_CHUNK = 20,
230 /* Ask the relay whether a trace chunk exists (2.11+) */
231 RELAYD_TRACE_CHUNK_EXISTS = 21,
232 /* Get the current configuration of a relayd peer (2.12+) */
233 RELAYD_GET_CONFIGURATION = 22,
234
235 /* Feature branch specific commands start at 10000. */
236 };
237
238 static inline const char *lttcomm_relayd_command_str(lttcomm_relayd_command cmd)
239 {
240 switch (cmd) {
241 case RELAYD_ADD_STREAM:
242 return "RELAYD_ADD_STREAM";
243 case RELAYD_CREATE_SESSION:
244 return "RELAYD_CREATE_SESSION";
245 case RELAYD_START_DATA:
246 return "RELAYD_START_DATA";
247 case RELAYD_UPDATE_SYNC_INFO:
248 return "RELAYD_UPDATE_SYNC_INFO";
249 case RELAYD_VERSION:
250 return "RELAYD_VERSION";
251 case RELAYD_SEND_METADATA:
252 return "RELAYD_SEND_METADATA";
253 case RELAYD_CLOSE_STREAM:
254 return "RELAYD_CLOSE_STREAM";
255 case RELAYD_DATA_PENDING:
256 return "RELAYD_DATA_PENDING";
257 case RELAYD_QUIESCENT_CONTROL:
258 return "RELAYD_QUIESCENT_CONTROL";
259 case RELAYD_BEGIN_DATA_PENDING:
260 return "RELAYD_BEGIN_DATA_PENDING";
261 case RELAYD_END_DATA_PENDING:
262 return "RELAYD_END_DATA_PENDING";
263 case RELAYD_ADD_INDEX:
264 return "RELAYD_ADD_INDEX";
265 case RELAYD_SEND_INDEX:
266 return "RELAYD_SEND_INDEX";
267 case RELAYD_CLOSE_INDEX:
268 return "RELAYD_CLOSE_INDEX";
269 case RELAYD_LIST_SESSIONS:
270 return "RELAYD_LIST_SESSIONS";
271 case RELAYD_STREAMS_SENT:
272 return "RELAYD_STREAMS_SENT";
273 case RELAYD_RESET_METADATA:
274 return "RELAYD_RESET_METADATA";
275 case RELAYD_ROTATE_STREAMS:
276 return "RELAYD_ROTATE_STREAMS";
277 case RELAYD_CREATE_TRACE_CHUNK:
278 return "RELAYD_CREATE_TRACE_CHUNK";
279 case RELAYD_CLOSE_TRACE_CHUNK:
280 return "RELAYD_CLOSE_TRACE_CHUNK";
281 case RELAYD_TRACE_CHUNK_EXISTS:
282 return "RELAYD_TRACE_CHUNK_EXISTS";
283 case RELAYD_GET_CONFIGURATION:
284 return "RELAYD_GET_CONFIGURATION";
285 default:
286 abort();
287 }
288 }
289
290 /*
291 * lttcomm error code.
292 */
293 enum lttcomm_return_code {
294 LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */
295 /*
296 * Some code paths use -1 to express an error, others
297 * negate this consumer return code. Starting codes at
298 * 100 ensures there is no mix-up between this error value
299 * and legitimate status codes.
300 */
301 LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 100, /* Command socket ready */
302 LTTCOMM_CONSUMERD_SUCCESS_RECV_FD, /* Success on receiving fds */
303 LTTCOMM_CONSUMERD_ERROR_RECV_FD, /* Error on receiving fds */
304 LTTCOMM_CONSUMERD_ERROR_RECV_CMD, /* Error on receiving command */
305 LTTCOMM_CONSUMERD_POLL_ERROR, /* Error in polling thread */
306 LTTCOMM_CONSUMERD_POLL_NVAL, /* Poll on closed fd */
307 LTTCOMM_CONSUMERD_POLL_HUP, /* All fds have hungup */
308 LTTCOMM_CONSUMERD_EXIT_SUCCESS, /* Consumerd exiting normally */
309 LTTCOMM_CONSUMERD_EXIT_FAILURE, /* Consumerd exiting on error */
310 LTTCOMM_CONSUMERD_OUTFD_ERROR, /* Error opening the tracefile */
311 LTTCOMM_CONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */
312 LTTCOMM_CONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */
313 LTTCOMM_CONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
314 LTTCOMM_CONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
315 LTTCOMM_CONSUMERD_ENOMEM, /* Consumer is out of memory */
316 LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */
317 LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */
318 LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */
319 LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
320 LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
321 LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
322 LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
323 LTTCOMM_CONSUMERD_SNAPSHOT_FAILED, /* snapshot has failed. */
324 LTTCOMM_CONSUMERD_CREATE_TRACE_CHUNK_FAILED, /* Trace chunk creation failed. */
325 LTTCOMM_CONSUMERD_CLOSE_TRACE_CHUNK_FAILED, /* Trace chunk close failed. */
326 LTTCOMM_CONSUMERD_INVALID_PARAMETERS, /* Invalid parameters. */
327 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_LOCAL, /* Trace chunk exists on consumer daemon. */
328 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_REMOTE, /* Trace chunk exists on relay daemon. */
329 LTTCOMM_CONSUMERD_UNKNOWN_TRACE_CHUNK, /* Unknown trace chunk. */
330 LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED, /* Relayd does not accept clear command. */
331 LTTCOMM_CONSUMERD_UNKNOWN_ERROR, /* Unknown error. */
332
333 /* MUST be last element */
334 LTTCOMM_NR, /* Last element */
335 };
336
337 /* lttng socket protocol. */
338 enum lttcomm_sock_proto {
339 LTTCOMM_SOCK_UDP,
340 LTTCOMM_SOCK_TCP,
341 };
342
343 /*
344 * Index in the net_families array below. Please keep in sync!
345 */
346 enum lttcomm_sock_domain {
347 LTTCOMM_INET = 0,
348 LTTCOMM_INET6 = 1,
349 };
350
351 enum lttcomm_metadata_command {
352 LTTCOMM_METADATA_REQUEST = 1,
353 };
354
355 /*
356 * Commands sent from the consumerd to the sessiond to request if new metadata
357 * is available. This message is used to find the per UID _or_ per PID registry
358 * for the channel key. For per UID lookup, the triplet
359 * bits_per_long/uid/session_id is used. On lookup failure, we search for the
360 * per PID registry indexed by session id ignoring the other values.
361 */
362 struct lttcomm_metadata_request_msg {
363 uint64_t session_id; /* Tracing session id */
364 uint64_t session_id_per_pid; /* Tracing session id for per-pid */
365 uint32_t bits_per_long; /* Consumer ABI */
366 uint32_t uid;
367 uint64_t key; /* Metadata channel key. */
368 } LTTNG_PACKED;
369
370 struct lttcomm_sockaddr {
371 enum lttcomm_sock_domain type;
372 union {
373 struct sockaddr_in sin;
374 struct sockaddr_in6 sin6;
375 } addr;
376 };
377
378 struct lttcomm_sock {
379 int32_t fd;
380 enum lttcomm_sock_proto proto;
381 struct lttcomm_sockaddr sockaddr;
382 const struct lttcomm_proto_ops *ops;
383 };
384
385 /*
386 * Relayd sock. Adds the protocol version to use for the communications with
387 * the relayd.
388 */
389 struct lttcomm_relayd_sock {
390 struct lttcomm_sock sock;
391 uint32_t major;
392 uint32_t minor;
393 };
394
395 struct lttcomm_net_family {
396 int family;
397 int (*create)(struct lttcomm_sock *sock, int type, int proto);
398 };
399
400 struct lttcomm_proto_ops {
401 int (*bind)(struct lttcomm_sock *sock);
402 int (*close)(struct lttcomm_sock *sock);
403 int (*connect)(struct lttcomm_sock *sock);
404 struct lttcomm_sock *(*accept)(struct lttcomm_sock *sock);
405 int (*listen)(struct lttcomm_sock *sock, int backlog);
406 ssize_t (*recvmsg)(struct lttcomm_sock *sock, void *buf, size_t len, int flags);
407 ssize_t (*sendmsg)(struct lttcomm_sock *sock, const void *buf, size_t len, int flags);
408 };
409
410 struct process_attr_integral_value_comm {
411 union {
412 int64_t _signed;
413 uint64_t _unsigned;
414 } u;
415 } LTTNG_PACKED;
416
417 /*
418 * Data structure received from lttng client to session daemon.
419 */
420 struct lttcomm_session_msg {
421 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
422 struct lttng_session session;
423 struct lttng_domain domain;
424 union {
425 /* Event data */
426 struct {
427 char channel_name[LTTNG_SYMBOL_NAME_LEN];
428 uint32_t length;
429 } LTTNG_PACKED enable;
430 struct {
431 char channel_name[LTTNG_SYMBOL_NAME_LEN];
432 uint32_t length;
433 } LTTNG_PACKED disable;
434 /* Create channel */
435 struct {
436 uint32_t length;
437 } LTTNG_PACKED channel;
438 /* Context */
439 struct {
440 char channel_name[LTTNG_SYMBOL_NAME_LEN];
441 uint32_t length;
442 } LTTNG_PACKED context;
443 /* Use by register_consumer */
444 struct {
445 char path[PATH_MAX];
446 } LTTNG_PACKED reg;
447 /* List */
448 struct {
449 char channel_name[LTTNG_SYMBOL_NAME_LEN];
450 } LTTNG_PACKED list;
451 struct lttng_calibrate calibrate;
452 /* Used by the set_consumer_url and used by create_session also call */
453 struct {
454 /* Number of lttng_uri following */
455 uint32_t size;
456 } LTTNG_PACKED uri;
457 struct {
458 struct lttng_snapshot_output output;
459 } LTTNG_PACKED snapshot_output;
460 struct {
461 uint32_t wait;
462 struct lttng_snapshot_output output;
463 } LTTNG_PACKED snapshot_record;
464 struct {
465 uint32_t nb_uri;
466 unsigned int timer_interval; /* usec */
467 } LTTNG_PACKED session_live;
468 struct {
469 struct lttng_save_session_attr attr;
470 } LTTNG_PACKED save_session;
471 struct {
472 char shm_path[PATH_MAX];
473 } LTTNG_PACKED set_shm_path;
474 struct {
475 /* enum lttng_process_attr */
476 int32_t process_attr;
477 /* enum lttng_process_attr_value_type */
478 int32_t value_type;
479
480 struct process_attr_integral_value_comm integral_value;
481 /*
482 * For user/group names, a variable length,
483 * zero-terminated, string of length 'name_len'
484 * (including the terminator) follows.
485 *
486 * integral_value should not be used in those cases.
487 */
488 uint32_t name_len;
489 } LTTNG_PACKED process_attr_tracker_add_remove_include_value;
490 struct {
491 /* enum lttng_process_attr */
492 int32_t process_attr;
493 } LTTNG_PACKED process_attr_tracker_get_inclusion_set;
494 struct {
495 /* enum lttng_process_attr */
496 int32_t process_attr;
497 } LTTNG_PACKED process_attr_tracker_get_tracking_policy;
498 struct {
499 /* enum lttng_process_attr */
500 int32_t process_attr;
501 /* enum lttng_tracking_policy */
502 int32_t tracking_policy;
503 } LTTNG_PACKED process_attr_tracker_set_tracking_policy;
504 struct {
505 uint32_t length;
506 uint8_t is_trigger_anonymous;
507 } LTTNG_PACKED trigger;
508 struct {
509 uint32_t length;
510 } LTTNG_PACKED error_query;
511 struct {
512 uint64_t rotation_id;
513 } LTTNG_PACKED get_rotation_info;
514 struct {
515 /* enum lttng_rotation_schedule_type */
516 uint8_t type;
517 /*
518 * If set == 1, set schedule to value, if set == 0,
519 * clear this schedule type.
520 */
521 uint8_t set;
522 uint64_t value;
523 } LTTNG_PACKED rotation_set_schedule;
524 struct {
525 /*
526 * Includes the null-terminator.
527 * Must be an absolute path.
528 *
529 * Size bounded by LTTNG_PATH_MAX.
530 */
531 uint16_t home_dir_size;
532 uint64_t session_descriptor_size;
533 /* An lttng_session_descriptor follows. */
534 } LTTNG_PACKED create_session;
535 } u;
536 /* Count of fds sent. */
537 uint32_t fd_count;
538 } LTTNG_PACKED;
539
540 #define LTTNG_FILTER_MAX_LEN 65536
541 #define LTTNG_SESSION_DESCRIPTOR_MAX_LEN 65536
542
543 /*
544 * Filter bytecode data. The reloc table is located at the end of the
545 * bytecode. It is made of tuples: (uint16_t, var. len. string). It
546 * starts at reloc_table_offset.
547 */
548 #define LTTNG_FILTER_PADDING 32
549 struct lttng_bytecode {
550 uint32_t len; /* len of data */
551 uint32_t reloc_table_offset;
552 uint64_t seqnum;
553 char padding[LTTNG_FILTER_PADDING];
554 char data[0];
555 } LTTNG_PACKED;
556
557 /*
558 * Event exclusion data. At the end of the structure, there will actually
559 * by zero or more names, where the actual number of names is given by
560 * the 'count' item of the structure.
561 */
562 #define LTTNG_EVENT_EXCLUSION_PADDING 32
563 struct lttng_event_exclusion {
564 uint32_t count;
565 char padding[LTTNG_EVENT_EXCLUSION_PADDING];
566 char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH][LTTNG_SYMBOL_NAME_LEN];
567 } LTTNG_PACKED;
568
569 #define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) ((_exclusion)->names[_i])
570
571 /*
572 * Listing command header.
573 */
574 struct lttcomm_list_command_header {
575 /* Number of elements */
576 uint32_t count;
577 } LTTNG_PACKED;
578
579 /*
580 * Event extended info header. This is the structure preceding each
581 * extended info data.
582 */
583 struct lttcomm_event_extended_header {
584 /*
585 * Size of filter string immediately following this header.
586 * This size includes the terminal null character.
587 */
588 uint32_t filter_len;
589
590 /*
591 * Number of exclusion names, immediately following the filter
592 * string. Each exclusion name has a fixed length of
593 * LTTNG_SYMBOL_NAME_LEN bytes, including the terminal null
594 * character.
595 */
596 uint32_t nb_exclusions;
597
598 /*
599 * Size of the event's userspace probe location (if applicable).
600 */
601 uint32_t userspace_probe_location_len;
602 } LTTNG_PACKED;
603
604 /*
605 * Command header of the reply to an LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION command.
606 */
607 struct lttcomm_session_destroy_command_header {
608 /* enum lttng_session */
609 int32_t rotation_state;
610 };
611
612 /*
613 * tracker command header.
614 */
615 struct lttcomm_tracker_command_header {
616 uint32_t nb_tracker_id;
617 } LTTNG_PACKED;
618
619 /*
620 * Data structure for the response from sessiond to the lttng client.
621 */
622 struct lttcomm_lttng_msg {
623 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
624 uint32_t ret_code; /* enum lttcomm_return_code */
625 uint32_t pid; /* pid_t */
626 uint32_t cmd_header_size;
627 uint32_t data_size;
628 uint32_t fd_count;
629 } LTTNG_PACKED;
630
631 struct lttcomm_lttng_output_id {
632 uint32_t id;
633 } LTTNG_PACKED;
634
635 /*
636 * lttcomm_consumer_msg is the message sent from sessiond to consumerd
637 * to either add a channel, add a stream, update a stream, or stop
638 * operation.
639 */
640 struct lttcomm_consumer_msg {
641 uint32_t cmd_type; /* enum lttng_consumer_command */
642 union {
643 struct {
644 uint64_t channel_key;
645 uint64_t session_id;
646 /* ID of the session's current trace chunk. */
647 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
648 char pathname[PATH_MAX];
649 uint64_t relayd_id;
650 /* nb_init_streams is the number of streams open initially. */
651 uint32_t nb_init_streams;
652 char name[LTTNG_SYMBOL_NAME_LEN];
653 /* Use splice or mmap to consume this fd */
654 enum lttng_event_output output;
655 int type; /* Per cpu or metadata. */
656 uint64_t tracefile_size; /* bytes */
657 uint32_t tracefile_count; /* number of tracefiles */
658 /* If the channel's streams have to be monitored or not. */
659 uint32_t monitor;
660 /* timer to check the streams usage in live mode (usec). */
661 unsigned int live_timer_interval;
662 /* is part of a live session */
663 uint8_t is_live;
664 /* timer to sample a channel's positions (usec). */
665 unsigned int monitor_timer_interval;
666 } LTTNG_PACKED channel; /* Only used by Kernel. */
667 struct {
668 uint64_t stream_key;
669 uint64_t channel_key;
670 int32_t cpu; /* On which CPU this stream is assigned. */
671 /* Tells the consumer if the stream should be or not monitored. */
672 uint32_t no_monitor;
673 } LTTNG_PACKED stream; /* Only used by Kernel. */
674 struct {
675 uint64_t net_index;
676 enum lttng_stream_type type;
677 uint32_t major;
678 uint32_t minor;
679 uint8_t relayd_socket_protocol;
680 /* Tracing session id associated to the relayd. */
681 uint64_t session_id;
682 /* Relayd session id, only used with control socket. */
683 uint64_t relayd_session_id;
684 } LTTNG_PACKED relayd_sock;
685 struct {
686 uint64_t net_seq_idx;
687 } LTTNG_PACKED destroy_relayd;
688 struct {
689 uint64_t session_id;
690 } LTTNG_PACKED data_pending;
691 struct {
692 uint64_t subbuf_size; /* bytes */
693 uint64_t num_subbuf; /* power of 2 */
694 int32_t overwrite; /* 1: overwrite, 0: discard */
695 uint32_t switch_timer_interval; /* usec */
696 uint32_t read_timer_interval; /* usec */
697 unsigned int live_timer_interval; /* usec */
698 uint8_t is_live; /* is part of a live session */
699 uint32_t monitor_timer_interval; /* usec */
700 int32_t output; /* splice, mmap */
701 int32_t type; /* metadata or per_cpu */
702 uint64_t session_id; /* Tracing session id */
703 char pathname[PATH_MAX]; /* Channel file path. */
704 char name[LTTNG_SYMBOL_NAME_LEN]; /* Channel name. */
705 /* Credentials used to open the UST buffer shared mappings. */
706 struct {
707 uint32_t uid;
708 uint32_t gid;
709 } LTTNG_PACKED buffer_credentials;
710 uint64_t relayd_id; /* Relayd id if apply. */
711 uint64_t key; /* Unique channel key. */
712 /* ID of the session's current trace chunk. */
713 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
714 unsigned char uuid[LTTNG_UUID_LEN]; /* uuid for ust tracer. */
715 uint32_t chan_id; /* Channel ID on the tracer side. */
716 uint64_t tracefile_size; /* bytes */
717 uint32_t tracefile_count; /* number of tracefiles */
718 uint64_t session_id_per_pid; /* Per-pid session ID. */
719 /* Tells the consumer if the stream should be or not monitored. */
720 uint32_t monitor;
721 /*
722 * For UST per UID buffers, this is the application UID of the
723 * channel. This can be different from the user UID requesting the
724 * channel creation and used for the rights on the stream file
725 * because the application can be in the tracing for instance.
726 */
727 uint32_t ust_app_uid;
728 int64_t blocking_timeout;
729 char root_shm_path[PATH_MAX];
730 char shm_path[PATH_MAX];
731 } LTTNG_PACKED ask_channel;
732 struct {
733 uint64_t key;
734 } LTTNG_PACKED get_channel;
735 struct {
736 uint64_t key;
737 } LTTNG_PACKED destroy_channel;
738 struct {
739 uint64_t key; /* Metadata channel key. */
740 uint64_t target_offset; /* Offset in the consumer */
741 uint64_t len; /* Length of metadata to be received. */
742 uint64_t version; /* Version of the metadata. */
743 } LTTNG_PACKED push_metadata;
744 struct {
745 uint64_t key; /* Metadata channel key. */
746 } LTTNG_PACKED close_metadata;
747 struct {
748 uint64_t key; /* Metadata channel key. */
749 } LTTNG_PACKED setup_metadata;
750 struct {
751 uint64_t key; /* Channel key. */
752 } LTTNG_PACKED flush_channel;
753 struct {
754 uint64_t key; /* Channel key. */
755 } LTTNG_PACKED clear_quiescent_channel;
756 struct {
757 char pathname[PATH_MAX];
758 /* Indicate if the snapshot goes on the relayd or locally. */
759 uint32_t use_relayd;
760 uint32_t metadata; /* This a metadata snapshot. */
761 uint64_t relayd_id; /* Relayd id if apply. */
762 uint64_t key;
763 uint64_t nb_packets_per_stream;
764 } LTTNG_PACKED snapshot_channel;
765 struct {
766 uint64_t channel_key;
767 uint64_t net_seq_idx;
768 } LTTNG_PACKED sent_streams;
769 struct {
770 uint64_t session_id;
771 uint64_t channel_key;
772 } LTTNG_PACKED discarded_events;
773 struct {
774 uint64_t session_id;
775 uint64_t channel_key;
776 } LTTNG_PACKED lost_packets;
777 struct {
778 uint64_t session_id;
779 } LTTNG_PACKED regenerate_metadata;
780 struct {
781 uint32_t metadata; /* This is a metadata channel. */
782 uint64_t relayd_id; /* Relayd id if apply. */
783 uint64_t key;
784 } LTTNG_PACKED rotate_channel;
785 struct {
786 uint64_t session_id;
787 uint64_t chunk_id;
788 } LTTNG_PACKED check_rotation_pending_local;
789 struct {
790 uint64_t relayd_id;
791 uint64_t session_id;
792 uint64_t chunk_id;
793 } LTTNG_PACKED check_rotation_pending_relay;
794 struct {
795 /*
796 * Relayd id, if applicable (remote).
797 *
798 * A directory file descriptor referring to the chunk's
799 * output folder is transmitted if the chunk is local
800 * (relayd_id unset).
801 *
802 * `override_name` is left NULL (all-zeroes) if the
803 * chunk's name is not overridden.
804 */
805 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
806 char override_name[LTTNG_NAME_MAX];
807 uint64_t session_id;
808 uint64_t chunk_id;
809 uint64_t creation_timestamp;
810 LTTNG_OPTIONAL_COMM(struct {
811 uint32_t uid;
812 uint32_t gid;
813 } LTTNG_PACKED)
814 LTTNG_PACKED credentials;
815 } LTTNG_PACKED create_trace_chunk;
816 struct {
817 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
818 uint64_t session_id;
819 uint64_t chunk_id;
820 uint64_t close_timestamp;
821 /* enum lttng_trace_chunk_command_type */
822 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
823 } LTTNG_PACKED close_trace_chunk;
824 struct {
825 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
826 uint64_t session_id;
827 uint64_t chunk_id;
828 } LTTNG_PACKED trace_chunk_exists;
829 struct {
830 uint8_t sessiond_uuid[LTTNG_UUID_LEN];
831 } LTTNG_PACKED init;
832 struct {
833 uint64_t key;
834 } LTTNG_PACKED clear_channel;
835 struct {
836 uint64_t key;
837 } LTTNG_PACKED open_channel_packets;
838 } u;
839 } LTTNG_PACKED;
840
841 /*
842 * Channel monitoring message returned to the session daemon on every
843 * monitor timer expiration.
844 */
845 struct lttcomm_consumer_channel_monitor_msg {
846 /* Key of the sampled channel. */
847 uint64_t key;
848 /* Id of the sampled channel's session. */
849 uint64_t session_id;
850 /*
851 * Lowest and highest usage (bytes) at the moment the sample was taken.
852 */
853 uint64_t lowest, highest;
854 /*
855 * Sum of all the consumed positions for a channel.
856 */
857 uint64_t consumed_since_last_sample;
858 } LTTNG_PACKED;
859
860 /*
861 * Status message returned to the sessiond after a received command.
862 */
863 struct lttcomm_consumer_status_msg {
864 enum lttcomm_return_code ret_code;
865 } LTTNG_PACKED;
866
867 struct lttcomm_consumer_status_channel {
868 enum lttcomm_return_code ret_code;
869 uint64_t key;
870 unsigned int stream_count;
871 } LTTNG_PACKED;
872
873 struct lttcomm_consumer_close_trace_chunk_reply {
874 enum lttcomm_return_code ret_code;
875 uint32_t path_length;
876 char path[];
877 };
878
879 #ifdef HAVE_LIBLTTNG_UST_CTL
880
881 #include <lttng/ust-abi.h>
882
883 /*
884 * Data structure for the commands sent from sessiond to UST.
885 */
886 struct lttcomm_ust_msg {
887 uint32_t handle;
888 uint32_t cmd;
889 union {
890 struct lttng_ust_abi_channel channel;
891 struct lttng_ust_abi_stream stream;
892 struct lttng_ust_abi_event event;
893 struct lttng_ust_abi_context context;
894 struct lttng_ust_abi_tracer_version version;
895 } u;
896 } LTTNG_PACKED;
897
898 /*
899 * Data structure for the response from UST to the session daemon.
900 * cmd_type is sent back in the reply for validation.
901 */
902 struct lttcomm_ust_reply {
903 uint32_t handle;
904 uint32_t cmd;
905 uint32_t ret_code; /* enum lttcomm_return_code */
906 uint32_t ret_val; /* return value */
907 union {
908 struct {
909 uint64_t memory_map_size;
910 } LTTNG_PACKED channel;
911 struct {
912 uint64_t memory_map_size;
913 } LTTNG_PACKED stream;
914 struct lttng_ust_abi_tracer_version version;
915 } u;
916 } LTTNG_PACKED;
917
918 #endif /* HAVE_LIBLTTNG_UST_CTL */
919
920 const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
921
922 int lttcomm_init_inet_sockaddr(struct lttcomm_sockaddr *sockaddr,
923 const char *ip,
924 unsigned int port);
925 int lttcomm_init_inet6_sockaddr(struct lttcomm_sockaddr *sockaddr,
926 const char *ip,
927 unsigned int port);
928
929 struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto);
930 int lttcomm_populate_sock_from_open_socket(struct lttcomm_sock *sock,
931 int fd,
932 enum lttcomm_sock_proto protocol);
933 int lttcomm_create_sock(struct lttcomm_sock *sock);
934 struct lttcomm_sock *lttcomm_alloc_sock_from_uri(struct lttng_uri *uri);
935 void lttcomm_destroy_sock(struct lttcomm_sock *sock);
936 struct lttcomm_sock *lttcomm_alloc_copy_sock(struct lttcomm_sock *src);
937 void lttcomm_copy_sock(struct lttcomm_sock *dst, struct lttcomm_sock *src);
938
939 /* Relayd socket object. */
940 struct lttcomm_relayd_sock *
941 lttcomm_alloc_relayd_sock(struct lttng_uri *uri, uint32_t major, uint32_t minor);
942
943 int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
944 int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
945
946 int lttcomm_sock_get_port(const struct lttcomm_sock *sock, uint16_t *port);
947 /*
948 * Set a port to an lttcomm_sock. This will have no effect is the socket is
949 * already bound.
950 */
951 int lttcomm_sock_set_port(struct lttcomm_sock *sock, uint16_t port);
952
953 void lttcomm_init();
954 /* Get network timeout, in milliseconds */
955 unsigned long lttcomm_get_network_timeout();
956
957 #endif /* _LTTNG_SESSIOND_COMM_H */
This page took 0.048858 seconds and 5 git commands to generate.