SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / src / common / sessiond-comm / sessiond-comm.h
CommitLineData
6e3805e2 1/*
ab5be9fa
MJ
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>
fac6795d 5 *
ab5be9fa 6 * SPDX-License-Identifier: GPL-2.0-only
ba999de0 7 *
fac6795d
DG
8 */
9
773168b7 10/*
990570ed
DG
11 * This header is meant for liblttng and libust internal use ONLY. These
12 * declarations should NOT be considered stable API.
773168b7 13 */
fac6795d 14
990570ed
DG
15#ifndef _LTTNG_SESSIOND_COMM_H
16#define _LTTNG_SESSIOND_COMM_H
17
fac6795d 18#include <limits.h>
f3ed775e 19#include <lttng/lttng.h>
da3c9ec1 20#include <lttng/snapshot-internal.h>
00c76cea 21#include <lttng/save-internal.h>
e9404c27
JG
22#include <lttng/channel-internal.h>
23#include <lttng/trigger/trigger-internal.h>
d88744a4 24#include <lttng/rotate-internal.h>
b17231c6 25#include <common/compat/socket.h>
a4b92340 26#include <common/uri.h>
ce2a9e76 27#include <common/defaults.h>
c70636a7 28#include <common/uuid.h>
aa52c986 29#include <common/macros.h>
d2956687 30#include <common/optional.h>
5e16da05 31
6364a07a
DG
32#include <arpa/inet.h>
33#include <netinet/in.h>
34#include <sys/un.h>
35
36#include "inet.h"
37#include "inet6.h"
2038dd6c 38#include <common/unix.h>
0d37f2bc 39
fac6795d 40/* Queue size of listen(2) */
f158a754 41#define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
fac6795d 42
990570ed
DG
43/* Maximum number of FDs that can be sent over a Unix socket */
44#define LTTCOMM_MAX_SEND_FDS 4
45
3817e7df
DG
46/*
47 * Get the error code index from 0 since LTTCOMM_OK start at 1000
fac6795d 48 */
f73fabfd 49#define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_CONSUMERD_COMMAND_SOCK_READY)
fac6795d 50
6abb15de 51enum lttcomm_sessiond_command {
0d0c377a 52 /* Tracer command */
66ea93b1 53 LTTNG_ADD_CONTEXT = 0,
b812e5ca 54 /* LTTNG_CALIBRATE used to be here */
66ea93b1
JG
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,
18a720cd 60 /* 7 */
0d0c377a 61 /* Session daemon command */
b178f53e 62 /* 8 */
66ea93b1
JG
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,
53a80697 73
de5e9086 74 /* Consumer */
66ea93b1
JG
75 LTTNG_DISABLE_CONSUMER = 19,
76 LTTNG_ENABLE_CONSUMER = 20,
77 LTTNG_SET_CONSUMER_URI = 21,
67676bd8
DG
78 /* 22 */
79 /* 23 */
66ea93b1
JG
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,
b178f53e
JG
85 /* 29 */
86 /* 30 */
66ea93b1 87 LTTNG_SAVE_SESSION = 31,
55c9e7ca
JR
88 LTTNG_TRACK_ID = 32,
89 LTTNG_UNTRACK_ID = 33,
90 LTTNG_LIST_TRACKER_IDS = 34,
66ea93b1
JG
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,
2c2de71e 99 LTTNG_SESSION_LIST_ROTATION_SCHEDULES = 48,
f2c1f0d4
MD
100 LTTNG_CREATE_SESSION_EXT = 49,
101 LTTNG_CLEAR_SESSION = 50,
1831ae68 102 LTTNG_LIST_TRIGGERS = 51,
7c9534d6
JD
103};
104
105enum 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,
1c20f0e2
JD
117 RELAYD_ADD_INDEX = 12,
118 RELAYD_SEND_INDEX = 13,
119 RELAYD_CLOSE_INDEX = 14,
a4baae1b 120 /* Live-reading commands (2.4+). */
d3e2ba59 121 RELAYD_LIST_SESSIONS = 15,
a4baae1b
JD
122 /* All streams of the channel have been sent to the relayd (2.4+). */
123 RELAYD_STREAMS_SENT = 16,
93ec662e
JD
124 /* Ask the relay to reset the metadata trace file (2.8+) */
125 RELAYD_RESET_METADATA = 17,
c35f9726
JG
126 /* Ask the relay to rotate a set of stream files (2.11+) */
127 RELAYD_ROTATE_STREAMS = 18,
e5add6d0
JG
128 /* Ask the relay to create a trace chunk (2.11+) */
129 RELAYD_CREATE_TRACE_CHUNK = 19,
bbc4768c
JG
130 /* Ask the relay to close a trace chunk (2.11+) */
131 RELAYD_CLOSE_TRACE_CHUNK = 20,
c35f9726
JG
132 /* Ask the relay whether a trace chunk exists (2.11+) */
133 RELAYD_TRACE_CHUNK_EXISTS = 21,
8614e600
MD
134 /* Get the current configuration of a relayd peer (2.12+) */
135 RELAYD_GET_CONFIGURATION = 22,
3fe73a46
MD
136
137 /* Feature branch specific commands start at 10000. */
fac6795d
DG
138};
139
140/*
141 * lttcomm error code.
142 */
143enum lttcomm_return_code {
0c759fc9 144 LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */
d2956687
JG
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 */
f73fabfd
DG
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) */
ffe60014 165 LTTCOMM_CONSUMERD_ENOMEM, /* Consumer is out of memory */
d88aee68
DG
166 LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */
167 LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */
618a6a28 168 LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */
0c759fc9 169 LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
e462382a 170 LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
e9404c27 171 LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
92b7a7f8 172 LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
3eb928aa 173 LTTCOMM_CONSUMERD_SNAPSHOT_FAILED, /* snapshot has failed. */
d2956687
JG
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. */
b01b201a 180 LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED, /* Relayd does not accept clear command. */
80e327fa 181
20fe2104
DG
182 /* MUST be last element */
183 LTTCOMM_NR, /* Last element */
fac6795d
DG
184};
185
de5e9086
DG
186/* lttng socket protocol. */
187enum 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 */
195enum lttcomm_sock_domain {
01d0a631
CB
196 LTTCOMM_INET = 0,
197 LTTCOMM_INET6 = 1,
de5e9086
DG
198};
199
331744e3
JD
200enum 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 */
211struct lttcomm_metadata_request_msg {
1950109e
JD
212 uint64_t session_id; /* Tracing session id */
213 uint64_t session_id_per_pid; /* Tracing session id for per-pid */
331744e3
JD
214 uint32_t bits_per_long; /* Consumer ABI */
215 uint32_t uid;
216 uint64_t key; /* Metadata channel key. */
217} LTTNG_PACKED;
218
de5e9086
DG
219struct lttcomm_sockaddr {
220 enum lttcomm_sock_domain type;
221 union {
222 struct sockaddr_in sin;
223 struct sockaddr_in6 sin6;
224 } addr;
fc5e05b7 225} LTTNG_PACKED;
de5e9086
DG
226
227struct lttcomm_sock {
d88aee68 228 int32_t fd;
de5e9086
DG
229 enum lttcomm_sock_proto proto;
230 struct lttcomm_sockaddr sockaddr;
231 const struct lttcomm_proto_ops *ops;
fc5e05b7 232} LTTNG_PACKED;
de5e9086 233
6151a90f
JD
234/*
235 * Relayd sock. Adds the protocol version to use for the communications with
236 * the relayd.
237 */
238struct lttcomm_relayd_sock {
239 struct lttcomm_sock sock;
240 uint32_t major;
241 uint32_t minor;
242} LTTNG_PACKED;
243
de5e9086
DG
244struct lttcomm_net_family {
245 int family;
246 int (*create) (struct lttcomm_sock *sock, int type, int proto);
247};
248
249struct 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);
c2d69327
JG
257 ssize_t (*sendmsg) (struct lttcomm_sock *sock, const void *buf,
258 size_t len, int flags);
de5e9086
DG
259};
260
fac6795d 261/*
9bda164d 262 * Data structure received from lttng client to session daemon.
fac6795d
DG
263 */
264struct lttcomm_session_msg {
d0b96690 265 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
42abccdb 266 struct lttng_session session;
9f19cc17 267 struct lttng_domain domain;
fac6795d 268 union {
f3ed775e 269 /* Event data */
fac6795d 270 struct {
db8870ed 271 char channel_name[LTTNG_SYMBOL_NAME_LEN];
1179a48f 272 struct lttng_event event LTTNG_PACKED;
6b453b5e
JG
273 /* Length of following filter expression. */
274 uint32_t expression_len;
025faf73
DG
275 /* Length of following bytecode for filter. */
276 uint32_t bytecode_len;
15e37663 277 /* Exclusion count (fixed-size strings). */
a5516688 278 uint32_t exclusion_count;
15e37663
JG
279 /* Userspace probe location size. */
280 uint32_t userspace_probe_location_len;
a5516688
JI
281 /*
282 * After this structure, the following variable-length
283 * items are transmitted:
284 * - char exclusion_names[LTTNG_SYMBOL_NAME_LEN][exclusion_count]
15e37663 285 * - char filter_expression[expression_len]
a5516688
JI
286 * - unsigned char filter_bytecode[bytecode_len]
287 */
fc5e05b7 288 } LTTNG_PACKED enable;
6e911cad
MD
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;
f3ed775e
DG
303 /* Create channel */
304 struct {
1179a48f 305 struct lttng_channel chan LTTNG_PACKED;
e9404c27
JG
306 /* struct lttng_channel_extended is already packed. */
307 struct lttng_channel_extended extended;
fc5e05b7 308 } LTTNG_PACKED channel;
d65106b1
DG
309 /* Context */
310 struct {
db8870ed 311 char channel_name[LTTNG_SYMBOL_NAME_LEN];
1179a48f 312 struct lttng_event_context ctx LTTNG_PACKED;
2001793c
JG
313 uint32_t provider_name_len;
314 uint32_t context_name_len;
fc5e05b7 315 } LTTNG_PACKED context;
d9800920
DG
316 /* Use by register_consumer */
317 struct {
318 char path[PATH_MAX];
fc5e05b7 319 } LTTNG_PACKED reg;
9f19cc17
DG
320 /* List */
321 struct {
db8870ed 322 char channel_name[LTTNG_SYMBOL_NAME_LEN];
fc5e05b7 323 } LTTNG_PACKED list;
d0254c7c 324 struct lttng_calibrate calibrate;
a4b92340 325 /* Used by the set_consumer_url and used by create_session also call */
de5e9086 326 struct {
a4b92340
DG
327 /* Number of lttng_uri following */
328 uint32_t size;
fc5e05b7 329 } LTTNG_PACKED uri;
da3c9ec1 330 struct {
1179a48f 331 struct lttng_snapshot_output output LTTNG_PACKED;
da3c9ec1
DG
332 } LTTNG_PACKED snapshot_output;
333 struct {
334 uint32_t wait;
1179a48f 335 struct lttng_snapshot_output output LTTNG_PACKED;
da3c9ec1 336 } LTTNG_PACKED snapshot_record;
ecc48a90
JD
337 struct {
338 uint32_t nb_uri;
339 unsigned int timer_interval; /* usec */
340 } LTTNG_PACKED session_live;
00c76cea 341 struct {
1179a48f 342 struct lttng_save_session_attr attr; /* struct already packed */
00c76cea 343 } LTTNG_PACKED save_session;
d7ba1388
MD
344 struct {
345 char shm_path[PATH_MAX];
346 } LTTNG_PACKED set_shm_path;
ccf10263 347 struct {
55c9e7ca
JR
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;
e9404c27
JG
363 struct {
364 uint32_t length;
365 } LTTNG_PACKED trigger;
d88744a4 366 struct {
d68c9a04
JD
367 uint64_t rotation_id;
368 } LTTNG_PACKED get_rotation_info;
259c2674 369 struct {
66ea93b1
JG
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;
b178f53e
JG
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;
fac6795d 390 } u;
fc5e05b7 391} LTTNG_PACKED;
fac6795d 392
d93c4f1f 393#define LTTNG_FILTER_MAX_LEN 65536
b178f53e 394#define LTTNG_SESSION_DESCRIPTOR_MAX_LEN 65536
53a80697
MD
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 */
b6bbed5f 401#define LTTNG_FILTER_PADDING 32
53a80697 402struct lttng_filter_bytecode {
d93c4f1f
CB
403 uint32_t len; /* len of data */
404 uint32_t reloc_table_offset;
f3f0db50 405 uint64_t seqnum;
b6bbed5f 406 char padding[LTTNG_FILTER_PADDING];
53a80697 407 char data[0];
fc5e05b7 408} LTTNG_PACKED;
53a80697 409
579640f9
JI
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
416struct lttng_event_exclusion {
417 uint32_t count;
418 char padding[LTTNG_EVENT_EXCLUSION_PADDING];
caafa356 419 char names[0][LTTNG_SYMBOL_NAME_LEN];
579640f9
JI
420} LTTNG_PACKED;
421
d7af3565
PP
422#define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) \
423 (&(_exclusion)->names[_i][0])
424
b4e3ceb9
PP
425/*
426 * Event command header.
427 */
428struct 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 */
437struct 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;
795d57ce
PP
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;
56f0bc67
JG
451
452 /*
453 * Size of the event's userspace probe location (if applicable).
454 */
455 uint32_t userspace_probe_location_len;
b4e3ceb9
PP
456} LTTNG_PACKED;
457
3e3665b8
JG
458/*
459 * Command header of the reply to an LTTNG_DESTROY_SESSION command.
460 */
461struct lttcomm_session_destroy_command_header {
462 /* enum lttng_session */
463 int32_t rotation_state;
464};
465
55c9e7ca
JR
466/*
467 * tracker command header.
468 */
469struct lttcomm_tracker_command_header {
470 uint32_t nb_tracker_id;
471} LTTNG_PACKED;
472
473struct 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
fac6795d 481/*
5e16da05 482 * Data structure for the response from sessiond to the lttng client.
fac6795d 483 */
5461b305 484struct lttcomm_lttng_msg {
d0b96690
DG
485 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
486 uint32_t ret_code; /* enum lttcomm_return_code */
487 uint32_t pid; /* pid_t */
795a978d 488 uint32_t cmd_header_size;
773168b7 489 uint32_t data_size;
fc5e05b7 490} LTTNG_PACKED;
fac6795d 491
da3c9ec1
DG
492struct lttcomm_lttng_output_id {
493 uint32_t id;
494} LTTNG_PACKED;
495
6e3805e2 496/*
3bd1e081
MD
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.
6e3805e2 500 */
3bd1e081 501struct lttcomm_consumer_msg {
92816cc3 502 uint32_t cmd_type; /* enum lttng_consumer_command */
3bd1e081
MD
503 union {
504 struct {
d88aee68 505 uint64_t channel_key;
ffe60014 506 uint64_t session_id;
d2956687 507 /* ID of the session's current trace chunk. */
0a30bf9b 508 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
ffe60014 509 char pathname[PATH_MAX];
d88aee68 510 uint64_t relayd_id;
c30aaa51 511 /* nb_init_streams is the number of streams open initially. */
d88aee68 512 uint32_t nb_init_streams;
de5e9086 513 char name[LTTNG_SYMBOL_NAME_LEN];
ffe60014
DG
514 /* Use splice or mmap to consume this fd */
515 enum lttng_event_output output;
516 int type; /* Per cpu or metadata. */
1624d5b7
JD
517 uint64_t tracefile_size; /* bytes */
518 uint32_t tracefile_count; /* number of tracefiles */
2bba9e53
DG
519 /* If the channel's streams have to be monitored or not. */
520 uint32_t monitor;
ecc48a90
JD
521 /* timer to check the streams usage in live mode (usec). */
522 unsigned int live_timer_interval;
e9404c27
JG
523 /* timer to sample a channel's positions (usec). */
524 unsigned int monitor_timer_interval;
ffe60014 525 } LTTNG_PACKED channel; /* Only used by Kernel. */
3bd1e081 526 struct {
d88aee68
DG
527 uint64_t stream_key;
528 uint64_t channel_key;
529 int32_t cpu; /* On which CPU this stream is assigned. */
6dc3064a
DG
530 /* Tells the consumer if the stream should be or not monitored. */
531 uint32_t no_monitor;
ffe60014 532 } LTTNG_PACKED stream; /* Only used by Kernel. */
de5e9086 533 struct {
d88aee68 534 uint64_t net_index;
de5e9086
DG
535 enum lttng_stream_type type;
536 /* Open socket to the relayd */
6151a90f 537 struct lttcomm_relayd_sock sock;
46e6455f
DG
538 /* Tracing session id associated to the relayd. */
539 uint64_t session_id;
d3e2ba59
JD
540 /* Relayd session id, only used with control socket. */
541 uint64_t relayd_session_id;
fc5e05b7 542 } LTTNG_PACKED relayd_sock;
173af62f
DG
543 struct {
544 uint64_t net_seq_idx;
fc5e05b7 545 } LTTNG_PACKED destroy_relayd;
53632229
DG
546 struct {
547 uint64_t session_id;
fc5e05b7 548 } LTTNG_PACKED data_pending;
ffe60014 549 struct {
d0b96690
DG
550 uint64_t subbuf_size; /* bytes */
551 uint64_t num_subbuf; /* power of 2 */
d88aee68
DG
552 int32_t overwrite; /* 1: overwrite, 0: discard */
553 uint32_t switch_timer_interval; /* usec */
554 uint32_t read_timer_interval; /* usec */
e9404c27
JG
555 unsigned int live_timer_interval; /* usec */
556 uint32_t monitor_timer_interval; /* usec */
d88aee68
DG
557 int32_t output; /* splice, mmap */
558 int32_t type; /* metadata or per_cpu */
d0b96690
DG
559 uint64_t session_id; /* Tracing session id */
560 char pathname[PATH_MAX]; /* Channel file path. */
ffe60014 561 char name[LTTNG_SYMBOL_NAME_LEN]; /* Channel name. */
d2956687
JG
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;
d88aee68
DG
567 uint64_t relayd_id; /* Relayd id if apply. */
568 uint64_t key; /* Unique channel key. */
d2956687 569 /* ID of the session's current trace chunk. */
0a30bf9b 570 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
c70636a7 571 unsigned char uuid[LTTNG_UUID_LEN]; /* uuid for ust tracer. */
7972aab2 572 uint32_t chan_id; /* Channel ID on the tracer side. */
1624d5b7
JD
573 uint64_t tracefile_size; /* bytes */
574 uint32_t tracefile_count; /* number of tracefiles */
1950109e 575 uint64_t session_id_per_pid; /* Per-pid session ID. */
2bba9e53
DG
576 /* Tells the consumer if the stream should be or not monitored. */
577 uint32_t monitor;
567eb353
DG
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;
491d1539 585 int64_t blocking_timeout;
3d071855 586 char root_shm_path[PATH_MAX];
d7ba1388 587 char shm_path[PATH_MAX];
ffe60014
DG
588 } LTTNG_PACKED ask_channel;
589 struct {
d88aee68 590 uint64_t key;
ffe60014
DG
591 } LTTNG_PACKED get_channel;
592 struct {
d88aee68 593 uint64_t key;
ffe60014 594 } LTTNG_PACKED destroy_channel;
d88aee68
DG
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. */
93ec662e 599 uint64_t version; /* Version of the metadata. */
d88aee68
DG
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;
7972aab2
DG
607 struct {
608 uint64_t key; /* Channel key. */
609 } LTTNG_PACKED flush_channel;
0dd01979
MD
610 struct {
611 uint64_t key; /* Channel key. */
612 } LTTNG_PACKED clear_quiescent_channel;
6dc3064a
DG
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;
d07ceecd 620 uint64_t nb_packets_per_stream;
6dc3064a 621 } LTTNG_PACKED snapshot_channel;
a4baae1b
JD
622 struct {
623 uint64_t channel_key;
624 uint64_t net_seq_idx;
625 } LTTNG_PACKED sent_streams;
fb83fe64
JD
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;
93ec662e
JD
634 struct {
635 uint64_t session_id;
eded6438 636 } LTTNG_PACKED regenerate_metadata;
b99a8d42 637 struct {
b99a8d42
JD
638 uint32_t metadata; /* This is a metadata channel. */
639 uint64_t relayd_id; /* Relayd id if apply. */
640 uint64_t key;
b99a8d42 641 } LTTNG_PACKED rotate_channel;
92816cc3
JG
642 struct {
643 uint64_t session_id;
644 uint64_t chunk_id;
645 } LTTNG_PACKED check_rotation_pending_local;
d88744a4
JD
646 struct {
647 uint64_t relayd_id;
648 uint64_t session_id;
649 uint64_t chunk_id;
92816cc3 650 } LTTNG_PACKED check_rotation_pending_relay;
a1ae2ea5 651 struct {
d2956687
JG
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
913a542b 660 * chunk's name is not overridden.
d2956687 661 */
0a30bf9b 662 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
d2956687
JG
663 char override_name[LTTNG_NAME_MAX];
664 uint64_t session_id;
665 uint64_t chunk_id;
666 uint64_t creation_timestamp;
e5add6d0 667 LTTNG_OPTIONAL_COMM(struct {
d2956687
JG
668 uint32_t uid;
669 uint32_t gid;
e5add6d0 670 } LTTNG_PACKED ) LTTNG_PACKED credentials;
d2956687
JG
671 } LTTNG_PACKED create_trace_chunk;
672 struct {
0a30bf9b 673 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
d2956687
JG
674 uint64_t session_id;
675 uint64_t chunk_id;
676 uint64_t close_timestamp;
bbc4768c
JG
677 /* enum lttng_trace_chunk_command_type */
678 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
d2956687
JG
679 } LTTNG_PACKED close_trace_chunk;
680 struct {
0a30bf9b 681 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
a1ae2ea5 682 uint64_t session_id;
d2956687
JG
683 uint64_t chunk_id;
684 } LTTNG_PACKED trace_chunk_exists;
685 struct {
686 lttng_uuid sessiond_uuid;
687 } LTTNG_PACKED init;
b01b201a
MD
688 struct {
689 uint64_t key;
690 } LTTNG_PACKED clear_channel;
3bd1e081 691 } u;
fc5e05b7 692} LTTNG_PACKED;
6e3805e2 693
e9404c27
JG
694/*
695 * Channel monitoring message returned to the session daemon on every
696 * monitor timer expiration.
697 */
698struct 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;
e8360425
JD
705 /*
706 * Sum of all the consumed positions for a channel.
707 */
708 uint64_t total_consumed;
e9404c27
JG
709} LTTNG_PACKED;
710
f50f23d9
DG
711/*
712 * Status message returned to the sessiond after a received command.
713 */
714struct lttcomm_consumer_status_msg {
0c759fc9 715 enum lttcomm_return_code ret_code;
fc5e05b7 716} LTTNG_PACKED;
f50f23d9 717
ffe60014 718struct lttcomm_consumer_status_channel {
0c759fc9 719 enum lttcomm_return_code ret_code;
d88aee68 720 uint64_t key;
ffe60014
DG
721 unsigned int stream_count;
722} LTTNG_PACKED;
723
ecd1a12f
MD
724struct lttcomm_consumer_close_trace_chunk_reply {
725 enum lttcomm_return_code ret_code;
726 uint32_t path_length;
727 char path[];
728};
729
51791532
JG
730#ifdef HAVE_LIBLTTNG_UST_CTL
731
9df8df5e 732#include <lttng/ust-abi.h>
6e3805e2 733
3817e7df
DG
734/*
735 * Data structure for the commands sent from sessiond to UST.
736 */
737struct lttcomm_ust_msg {
3817e7df
DG
738 uint32_t handle;
739 uint32_t cmd;
740 union {
3817e7df 741 struct lttng_ust_channel channel;
00a17c97 742 struct lttng_ust_stream stream;
3817e7df
DG
743 struct lttng_ust_event event;
744 struct lttng_ust_context context;
00a17c97 745 struct lttng_ust_tracer_version version;
3817e7df 746 } u;
fc5e05b7 747} LTTNG_PACKED;
3817e7df
DG
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 */
753struct 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 {
2b0bf864
DG
759 struct {
760 uint64_t memory_map_size;
fc5e05b7 761 } LTTNG_PACKED channel;
2b0bf864
DG
762 struct {
763 uint64_t memory_map_size;
fc5e05b7 764 } LTTNG_PACKED stream;
00a17c97 765 struct lttng_ust_tracer_version version;
3817e7df 766 } u;
fc5e05b7 767} LTTNG_PACKED;
3817e7df 768
74d0b642 769#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 770
79445cf0 771LTTNG_HIDDEN const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
fac6795d 772
79445cf0 773LTTNG_HIDDEN int lttcomm_init_inet_sockaddr(struct lttcomm_sockaddr *sockaddr,
6364a07a 774 const char *ip, unsigned int port);
79445cf0 775LTTNG_HIDDEN int lttcomm_init_inet6_sockaddr(struct lttcomm_sockaddr *sockaddr,
6364a07a
DG
776 const char *ip, unsigned int port);
777
79445cf0
JG
778LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto);
779LTTNG_HIDDEN int lttcomm_create_sock(struct lttcomm_sock *sock);
780LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_sock_from_uri(struct lttng_uri *uri);
781LTTNG_HIDDEN void lttcomm_destroy_sock(struct lttcomm_sock *sock);
782LTTNG_HIDDEN struct lttcomm_sock *lttcomm_alloc_copy_sock(struct lttcomm_sock *src);
783LTTNG_HIDDEN void lttcomm_copy_sock(struct lttcomm_sock *dst,
de5e9086 784 struct lttcomm_sock *src);
6364a07a 785
6151a90f 786/* Relayd socket object. */
79445cf0 787LTTNG_HIDDEN struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock(
6151a90f
JD
788 struct lttng_uri *uri, uint32_t major, uint32_t minor);
789
79445cf0
JG
790LTTNG_HIDDEN int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
791LTTNG_HIDDEN int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
783a3b9a 792
2288467f
JG
793LTTNG_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 */
799LTTNG_HIDDEN int lttcomm_sock_set_port(struct lttcomm_sock *sock, uint16_t port);
800
79445cf0 801LTTNG_HIDDEN void lttcomm_init(void);
554831e7 802/* Get network timeout, in milliseconds */
79445cf0 803LTTNG_HIDDEN unsigned long lttcomm_get_network_timeout(void);
554831e7 804
773168b7 805#endif /* _LTTNG_SESSIOND_COMM_H */
This page took 0.126529 seconds and 5 git commands to generate.