2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Mimic system calls for:
9 * - session creation, returns an object descriptor or failure.
10 * - channel creation, returns an object descriptor or failure.
11 * - Operates on a session object descriptor
12 * - Takes all channel options as parameters.
13 * - stream get, returns an object descriptor or failure.
14 * - Operates on a channel object descriptor.
15 * - stream notifier get, returns an object descriptor or failure.
16 * - Operates on a channel object descriptor.
17 * - event creation, returns an object descriptor or failure.
18 * - Operates on a channel object descriptor
19 * - Takes an event name as parameter
20 * - Takes an instrumentation source as parameter
21 * - e.g. tracepoints, dynamic_probes...
22 * - Takes instrumentation source specific arguments.
30 #include <urcu/compiler.h>
31 #include <urcu/list.h>
34 #include <lttng/tracepoint.h>
35 #include <lttng/ust-abi.h>
36 #include <lttng/ust-error.h>
37 #include <lttng/ust-events.h>
38 #include <lttng/ust-version.h>
40 #include <usterr-signal-safe.h>
42 #include "../libringbuffer/frontend_types.h"
43 #include "../libringbuffer/shm.h"
44 #include "../libcounter/counter.h"
45 #include "tracepoint-internal.h"
46 #include "lttng-tracer.h"
47 #include "string-utils.h"
48 #include "ust-events-internal.h"
50 #define OBJ_NAME_LEN 16
52 static int lttng_ust_abi_close_in_progress
;
55 int lttng_abi_tracepoint_list(void *owner
);
57 int lttng_abi_tracepoint_field_list(void *owner
);
60 * Object descriptor table. Should be protected from concurrent access
64 struct lttng_ust_obj
{
68 const struct lttng_ust_objd_ops
*ops
;
70 int owner_ref
; /* has ref from owner */
72 char name
[OBJ_NAME_LEN
];
74 int freelist_next
; /* offset freelist. end is -1. */
78 struct lttng_ust_objd_table
{
79 struct lttng_ust_obj
*array
;
80 unsigned int len
, allocated_len
;
81 int freelist_head
; /* offset freelist head. end is -1 */
84 static struct lttng_ust_objd_table objd_table
= {
89 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
,
90 void *owner
, const char *name
)
92 struct lttng_ust_obj
*obj
;
94 if (objd_table
.freelist_head
!= -1) {
95 obj
= &objd_table
.array
[objd_table
.freelist_head
];
96 objd_table
.freelist_head
= obj
->u
.freelist_next
;
100 if (objd_table
.len
>= objd_table
.allocated_len
) {
101 unsigned int new_allocated_len
, old_allocated_len
;
102 struct lttng_ust_obj
*new_table
, *old_table
;
104 old_allocated_len
= objd_table
.allocated_len
;
105 old_table
= objd_table
.array
;
106 if (!old_allocated_len
)
107 new_allocated_len
= 1;
109 new_allocated_len
= old_allocated_len
<< 1;
110 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
113 memcpy(new_table
, old_table
,
114 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
116 objd_table
.array
= new_table
;
117 objd_table
.allocated_len
= new_allocated_len
;
119 obj
= &objd_table
.array
[objd_table
.len
];
122 obj
->u
.s
.private_data
= private_data
;
124 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
125 /* count == 2 : allocated + hold ref */
126 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
127 obj
->u
.s
.owner
= owner
;
128 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
129 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
130 return obj
- objd_table
.array
;
134 struct lttng_ust_obj
*_objd_get(int id
)
136 if (id
>= objd_table
.len
)
138 if (!objd_table
.array
[id
].u
.s
.f_count
)
140 return &objd_table
.array
[id
];
144 void *objd_private(int id
)
146 struct lttng_ust_obj
*obj
= _objd_get(id
);
148 return obj
->u
.s
.private_data
;
152 void objd_set_private(int id
, void *private_data
)
154 struct lttng_ust_obj
*obj
= _objd_get(id
);
156 obj
->u
.s
.private_data
= private_data
;
159 const struct lttng_ust_objd_ops
*objd_ops(int id
)
161 struct lttng_ust_obj
*obj
= _objd_get(id
);
169 void objd_free(int id
)
171 struct lttng_ust_obj
*obj
= _objd_get(id
);
174 obj
->u
.freelist_next
= objd_table
.freelist_head
;
175 objd_table
.freelist_head
= obj
- objd_table
.array
;
176 assert(obj
->u
.s
.f_count
== 1);
177 obj
->u
.s
.f_count
= 0; /* deallocated */
181 void objd_ref(int id
)
183 struct lttng_ust_obj
*obj
= _objd_get(id
);
188 int lttng_ust_objd_unref(int id
, int is_owner
)
190 struct lttng_ust_obj
*obj
= _objd_get(id
);
194 if (obj
->u
.s
.f_count
== 1) {
195 ERR("Reference counting error\n");
199 if (!obj
->u
.s
.owner_ref
) {
200 ERR("Error decrementing owner reference");
203 obj
->u
.s
.owner_ref
--;
205 if ((--obj
->u
.s
.f_count
) == 1) {
206 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
216 void objd_table_destroy(void)
220 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
221 struct lttng_ust_obj
*obj
;
226 if (!obj
->u
.s
.owner_ref
)
227 continue; /* only unref owner ref. */
228 (void) lttng_ust_objd_unref(i
, 1);
230 free(objd_table
.array
);
231 objd_table
.array
= NULL
;
233 objd_table
.allocated_len
= 0;
234 objd_table
.freelist_head
= -1;
237 const char *lttng_ust_obj_get_name(int id
)
239 struct lttng_ust_obj
*obj
= _objd_get(id
);
243 return obj
->u
.s
.name
;
246 void lttng_ust_objd_table_owner_cleanup(void *owner
)
250 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
251 struct lttng_ust_obj
*obj
;
257 continue; /* skip root handles */
258 if (!obj
->u
.s
.owner_ref
)
259 continue; /* only unref owner ref. */
260 if (obj
->u
.s
.owner
== owner
)
261 (void) lttng_ust_objd_unref(i
, 1);
266 * This is LTTng's own personal way to create an ABI for sessiond.
267 * We send commands over a socket.
270 static const struct lttng_ust_objd_ops lttng_ops
;
271 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
;
272 static const struct lttng_ust_objd_ops lttng_session_ops
;
273 static const struct lttng_ust_objd_ops lttng_channel_ops
;
274 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
;
275 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
;
276 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
277 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
279 int lttng_abi_create_root_handle(void)
283 /* root handles have NULL owners */
284 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
289 int lttng_is_channel_ready(struct lttng_channel
*lttng_chan
)
291 struct channel
*chan
;
292 unsigned int nr_streams
, exp_streams
;
294 chan
= lttng_chan
->chan
;
295 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->handle
);
296 exp_streams
= chan
->nr_streams
;
297 return nr_streams
== exp_streams
;
301 int lttng_abi_create_session(void *owner
)
303 struct lttng_session
*session
;
304 int session_objd
, ret
;
306 session
= lttng_session_create();
309 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
310 if (session_objd
< 0) {
314 session
->objd
= session_objd
;
315 session
->owner
= owner
;
319 lttng_session_destroy(session
);
324 long lttng_abi_tracer_version(int objd
,
325 struct lttng_ust_tracer_version
*v
)
327 v
->major
= LTTNG_UST_MAJOR_VERSION
;
328 v
->minor
= LTTNG_UST_MINOR_VERSION
;
329 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
334 int lttng_abi_event_notifier_send_fd(void *owner
, int *event_notifier_notif_fd
)
336 struct lttng_event_notifier_group
*event_notifier_group
;
337 int event_notifier_group_objd
, ret
, fd_flag
;
339 event_notifier_group
= lttng_event_notifier_group_create();
340 if (!event_notifier_group
)
344 * Set this file descriptor as NON-BLOCKING.
346 fd_flag
= fcntl(*event_notifier_notif_fd
, F_GETFL
);
348 fd_flag
|= O_NONBLOCK
;
350 ret
= fcntl(*event_notifier_notif_fd
, F_SETFL
, fd_flag
);
356 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
357 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
358 if (event_notifier_group_objd
< 0) {
359 ret
= event_notifier_group_objd
;
363 event_notifier_group
->objd
= event_notifier_group_objd
;
364 event_notifier_group
->owner
= owner
;
365 event_notifier_group
->notification_fd
= *event_notifier_notif_fd
;
366 /* Object descriptor takes ownership of notification fd. */
367 *event_notifier_notif_fd
= -1;
369 return event_notifier_group_objd
;
372 lttng_event_notifier_group_destroy(event_notifier_group
);
378 long lttng_abi_add_context(int objd
,
379 struct lttng_ust_context
*context_param
,
380 union ust_args
*uargs
,
381 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
383 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
387 * lttng_cmd - lttng control through socket commands
389 * @objd: the object descriptor
392 * @uargs: UST arguments (internal)
395 * This descriptor implements lttng commands:
397 * Returns a LTTng trace session object descriptor
398 * LTTNG_UST_TRACER_VERSION
399 * Returns the LTTng kernel tracer version
400 * LTTNG_UST_TRACEPOINT_LIST
401 * Returns a file descriptor listing available tracepoints
402 * LTTNG_UST_TRACEPOINT_FIELD_LIST
403 * Returns a file descriptor listing available tracepoint fields
404 * LTTNG_UST_WAIT_QUIESCENT
405 * Returns after all previously running probes have completed
407 * The returned session will be deleted when its file descriptor is closed.
410 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
411 union ust_args
*uargs
, void *owner
)
414 case LTTNG_UST_SESSION
:
415 return lttng_abi_create_session(owner
);
416 case LTTNG_UST_TRACER_VERSION
:
417 return lttng_abi_tracer_version(objd
,
418 (struct lttng_ust_tracer_version
*) arg
);
419 case LTTNG_UST_TRACEPOINT_LIST
:
420 return lttng_abi_tracepoint_list(owner
);
421 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
422 return lttng_abi_tracepoint_field_list(owner
);
423 case LTTNG_UST_WAIT_QUIESCENT
:
424 lttng_ust_synchronize_trace();
426 case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE
:
427 return lttng_abi_event_notifier_send_fd(owner
,
428 &uargs
->event_notifier_handle
.event_notifier_notif_fd
);
434 static const struct lttng_ust_objd_ops lttng_ops
= {
439 int lttng_abi_map_channel(int session_objd
,
440 struct lttng_ust_channel
*ust_chan
,
441 union ust_args
*uargs
,
444 struct lttng_session
*session
= objd_private(session_objd
);
445 const char *transport_name
;
446 const struct lttng_transport
*transport
;
447 const char *chan_name
;
449 struct lttng_ust_shm_handle
*channel_handle
;
450 struct lttng_channel
*lttng_chan
;
451 struct channel
*chan
;
452 struct lttng_ust_lib_ring_buffer_config
*config
;
457 enum lttng_ust_chan_type type
;
459 chan_data
= uargs
->channel
.chan_data
;
460 wakeup_fd
= uargs
->channel
.wakeup_fd
;
462 type
= ust_chan
->type
;
465 case LTTNG_UST_CHAN_PER_CPU
:
472 if (session
->been_active
) {
474 goto active
; /* Refuse to add channel to active session */
477 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
478 if (!channel_handle
) {
483 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
484 uargs
->channel
.chan_data
= NULL
;
485 uargs
->channel
.wakeup_fd
= -1;
487 chan
= shmp(channel_handle
, channel_handle
->chan
);
489 chan
->handle
= channel_handle
;
490 config
= &chan
->backend
.config
;
491 lttng_chan
= channel_get_private(chan
);
497 /* Lookup transport name */
499 case LTTNG_UST_CHAN_PER_CPU
:
500 if (config
->output
== RING_BUFFER_MMAP
) {
501 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
502 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
503 transport_name
= "relay-overwrite-mmap";
505 transport_name
= "relay-overwrite-rt-mmap";
508 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
509 transport_name
= "relay-discard-mmap";
511 transport_name
= "relay-discard-rt-mmap";
518 chan_name
= "channel";
524 transport
= lttng_transport_find(transport_name
);
526 DBG("LTTng transport %s not found\n",
532 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
538 /* Initialize our lttng chan */
539 lttng_chan
->chan
= chan
;
540 lttng_chan
->tstate
= 1;
541 lttng_chan
->enabled
= 1;
542 lttng_chan
->ctx
= NULL
;
543 lttng_chan
->session
= session
;
544 lttng_chan
->ops
= &transport
->ops
;
545 memcpy(<tng_chan
->chan
->backend
.config
,
546 transport
->client_config
,
547 sizeof(lttng_chan
->chan
->backend
.config
));
548 cds_list_add(<tng_chan
->node
, &session
->chan_head
);
549 lttng_chan
->header_type
= 0;
550 lttng_chan
->handle
= channel_handle
;
551 lttng_chan
->type
= type
;
554 * We tolerate no failure path after channel creation. It will stay
555 * invariant for the rest of the session.
557 objd_set_private(chan_objd
, lttng_chan
);
558 lttng_chan
->objd
= chan_objd
;
559 /* The channel created holds a reference on the session */
560 objd_ref(session_objd
);
563 /* error path after channel was created */
567 channel_destroy(chan
, channel_handle
, 0);
577 * lttng_session_cmd - lttng session object command
582 * @uargs: UST arguments (internal)
585 * This descriptor implements lttng commands:
587 * Returns a LTTng channel object descriptor
589 * Enables tracing for a session (weak enable)
591 * Disables tracing for a session (strong disable)
593 * The returned channel will be deleted when its file descriptor is closed.
596 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
597 union ust_args
*uargs
, void *owner
)
599 struct lttng_session
*session
= objd_private(objd
);
602 case LTTNG_UST_CHANNEL
:
603 return lttng_abi_map_channel(objd
,
604 (struct lttng_ust_channel
*) arg
,
606 case LTTNG_UST_SESSION_START
:
607 case LTTNG_UST_ENABLE
:
608 return lttng_session_enable(session
);
609 case LTTNG_UST_SESSION_STOP
:
610 case LTTNG_UST_DISABLE
:
611 return lttng_session_disable(session
);
612 case LTTNG_UST_SESSION_STATEDUMP
:
613 return lttng_session_statedump(session
);
614 case LTTNG_UST_COUNTER
:
615 case LTTNG_UST_COUNTER_GLOBAL
:
616 case LTTNG_UST_COUNTER_CPU
:
617 /* Not implemented yet. */
625 * Called when the last file reference is dropped.
627 * Big fat note: channels and events are invariant for the whole session after
628 * their creation. So this session destruction also destroys all channel and
629 * event structures specific to this session (they are not destroyed when their
630 * individual file is released).
633 int lttng_release_session(int objd
)
635 struct lttng_session
*session
= objd_private(objd
);
638 lttng_session_destroy(session
);
645 static const struct lttng_ust_objd_ops lttng_session_ops
= {
646 .release
= lttng_release_session
,
647 .cmd
= lttng_session_cmd
,
650 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
651 void *owner
, struct lttng_ust_event_notifier
*event_notifier_param
,
652 enum lttng_enabler_format_type type
)
654 struct lttng_event_notifier_group
*event_notifier_group
=
655 objd_private(event_notifier_group_obj
);
656 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
657 int event_notifier_objd
, ret
;
659 event_notifier_param
->event
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
660 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
661 "event_notifier enabler");
662 if (event_notifier_objd
< 0) {
663 ret
= event_notifier_objd
;
667 event_notifier_enabler
= lttng_event_notifier_enabler_create(
668 event_notifier_group
, type
, event_notifier_param
);
669 if (!event_notifier_enabler
) {
671 goto event_notifier_error
;
674 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
675 /* The event_notifier holds a reference on the event_notifier group. */
676 objd_ref(event_notifier_enabler
->group
->objd
);
678 return event_notifier_objd
;
680 event_notifier_error
:
684 err
= lttng_ust_objd_unref(event_notifier_objd
, 1);
692 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
693 union ust_args
*uargs
, void *owner
)
695 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
697 case LTTNG_UST_FILTER
:
698 return lttng_event_notifier_enabler_attach_filter_bytecode(
699 event_notifier_enabler
,
700 (struct lttng_ust_bytecode_node
**) arg
);
701 case LTTNG_UST_EXCLUSION
:
702 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
703 (struct lttng_ust_excluder_node
**) arg
);
704 case LTTNG_UST_CAPTURE
:
705 return lttng_event_notifier_enabler_attach_capture_bytecode(
706 event_notifier_enabler
,
707 (struct lttng_ust_bytecode_node
**) arg
);
708 case LTTNG_UST_ENABLE
:
709 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
710 case LTTNG_UST_DISABLE
:
711 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
718 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
723 * @uargs: UST arguments (internal)
726 * This descriptor implements lttng commands:
727 * LTTNG_UST_COUNTER_GLOBAL
728 * Return negative error code on error, 0 on success.
729 * LTTNG_UST_COUNTER_CPU
730 * Return negative error code on error, 0 on success.
733 long lttng_event_notifier_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
734 union ust_args
*uargs
, void *owner
)
737 struct lttng_counter
*counter
= objd_private(objd
);
740 case LTTNG_UST_COUNTER_GLOBAL
:
741 ret
= -EINVAL
; /* Unimplemented. */
743 case LTTNG_UST_COUNTER_CPU
:
745 struct lttng_ust_counter_cpu
*counter_cpu
=
746 (struct lttng_ust_counter_cpu
*)arg
;
748 ret
= lttng_counter_set_cpu_shm(counter
->counter
,
749 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
751 /* Take ownership of the shm_fd. */
752 uargs
->counter_shm
.shm_fd
= -1;
765 int lttng_release_event_notifier_group_error_counter(int objd
)
767 struct lttng_counter
*counter
= objd_private(objd
);
770 return lttng_ust_objd_unref(counter
->event_notifier_group
->objd
, 0);
776 static const struct lttng_ust_objd_ops lttng_event_notifier_group_error_counter_ops
= {
777 .release
= lttng_release_event_notifier_group_error_counter
,
778 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
782 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
783 struct lttng_ust_counter_conf
*error_counter_conf
)
785 const char *counter_transport_name
;
786 struct lttng_event_notifier_group
*event_notifier_group
=
787 objd_private(event_notifier_group_objd
);
788 struct lttng_counter
*counter
;
789 int counter_objd
, ret
;
790 struct lttng_counter_dimension dimensions
[1];
793 if (event_notifier_group
->error_counter
)
796 if (error_counter_conf
->arithmetic
!= LTTNG_UST_COUNTER_ARITHMETIC_MODULAR
)
799 if (error_counter_conf
->number_dimensions
!= 1)
802 switch (error_counter_conf
->bitness
) {
803 case LTTNG_UST_COUNTER_BITNESS_64
:
804 counter_transport_name
= "counter-per-cpu-64-modular";
806 case LTTNG_UST_COUNTER_BITNESS_32
:
807 counter_transport_name
= "counter-per-cpu-32-modular";
813 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
814 "event_notifier group error counter");
815 if (counter_objd
< 0) {
820 counter_len
= error_counter_conf
->dimensions
[0].size
;
821 dimensions
[0].size
= counter_len
;
822 dimensions
[0].underflow_index
= 0;
823 dimensions
[0].overflow_index
= 0;
824 dimensions
[0].has_underflow
= 0;
825 dimensions
[0].has_overflow
= 0;
827 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
833 event_notifier_group
->error_counter_len
= counter_len
;
835 * store-release to publish error counter matches load-acquire
836 * in record_error. Ensures the counter is created and the
837 * error_counter_len is set before they are used.
838 * Currently a full memory barrier is used, which could be
839 * turned into acquire-release barriers.
842 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
844 counter
->objd
= counter_objd
;
845 counter
->event_notifier_group
= event_notifier_group
; /* owner */
847 objd_set_private(counter_objd
, counter
);
848 /* The error counter holds a reference on the event_notifier group. */
849 objd_ref(event_notifier_group
->objd
);
857 err
= lttng_ust_objd_unref(counter_objd
, 1);
865 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
866 union ust_args
*uargs
, void *owner
)
869 case LTTNG_UST_EVENT_NOTIFIER_CREATE
:
871 struct lttng_ust_event_notifier
*event_notifier_param
=
872 (struct lttng_ust_event_notifier
*) arg
;
873 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
875 * If the event name is a star globbing pattern,
876 * we create the special star globbing enabler.
878 return lttng_ust_event_notifier_enabler_create(objd
,
879 owner
, event_notifier_param
,
880 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
882 return lttng_ust_event_notifier_enabler_create(objd
,
883 owner
, event_notifier_param
,
884 LTTNG_ENABLER_FORMAT_EVENT
);
887 case LTTNG_UST_COUNTER
:
889 struct lttng_ust_counter_conf
*counter_conf
=
890 (struct lttng_ust_counter_conf
*) uargs
->counter
.counter_data
;
891 return lttng_ust_event_notifier_group_create_error_counter(
892 objd
, owner
, counter_conf
);
900 int lttng_event_notifier_enabler_release(int objd
)
902 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
904 if (event_notifier_enabler
)
905 return lttng_ust_objd_unref(event_notifier_enabler
->group
->objd
, 0);
909 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
= {
910 .release
= lttng_event_notifier_enabler_release
,
911 .cmd
= lttng_event_notifier_enabler_cmd
,
915 int lttng_release_event_notifier_group(int objd
)
917 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
919 if (event_notifier_group
) {
920 lttng_event_notifier_group_destroy(event_notifier_group
);
927 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
= {
928 .release
= lttng_release_event_notifier_group
,
929 .cmd
= lttng_event_notifier_group_cmd
,
933 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
934 union ust_args
*uargs
, void *owner
)
936 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
937 struct lttng_ust_tracepoint_iter
*tp
=
938 (struct lttng_ust_tracepoint_iter
*) arg
;
939 struct lttng_ust_tracepoint_iter
*iter
;
942 case LTTNG_UST_TRACEPOINT_LIST_GET
:
944 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
946 return -LTTNG_UST_ERR_NOENT
;
947 memcpy(tp
, iter
, sizeof(*tp
));
956 int lttng_abi_tracepoint_list(void *owner
)
959 struct lttng_ust_tracepoint_list
*list
;
961 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
966 list
= zmalloc(sizeof(*list
));
971 objd_set_private(list_objd
, list
);
973 /* populate list by walking on all registered probes. */
974 ret
= lttng_probes_get_event_list(list
);
986 err
= lttng_ust_objd_unref(list_objd
, 1);
994 int lttng_release_tracepoint_list(int objd
)
996 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
999 lttng_probes_prune_event_list(list
);
1007 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
1008 .release
= lttng_release_tracepoint_list
,
1009 .cmd
= lttng_tracepoint_list_cmd
,
1013 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1014 unsigned long arg
, union ust_args
*uargs
, void *owner
)
1016 struct lttng_ust_field_list
*list
= objd_private(objd
);
1017 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
1018 struct lttng_ust_field_iter
*iter
;
1021 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
1023 iter
= lttng_ust_field_list_get_iter_next(list
);
1025 return -LTTNG_UST_ERR_NOENT
;
1026 memcpy(tp
, iter
, sizeof(*tp
));
1035 int lttng_abi_tracepoint_field_list(void *owner
)
1038 struct lttng_ust_field_list
*list
;
1040 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1042 if (list_objd
< 0) {
1046 list
= zmalloc(sizeof(*list
));
1051 objd_set_private(list_objd
, list
);
1053 /* populate list by walking on all registered probes. */
1054 ret
= lttng_probes_get_field_list(list
);
1066 err
= lttng_ust_objd_unref(list_objd
, 1);
1074 int lttng_release_tracepoint_field_list(int objd
)
1076 struct lttng_ust_field_list
*list
= objd_private(objd
);
1079 lttng_probes_prune_field_list(list
);
1087 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
1088 .release
= lttng_release_tracepoint_field_list
,
1089 .cmd
= lttng_tracepoint_field_list_cmd
,
1093 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
1094 union ust_args
*uargs
, void *owner
)
1096 struct lttng_channel
*channel
= objd_private(channel_objd
);
1099 ret
= channel_handle_add_stream(channel
->handle
,
1100 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1101 info
->stream_nr
, info
->len
);
1103 goto error_add_stream
;
1104 /* Take ownership of shm_fd and wakeup_fd. */
1105 uargs
->stream
.shm_fd
= -1;
1106 uargs
->stream
.wakeup_fd
= -1;
1115 int lttng_abi_create_event_enabler(int channel_objd
,
1116 struct lttng_ust_event
*event_param
,
1118 enum lttng_enabler_format_type format_type
)
1120 struct lttng_channel
*channel
= objd_private(channel_objd
);
1121 struct lttng_event_enabler
*enabler
;
1122 int event_objd
, ret
;
1124 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1125 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1127 if (event_objd
< 0) {
1132 * We tolerate no failure path after event creation. It will stay
1133 * invariant for the rest of the session.
1135 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1140 objd_set_private(event_objd
, enabler
);
1141 /* The event holds a reference on the channel */
1142 objd_ref(channel_objd
);
1149 err
= lttng_ust_objd_unref(event_objd
, 1);
1157 * lttng_channel_cmd - lttng control through object descriptors
1159 * @objd: the object descriptor
1162 * @uargs: UST arguments (internal)
1163 * @owner: objd owner
1165 * This object descriptor implements lttng commands:
1167 * Returns an event stream object descriptor or failure.
1168 * (typically, one event stream records events from one CPU)
1170 * Returns an event object descriptor or failure.
1172 * Prepend a context field to each event in the channel
1174 * Enable recording for events in this channel (weak enable)
1176 * Disable recording for events in this channel (strong disable)
1178 * Channel and event file descriptors also hold a reference on the session.
1181 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1182 union ust_args
*uargs
, void *owner
)
1184 struct lttng_channel
*channel
= objd_private(objd
);
1186 if (cmd
!= LTTNG_UST_STREAM
) {
1188 * Check if channel received all streams.
1190 if (!lttng_is_channel_ready(channel
))
1195 case LTTNG_UST_STREAM
:
1197 struct lttng_ust_stream
*stream
;
1199 stream
= (struct lttng_ust_stream
*) arg
;
1200 /* stream used as output */
1201 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1203 case LTTNG_UST_EVENT
:
1205 struct lttng_ust_event
*event_param
=
1206 (struct lttng_ust_event
*) arg
;
1208 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1210 * If the event name is a star globbing pattern,
1211 * we create the special star globbing enabler.
1213 return lttng_abi_create_event_enabler(objd
, event_param
,
1214 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1216 return lttng_abi_create_event_enabler(objd
, event_param
,
1217 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1220 case LTTNG_UST_CONTEXT
:
1221 return lttng_abi_add_context(objd
,
1222 (struct lttng_ust_context
*) arg
, uargs
,
1223 &channel
->ctx
, channel
->session
);
1224 case LTTNG_UST_ENABLE
:
1225 return lttng_channel_enable(channel
);
1226 case LTTNG_UST_DISABLE
:
1227 return lttng_channel_disable(channel
);
1228 case LTTNG_UST_FLUSH_BUFFER
:
1229 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1236 int lttng_channel_release(int objd
)
1238 struct lttng_channel
*channel
= objd_private(objd
);
1241 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1245 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1246 .release
= lttng_channel_release
,
1247 .cmd
= lttng_channel_cmd
,
1251 * lttng_enabler_cmd - lttng control through object descriptors
1253 * @objd: the object descriptor
1256 * @uargs: UST arguments (internal)
1257 * @owner: objd owner
1259 * This object descriptor implements lttng commands:
1261 * Prepend a context field to each record of events of this
1264 * Enable recording for this enabler
1266 * Disable recording for this enabler
1268 * Attach a filter to an enabler.
1269 * LTTNG_UST_EXCLUSION
1270 * Attach exclusions to an enabler.
1273 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1274 union ust_args
*uargs
, void *owner
)
1276 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1279 case LTTNG_UST_CONTEXT
:
1280 return lttng_event_enabler_attach_context(enabler
,
1281 (struct lttng_ust_context
*) arg
);
1282 case LTTNG_UST_ENABLE
:
1283 return lttng_event_enabler_enable(enabler
);
1284 case LTTNG_UST_DISABLE
:
1285 return lttng_event_enabler_disable(enabler
);
1286 case LTTNG_UST_FILTER
:
1290 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1291 (struct lttng_ust_bytecode_node
**) arg
);
1296 case LTTNG_UST_EXCLUSION
:
1298 return lttng_event_enabler_attach_exclusion(enabler
,
1299 (struct lttng_ust_excluder_node
**) arg
);
1307 int lttng_event_enabler_release(int objd
)
1309 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1312 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1317 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1318 .release
= lttng_event_enabler_release
,
1319 .cmd
= lttng_event_enabler_cmd
,
1322 void lttng_ust_abi_exit(void)
1324 lttng_ust_abi_close_in_progress
= 1;
1326 objd_table_destroy();
1328 lttng_ust_abi_close_in_progress
= 0;