Fix: sessiond: leak of trigger on registration error
[lttng-tools.git] / src / bin / lttng-sessiond / ust-ctl-internal.h
CommitLineData
75018ab6 1/*
ab5be9fa
MJ
2 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
75018ab6 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
75018ab6 6 *
75018ab6
JG
7 */
8
9#ifndef LTTNG_UST_CTL_INTERNAL_H
10#define LTTNG_UST_CTL_INTERNAL_H
11
12#include <sys/types.h>
13#include <limits.h>
14
15#include "lttng-ust-abi.h"
16
17#ifndef LTTNG_UST_UUID_LEN
18#define LTTNG_UST_UUID_LEN 16
19#endif
20
21/* Default unix socket path */
22#define LTTNG_UST_SOCK_FILENAME \
23 "lttng-ust-sock-" \
24 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
25
26/*
27 * Shared memory files path are automatically related to shm root, e.g.
28 * /dev/shm under linux.
29 */
30#define LTTNG_UST_WAIT_FILENAME \
31 "lttng-ust-wait-" \
32 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
33
34struct lttng_ust_shm_handle;
35struct lttng_ust_lib_ring_buffer;
36
37struct ustctl_consumer_channel_attr {
38 enum lttng_ust_chan_type type;
39 uint64_t subbuf_size; /* bytes */
40 uint64_t num_subbuf; /* power of 2 */
41 int overwrite; /* 1: overwrite, 0: discard */
42 unsigned int switch_timer_interval; /* usec */
43 unsigned int read_timer_interval; /* usec */
44 enum lttng_ust_output output; /* splice, mmap */
45 uint32_t chan_id; /* channel ID */
46 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
47 int64_t blocking_timeout; /* Blocking timeout (usec) */
48} LTTNG_PACKED;
49
50/*
51 * API used by sessiond.
52 */
53
54struct lttng_ust_context_attr {
55 enum lttng_ust_context_type ctx;
56 union {
57 struct lttng_ust_perf_counter_ctx perf_counter;
58 struct {
59 char *provider_name;
60 char *ctx_name;
61 } app_ctx;
62 } u;
63};
64
65/*
66 * Error values: all the following functions return:
67 * >= 0: Success (LTTNG_UST_OK)
68 * < 0: error code.
69 */
70int ustctl_register_done(int sock);
71int ustctl_create_session(int sock);
72int ustctl_create_event(int sock, struct lttng_ust_event *ev,
73 struct lttng_ust_object_data *channel_data,
74 struct lttng_ust_object_data **event_data);
75int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
76 struct lttng_ust_object_data *obj_data,
77 struct lttng_ust_object_data **context_data);
78int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
79 struct lttng_ust_object_data *obj_data);
80int ustctl_set_exclusion(int sock, struct lttng_ust_event_exclusion *exclusion,
81 struct lttng_ust_object_data *obj_data);
82
83int ustctl_enable(int sock, struct lttng_ust_object_data *object);
84int ustctl_disable(int sock, struct lttng_ust_object_data *object);
85int ustctl_start_session(int sock, int handle);
86int ustctl_stop_session(int sock, int handle);
87
233350e5
JR
88int ustctl_create_event_notifier_group(int sock,
89 int pipe_fd,
90 struct lttng_ust_object_data **event_notifier_group_handle);
91int ustctl_create_event_notifier(int sock,
92 struct lttng_ust_event_notifier *event_notifier,
93 struct lttng_ust_object_data *event_notifier_group_handle,
94 struct lttng_ust_object_data **event_notifier_data);
95
75018ab6
JG
96/*
97 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
98 * error value.
99 */
100int ustctl_tracepoint_list(int sock);
101
102/*
103 * ustctl_tracepoint_list_get is used to iterate on the tp list
104 * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
105 * returned.
106 */
107int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
108 struct lttng_ust_tracepoint_iter *iter);
109
110/*
111 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
112 * or negative error value.
113 */
114int ustctl_tracepoint_field_list(int sock);
115
116/*
117 * ustctl_tracepoint_field_list_get is used to iterate on the tp field
118 * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
119 * returned.
120 */
121int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle,
122 struct lttng_ust_field_iter *iter);
123
124int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v);
125int ustctl_wait_quiescent(int sock);
126
127int ustctl_sock_flush_buffer(int sock, struct lttng_ust_object_data *object);
128
129int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate);
130
131/* Release object created by members of this API. */
132int ustctl_release_object(int sock, struct lttng_ust_object_data *data);
133/* Release handle returned by create session. */
134int ustctl_release_handle(int sock, int handle);
135
136int ustctl_recv_channel_from_consumer(int sock,
137 struct lttng_ust_object_data **channel_data);
138int ustctl_recv_stream_from_consumer(int sock,
139 struct lttng_ust_object_data **stream_data);
140int ustctl_send_channel_to_ust(int sock, int session_handle,
141 struct lttng_ust_object_data *channel_data);
142int ustctl_send_stream_to_ust(int sock,
143 struct lttng_ust_object_data *channel_data,
144 struct lttng_ust_object_data *stream_data);
145
146/*
147 * ustctl_duplicate_ust_object_data allocated a new object in "dest" if
148 * it succeeds (returns 0). It must be released using
149 * ustctl_release_object() and then freed with free().
150 */
151int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest,
152 struct lttng_ust_object_data *src);
153
154/*
155 * API used by consumer.
156 */
157
158struct ustctl_consumer_channel;
159struct ustctl_consumer_stream;
160struct ustctl_consumer_channel_attr;
161
162int ustctl_get_nr_stream_per_channel(void);
163
164struct ustctl_consumer_channel *
165 ustctl_create_channel(struct ustctl_consumer_channel_attr *attr,
166 const int *stream_fds, int nr_stream_fds);
167/*
168 * Each stream created needs to be destroyed before calling
169 * ustctl_destroy_channel().
170 */
171void ustctl_destroy_channel(struct ustctl_consumer_channel *chan);
172
173int ustctl_send_channel_to_sessiond(int sock,
174 struct ustctl_consumer_channel *channel);
175int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan);
176int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan);
177int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *consumer_chan);
178int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *consumer_chan);
179
180int ustctl_write_metadata_to_channel(
181 struct ustctl_consumer_channel *channel,
182 const char *metadata_str, /* NOT null-terminated */
183 size_t len); /* metadata length */
184ssize_t ustctl_write_one_packet_to_channel(
185 struct ustctl_consumer_channel *channel,
186 const char *metadata_str, /* NOT null-terminated */
187 size_t len); /* metadata length */
188
189/*
190 * Send a NULL stream to finish iteration over all streams of a given
191 * channel.
192 */
193int ustctl_send_stream_to_sessiond(int sock,
194 struct ustctl_consumer_stream *stream);
195int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream);
196int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream *stream);
197int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream);
198int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream);
199
200/* Create/destroy stream buffers for read */
201struct ustctl_consumer_stream *
202 ustctl_create_stream(struct ustctl_consumer_channel *channel,
203 int cpu);
204void ustctl_destroy_stream(struct ustctl_consumer_stream *stream);
205
206/* For mmap mode, readable without "get" operation */
207int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream,
208 unsigned long *len);
209int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream,
210 unsigned long *len);
211
212/*
213 * For mmap mode, operate on the current packet (between get/put or
214 * get_next/put_next).
215 */
216void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream);
217int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream,
218 unsigned long *off);
219int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream,
220 unsigned long *len);
221int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
222 unsigned long *len);
223int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream);
224int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream);
225
226/* snapshot */
227
228int ustctl_snapshot(struct ustctl_consumer_stream *stream);
229int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream);
230int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
231 unsigned long *pos);
232int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,
233 unsigned long *pos);
234int ustctl_get_subbuf(struct ustctl_consumer_stream *stream,
235 unsigned long *pos);
236int ustctl_put_subbuf(struct ustctl_consumer_stream *stream);
237
238void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
239 int producer_active);
240
241/* index */
242int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
243 uint64_t *timestamp_begin);
244int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
245 uint64_t *timestamp_end);
246int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
247 uint64_t *events_discarded);
248int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
249 uint64_t *content_size);
250int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
251 uint64_t *packet_size);
252int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
253 uint64_t *stream_id);
254int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
255 uint64_t *ts);
256int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
257 uint64_t *seq);
258int ustctl_get_instance_id(struct ustctl_consumer_stream *stream,
259 uint64_t *id);
260
261/* returns whether UST has perf counters support. */
262int ustctl_has_perf_counters(void);
263
264/* Regenerate the statedump. */
265int ustctl_regenerate_statedump(int sock, int handle);
266
267/* event registry management */
268
269enum ustctl_socket_type {
270 USTCTL_SOCKET_CMD = 0,
271 USTCTL_SOCKET_NOTIFY = 1,
272};
273
274enum ustctl_notify_cmd {
275 USTCTL_NOTIFY_CMD_EVENT = 0,
276 USTCTL_NOTIFY_CMD_CHANNEL = 1,
277 USTCTL_NOTIFY_CMD_ENUM = 2,
278};
279
280enum ustctl_channel_header {
281 USTCTL_CHANNEL_HEADER_UNKNOWN = 0,
282 USTCTL_CHANNEL_HEADER_COMPACT = 1,
283 USTCTL_CHANNEL_HEADER_LARGE = 2,
284};
285
286/* event type structures */
287
288enum ustctl_abstract_types {
289 ustctl_atype_integer,
0d32d1a9
MD
290 ustctl_atype_enum, /* legacy */
291 ustctl_atype_array, /* legacy */
292 ustctl_atype_sequence, /* legacy */
75018ab6
JG
293 ustctl_atype_string,
294 ustctl_atype_float,
0d32d1a9
MD
295 ustctl_atype_variant, /* legacy */
296 ustctl_atype_struct, /* legacy */
297 ustctl_atype_enum_nestable,
298 ustctl_atype_array_nestable,
299 ustctl_atype_sequence_nestable,
300 ustctl_atype_struct_nestable,
301 ustctl_atype_variant_nestable,
75018ab6
JG
302 NR_USTCTL_ABSTRACT_TYPES,
303};
304
305enum ustctl_string_encodings {
306 ustctl_encode_none = 0,
307 ustctl_encode_UTF8 = 1,
308 ustctl_encode_ASCII = 2,
309 NR_USTCTL_STRING_ENCODINGS,
310};
311
312#define USTCTL_UST_INTEGER_TYPE_PADDING 24
313struct ustctl_integer_type {
314 uint32_t size; /* in bits */
315 uint32_t signedness;
316 uint32_t reverse_byte_order;
317 uint32_t base; /* 2, 8, 10, 16, for pretty print */
318 int32_t encoding; /* enum ustctl_string_encodings */
319 uint16_t alignment; /* in bits */
320 char padding[USTCTL_UST_INTEGER_TYPE_PADDING];
321} LTTNG_PACKED;
322
323#define USTCTL_UST_FLOAT_TYPE_PADDING 24
324struct ustctl_float_type {
325 uint32_t exp_dig; /* exponent digits, in bits */
326 uint32_t mant_dig; /* mantissa digits, in bits */
327 uint32_t reverse_byte_order;
328 uint16_t alignment; /* in bits */
329 char padding[USTCTL_UST_FLOAT_TYPE_PADDING];
330} LTTNG_PACKED;
331
332#define USTCTL_UST_ENUM_VALUE_PADDING 15
333struct ustctl_enum_value {
334 uint64_t value;
335 uint8_t signedness;
336 char padding[USTCTL_UST_ENUM_VALUE_PADDING];
337} LTTNG_PACKED;
338
339enum ustctl_ust_enum_entry_options {
340 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
341};
342
343#define USTCTL_UST_ENUM_ENTRY_PADDING 32
344struct ustctl_enum_entry {
345 struct ustctl_enum_value start, end; /* start and end are inclusive */
346 char string[LTTNG_UST_SYM_NAME_LEN];
347 union {
348 struct {
349 uint32_t options;
350 } LTTNG_PACKED extra;
351 char padding[USTCTL_UST_ENUM_ENTRY_PADDING];
352 } u;
353} LTTNG_PACKED;
354
0d32d1a9 355/* legacy */
75018ab6
JG
356#define USTCTL_UST_BASIC_TYPE_PADDING 296
357union _ustctl_basic_type {
358 struct ustctl_integer_type integer;
359 struct {
360 char name[LTTNG_UST_SYM_NAME_LEN];
361 struct ustctl_integer_type container_type;
362 uint64_t id; /* enum ID in sessiond. */
363 } enumeration;
364 struct {
365 int32_t encoding; /* enum ustctl_string_encodings */
366 } string;
367 struct ustctl_float_type _float;
368 char padding[USTCTL_UST_BASIC_TYPE_PADDING];
369} LTTNG_PACKED;
370
0d32d1a9 371/* legacy */
75018ab6
JG
372struct ustctl_basic_type {
373 enum ustctl_abstract_types atype;
374 union {
375 union _ustctl_basic_type basic;
376 } u;
377} LTTNG_PACKED;
378
0d32d1a9
MD
379/*
380 * Padding is derived from largest member: u.legacy.sequence which
381 * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING.
382 */
383#define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING)
75018ab6
JG
384struct ustctl_type {
385 enum ustctl_abstract_types atype;
386 union {
0d32d1a9
MD
387 struct ustctl_integer_type integer;
388 struct ustctl_float_type _float;
389 struct {
390 int32_t encoding; /* enum ustctl_string_encodings */
391 } string;
392 struct {
393 char name[LTTNG_UST_SYM_NAME_LEN];
394 uint64_t id; /* enum ID in sessiond. */
395 /* container_type follows after this struct ustctl_field. */
396 } enum_nestable;
75018ab6 397 struct {
75018ab6 398 uint32_t length; /* num. elems. */
0d32d1a9
MD
399 uint32_t alignment;
400 /* elem_type follows after this struct ustctl_field. */
401 } array_nestable;
75018ab6 402 struct {
0d32d1a9
MD
403 char length_name[LTTNG_UST_SYM_NAME_LEN];
404 uint32_t alignment; /* Alignment before elements. */
405 /* elem_type follows after the length_type. */
406 } sequence_nestable;
407 struct {
408 uint32_t nr_fields;
409 uint32_t alignment;
410 /* Followed by nr_fields struct ustctl_field. */
411 } struct_nestable;
75018ab6
JG
412 struct {
413 uint32_t nr_choices;
414 char tag_name[LTTNG_UST_SYM_NAME_LEN];
0d32d1a9 415 uint32_t alignment;
75018ab6 416 /* Followed by nr_choices struct ustctl_field. */
0d32d1a9
MD
417 } variant_nestable;
418
419 /* Legacy ABI */
420 union {
421 union _ustctl_basic_type basic;
422 struct {
423 struct ustctl_basic_type elem_type;
424 uint32_t length; /* num. elems. */
425 } array;
426 struct {
427 struct ustctl_basic_type length_type;
428 struct ustctl_basic_type elem_type;
429 } sequence;
430 struct {
431 uint32_t nr_fields;
432 /* Followed by nr_fields struct ustctl_field. */
433 } _struct;
434 struct {
435 uint32_t nr_choices;
436 char tag_name[LTTNG_UST_SYM_NAME_LEN];
437 /* Followed by nr_choices struct ustctl_field. */
438 } variant;
439 } legacy;
75018ab6
JG
440 char padding[USTCTL_UST_TYPE_PADDING];
441 } u;
442} LTTNG_PACKED;
443
444#define USTCTL_UST_FIELD_PADDING 28
445struct ustctl_field {
446 char name[LTTNG_UST_SYM_NAME_LEN];
447 struct ustctl_type type;
448 char padding[USTCTL_UST_FIELD_PADDING];
449} LTTNG_PACKED;
450
451/*
452 * Returns 0 on success, negative error value on error.
453 * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned,
454 * the output fields are not populated.
455 */
456int ustctl_recv_reg_msg(int sock,
457 enum ustctl_socket_type *type,
458 uint32_t *major,
459 uint32_t *minor,
460 uint32_t *pid,
461 uint32_t *ppid,
462 uint32_t *uid,
463 uint32_t *gid,
464 uint32_t *bits_per_long,
465 uint32_t *uint8_t_alignment,
466 uint32_t *uint16_t_alignment,
467 uint32_t *uint32_t_alignment,
468 uint32_t *uint64_t_alignment,
469 uint32_t *long_alignment,
470 int *byte_order,
471 char *name); /* size LTTNG_UST_ABI_PROCNAME_LEN */
472
473/*
474 * Returns 0 on success, negative UST or system error value on error.
475 * Receive the notification command. The "notify_cmd" can then be used
476 * by the caller to find out which ustctl_recv_* function should be
477 * called to receive the notification, and which ustctl_reply_* is
478 * appropriate.
479 */
480int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd);
481
482/*
483 * Returns 0 on success, negative UST or system error value on error.
484 */
485int ustctl_recv_register_event(int sock,
486 int *session_objd, /* session descriptor (output) */
487 int *channel_objd, /* channel descriptor (output) */
488 char *event_name, /*
489 * event name (output,
490 * size LTTNG_UST_SYM_NAME_LEN)
491 */
492 int *loglevel,
493 char **signature, /*
494 * event signature
495 * (output, dynamically
496 * allocated, must be free(3)'d
497 * by the caller if function
498 * returns success.)
499 */
500 size_t *nr_fields,
501 struct ustctl_field **fields,
502 char **model_emf_uri);
503
504/*
505 * Returns 0 on success, negative error value on error.
506 */
507int ustctl_reply_register_event(int sock,
508 uint32_t id, /* event id (input) */
509 int ret_code); /* return code. 0 ok, negative error */
510
511/*
512 * Returns 0 on success, negative UST or system error value on error.
513 */
514int ustctl_recv_register_enum(int sock,
515 int *session_objd,
516 char *enum_name,
517 struct ustctl_enum_entry **entries,
518 size_t *nr_entries);
519
520/*
521 * Returns 0 on success, negative error value on error.
522 */
523int ustctl_reply_register_enum(int sock,
524 uint64_t id, /* enum id (input) */
525 int ret_code);
526
527/*
528 * Returns 0 on success, negative UST or system error value on error.
529 */
530int ustctl_recv_register_channel(int sock,
531 int *session_objd, /* session descriptor (output) */
532 int *channel_objd, /* channel descriptor (output) */
533 size_t *nr_fields, /* context fields */
534 struct ustctl_field **fields);
535
536/*
537 * Returns 0 on success, negative error value on error.
538 */
539int ustctl_reply_register_channel(int sock,
540 uint32_t chan_id,
541 enum ustctl_channel_header header_type,
542 int ret_code); /* return code. 0 ok, negative error */
543
544#endif /* LTTNG_UST_CTL_INTERNAL_H */
This page took 0.046917 seconds and 4 git commands to generate.