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>
33 #include <lttng/tracepoint.h>
34 #include <lttng/ust-abi.h>
35 #include <lttng/ust-error.h>
36 #include <lttng/ust-events.h>
37 #include <lttng/ust-version.h>
39 #include <usterr-signal-safe.h>
41 #include "../libringbuffer/frontend_types.h"
42 #include "../libringbuffer/shm.h"
43 #include "../libcounter/counter.h"
44 #include "tracepoint-internal.h"
45 #include "lttng-tracer.h"
46 #include "string-utils.h"
47 #include "ust-events-internal.h"
48 #include "context-internal.h"
49 #include "ust-helper.h"
51 #define OBJ_NAME_LEN 16
53 static int lttng_ust_abi_close_in_progress
;
56 int lttng_abi_tracepoint_list(void *owner
);
58 int lttng_abi_tracepoint_field_list(void *owner
);
61 * Object descriptor table. Should be protected from concurrent access
65 struct lttng_ust_abi_obj
{
69 const struct lttng_ust_abi_objd_ops
*ops
;
71 int owner_ref
; /* has ref from owner */
73 char name
[OBJ_NAME_LEN
];
75 int freelist_next
; /* offset freelist. end is -1. */
79 struct lttng_ust_abi_objd_table
{
80 struct lttng_ust_abi_obj
*array
;
81 unsigned int len
, allocated_len
;
82 int freelist_head
; /* offset freelist head. end is -1 */
85 static struct lttng_ust_abi_objd_table objd_table
= {
90 int objd_alloc(void *private_data
, const struct lttng_ust_abi_objd_ops
*ops
,
91 void *owner
, const char *name
)
93 struct lttng_ust_abi_obj
*obj
;
95 if (objd_table
.freelist_head
!= -1) {
96 obj
= &objd_table
.array
[objd_table
.freelist_head
];
97 objd_table
.freelist_head
= obj
->u
.freelist_next
;
101 if (objd_table
.len
>= objd_table
.allocated_len
) {
102 unsigned int new_allocated_len
, old_allocated_len
;
103 struct lttng_ust_abi_obj
*new_table
, *old_table
;
105 old_allocated_len
= objd_table
.allocated_len
;
106 old_table
= objd_table
.array
;
107 if (!old_allocated_len
)
108 new_allocated_len
= 1;
110 new_allocated_len
= old_allocated_len
<< 1;
111 new_table
= zmalloc(sizeof(struct lttng_ust_abi_obj
) * new_allocated_len
);
114 memcpy(new_table
, old_table
,
115 sizeof(struct lttng_ust_abi_obj
) * old_allocated_len
);
117 objd_table
.array
= new_table
;
118 objd_table
.allocated_len
= new_allocated_len
;
120 obj
= &objd_table
.array
[objd_table
.len
];
123 obj
->u
.s
.private_data
= private_data
;
125 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
126 /* count == 2 : allocated + hold ref */
127 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
128 obj
->u
.s
.owner
= owner
;
129 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
130 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
131 return obj
- objd_table
.array
;
135 struct lttng_ust_abi_obj
*_objd_get(int id
)
137 if (id
>= objd_table
.len
)
139 if (!objd_table
.array
[id
].u
.s
.f_count
)
141 return &objd_table
.array
[id
];
145 void *objd_private(int id
)
147 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
149 return obj
->u
.s
.private_data
;
153 void objd_set_private(int id
, void *private_data
)
155 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
157 obj
->u
.s
.private_data
= private_data
;
160 const struct lttng_ust_abi_objd_ops
*lttng_ust_abi_objd_ops(int id
)
162 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
170 void objd_free(int id
)
172 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
175 obj
->u
.freelist_next
= objd_table
.freelist_head
;
176 objd_table
.freelist_head
= obj
- objd_table
.array
;
177 assert(obj
->u
.s
.f_count
== 1);
178 obj
->u
.s
.f_count
= 0; /* deallocated */
182 void objd_ref(int id
)
184 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
189 int lttng_ust_abi_objd_unref(int id
, int is_owner
)
191 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
195 if (obj
->u
.s
.f_count
== 1) {
196 ERR("Reference counting error\n");
200 if (!obj
->u
.s
.owner_ref
) {
201 ERR("Error decrementing owner reference");
204 obj
->u
.s
.owner_ref
--;
206 if ((--obj
->u
.s
.f_count
) == 1) {
207 const struct lttng_ust_abi_objd_ops
*ops
= lttng_ust_abi_objd_ops(id
);
217 void objd_table_destroy(void)
221 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
222 struct lttng_ust_abi_obj
*obj
;
227 if (!obj
->u
.s
.owner_ref
)
228 continue; /* only unref owner ref. */
229 (void) lttng_ust_abi_objd_unref(i
, 1);
231 free(objd_table
.array
);
232 objd_table
.array
= NULL
;
234 objd_table
.allocated_len
= 0;
235 objd_table
.freelist_head
= -1;
238 const char *lttng_ust_obj_get_name(int id
)
240 struct lttng_ust_abi_obj
*obj
= _objd_get(id
);
244 return obj
->u
.s
.name
;
247 void lttng_ust_abi_objd_table_owner_cleanup(void *owner
)
251 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
252 struct lttng_ust_abi_obj
*obj
;
258 continue; /* skip root handles */
259 if (!obj
->u
.s
.owner_ref
)
260 continue; /* only unref owner ref. */
261 if (obj
->u
.s
.owner
== owner
)
262 (void) lttng_ust_abi_objd_unref(i
, 1);
267 * This is LTTng's own personal way to create an ABI for sessiond.
268 * We send commands over a socket.
271 static const struct lttng_ust_abi_objd_ops lttng_ops
;
272 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
;
273 static const struct lttng_ust_abi_objd_ops lttng_session_ops
;
274 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
;
275 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
;
276 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
;
277 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
;
278 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
;
280 int lttng_abi_create_root_handle(void)
284 /* root handles have NULL owners */
285 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
290 int lttng_is_channel_ready(struct lttng_channel
*lttng_chan
)
292 struct lttng_ust_lib_ring_buffer_channel
*chan
;
293 unsigned int nr_streams
, exp_streams
;
295 chan
= lttng_chan
->chan
;
296 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->handle
);
297 exp_streams
= chan
->nr_streams
;
298 return nr_streams
== exp_streams
;
302 int lttng_abi_create_session(void *owner
)
304 struct lttng_session
*session
;
305 int session_objd
, ret
;
307 session
= lttng_session_create();
310 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
311 if (session_objd
< 0) {
315 session
->priv
->objd
= session_objd
;
316 session
->priv
->owner
= owner
;
320 lttng_session_destroy(session
);
325 long lttng_abi_tracer_version(int objd
,
326 struct lttng_ust_abi_tracer_version
*v
)
328 v
->major
= LTTNG_UST_MAJOR_VERSION
;
329 v
->minor
= LTTNG_UST_MINOR_VERSION
;
330 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
335 int lttng_abi_event_notifier_send_fd(void *owner
, int *event_notifier_notif_fd
)
337 struct lttng_event_notifier_group
*event_notifier_group
;
338 int event_notifier_group_objd
, ret
, fd_flag
;
340 event_notifier_group
= lttng_event_notifier_group_create();
341 if (!event_notifier_group
)
345 * Set this file descriptor as NON-BLOCKING.
347 fd_flag
= fcntl(*event_notifier_notif_fd
, F_GETFL
);
349 fd_flag
|= O_NONBLOCK
;
351 ret
= fcntl(*event_notifier_notif_fd
, F_SETFL
, fd_flag
);
357 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
358 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
359 if (event_notifier_group_objd
< 0) {
360 ret
= event_notifier_group_objd
;
364 event_notifier_group
->objd
= event_notifier_group_objd
;
365 event_notifier_group
->owner
= owner
;
366 event_notifier_group
->notification_fd
= *event_notifier_notif_fd
;
367 /* Object descriptor takes ownership of notification fd. */
368 *event_notifier_notif_fd
= -1;
370 return event_notifier_group_objd
;
373 lttng_event_notifier_group_destroy(event_notifier_group
);
379 long lttng_abi_add_context(int objd
,
380 struct lttng_ust_abi_context
*context_param
,
381 union lttng_ust_abi_args
*uargs
,
382 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
384 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
388 * lttng_cmd - lttng control through socket commands
390 * @objd: the object descriptor
393 * @uargs: UST arguments (internal)
396 * This descriptor implements lttng commands:
397 * LTTNG_UST_ABI_SESSION
398 * Returns a LTTng trace session object descriptor
399 * LTTNG_UST_ABI_TRACER_VERSION
400 * Returns the LTTng kernel tracer version
401 * LTTNG_UST_ABI_TRACEPOINT_LIST
402 * Returns a file descriptor listing available tracepoints
403 * LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
404 * Returns a file descriptor listing available tracepoint fields
405 * LTTNG_UST_ABI_WAIT_QUIESCENT
406 * Returns after all previously running probes have completed
408 * The returned session will be deleted when its file descriptor is closed.
411 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
412 union lttng_ust_abi_args
*uargs
, void *owner
)
415 case LTTNG_UST_ABI_SESSION
:
416 return lttng_abi_create_session(owner
);
417 case LTTNG_UST_ABI_TRACER_VERSION
:
418 return lttng_abi_tracer_version(objd
,
419 (struct lttng_ust_abi_tracer_version
*) arg
);
420 case LTTNG_UST_ABI_TRACEPOINT_LIST
:
421 return lttng_abi_tracepoint_list(owner
);
422 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST
:
423 return lttng_abi_tracepoint_field_list(owner
);
424 case LTTNG_UST_ABI_WAIT_QUIESCENT
:
425 lttng_ust_urcu_synchronize_rcu();
427 case LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE
:
428 return lttng_abi_event_notifier_send_fd(owner
,
429 &uargs
->event_notifier_handle
.event_notifier_notif_fd
);
435 static const struct lttng_ust_abi_objd_ops lttng_ops
= {
440 int lttng_abi_map_channel(int session_objd
,
441 struct lttng_ust_abi_channel
*ust_chan
,
442 union lttng_ust_abi_args
*uargs
,
445 struct lttng_session
*session
= objd_private(session_objd
);
446 const char *transport_name
;
447 const struct lttng_transport
*transport
;
448 const char *chan_name
;
450 struct lttng_ust_shm_handle
*channel_handle
;
451 struct lttng_channel
*lttng_chan
;
452 struct lttng_ust_lib_ring_buffer_channel
*chan
;
453 struct lttng_ust_lib_ring_buffer_config
*config
;
458 enum lttng_ust_abi_chan_type type
;
460 chan_data
= uargs
->channel
.chan_data
;
461 wakeup_fd
= uargs
->channel
.wakeup_fd
;
463 type
= ust_chan
->type
;
466 case LTTNG_UST_ABI_CHAN_PER_CPU
:
473 if (session
->priv
->been_active
) {
475 goto active
; /* Refuse to add channel to active session */
478 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
479 if (!channel_handle
) {
484 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
485 uargs
->channel
.chan_data
= NULL
;
486 uargs
->channel
.wakeup_fd
= -1;
488 chan
= shmp(channel_handle
, channel_handle
->chan
);
490 chan
->handle
= channel_handle
;
491 config
= &chan
->backend
.config
;
492 lttng_chan
= channel_get_private(chan
);
498 /* Lookup transport name */
500 case LTTNG_UST_ABI_CHAN_PER_CPU
:
501 if (config
->output
== RING_BUFFER_MMAP
) {
502 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
503 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
504 transport_name
= "relay-overwrite-mmap";
506 transport_name
= "relay-overwrite-rt-mmap";
509 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
510 transport_name
= "relay-discard-mmap";
512 transport_name
= "relay-discard-rt-mmap";
519 chan_name
= "channel";
525 transport
= lttng_ust_transport_find(transport_name
);
527 DBG("LTTng transport %s not found\n",
533 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
539 /* Initialize our lttng chan */
540 lttng_chan
->chan
= chan
;
541 lttng_chan
->tstate
= 1;
542 lttng_chan
->enabled
= 1;
543 lttng_chan
->ctx
= NULL
;
544 lttng_chan
->session
= session
;
545 lttng_chan
->ops
= &transport
->ops
;
546 memcpy(<tng_chan
->chan
->backend
.config
,
547 transport
->client_config
,
548 sizeof(lttng_chan
->chan
->backend
.config
));
549 cds_list_add(<tng_chan
->node
, &session
->priv
->chan_head
);
550 lttng_chan
->header_type
= 0;
551 lttng_chan
->handle
= channel_handle
;
552 lttng_chan
->type
= type
;
555 * We tolerate no failure path after channel creation. It will stay
556 * invariant for the rest of the session.
558 objd_set_private(chan_objd
, lttng_chan
);
559 lttng_chan
->objd
= chan_objd
;
560 /* The channel created holds a reference on the session */
561 objd_ref(session_objd
);
564 /* error path after channel was created */
568 channel_destroy(chan
, channel_handle
, 0);
578 * lttng_session_cmd - lttng session object command
583 * @uargs: UST arguments (internal)
586 * This descriptor implements lttng commands:
587 * LTTNG_UST_ABI_CHANNEL
588 * Returns a LTTng channel object descriptor
589 * LTTNG_UST_ABI_ENABLE
590 * Enables tracing for a session (weak enable)
591 * LTTNG_UST_ABI_DISABLE
592 * Disables tracing for a session (strong disable)
594 * The returned channel will be deleted when its file descriptor is closed.
597 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
598 union lttng_ust_abi_args
*uargs
, void *owner
)
600 struct lttng_session
*session
= objd_private(objd
);
603 case LTTNG_UST_ABI_CHANNEL
:
604 return lttng_abi_map_channel(objd
,
605 (struct lttng_ust_abi_channel
*) arg
,
607 case LTTNG_UST_ABI_SESSION_START
:
608 case LTTNG_UST_ABI_ENABLE
:
609 return lttng_session_enable(session
);
610 case LTTNG_UST_ABI_SESSION_STOP
:
611 case LTTNG_UST_ABI_DISABLE
:
612 return lttng_session_disable(session
);
613 case LTTNG_UST_ABI_SESSION_STATEDUMP
:
614 return lttng_session_statedump(session
);
615 case LTTNG_UST_ABI_COUNTER
:
616 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
617 case LTTNG_UST_ABI_COUNTER_CPU
:
618 /* Not implemented yet. */
626 * Called when the last file reference is dropped.
628 * Big fat note: channels and events are invariant for the whole session after
629 * their creation. So this session destruction also destroys all channel and
630 * event structures specific to this session (they are not destroyed when their
631 * individual file is released).
634 int lttng_release_session(int objd
)
636 struct lttng_session
*session
= objd_private(objd
);
639 lttng_session_destroy(session
);
646 static const struct lttng_ust_abi_objd_ops lttng_session_ops
= {
647 .release
= lttng_release_session
,
648 .cmd
= lttng_session_cmd
,
651 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
652 void *owner
, struct lttng_ust_abi_event_notifier
*event_notifier_param
,
653 enum lttng_enabler_format_type type
)
655 struct lttng_event_notifier_group
*event_notifier_group
=
656 objd_private(event_notifier_group_obj
);
657 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
658 int event_notifier_objd
, ret
;
660 event_notifier_param
->event
.name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
661 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
662 "event_notifier enabler");
663 if (event_notifier_objd
< 0) {
664 ret
= event_notifier_objd
;
668 event_notifier_enabler
= lttng_event_notifier_enabler_create(
669 event_notifier_group
, type
, event_notifier_param
);
670 if (!event_notifier_enabler
) {
672 goto event_notifier_error
;
675 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
676 /* The event_notifier holds a reference on the event_notifier group. */
677 objd_ref(event_notifier_enabler
->group
->objd
);
679 return event_notifier_objd
;
681 event_notifier_error
:
685 err
= lttng_ust_abi_objd_unref(event_notifier_objd
, 1);
693 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
694 union lttng_ust_abi_args
*uargs
, void *owner
)
696 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
698 case LTTNG_UST_ABI_FILTER
:
699 return lttng_event_notifier_enabler_attach_filter_bytecode(
700 event_notifier_enabler
,
701 (struct lttng_ust_bytecode_node
**) arg
);
702 case LTTNG_UST_ABI_EXCLUSION
:
703 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
704 (struct lttng_ust_excluder_node
**) arg
);
705 case LTTNG_UST_ABI_CAPTURE
:
706 return lttng_event_notifier_enabler_attach_capture_bytecode(
707 event_notifier_enabler
,
708 (struct lttng_ust_bytecode_node
**) arg
);
709 case LTTNG_UST_ABI_ENABLE
:
710 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
711 case LTTNG_UST_ABI_DISABLE
:
712 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
719 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
724 * @uargs: UST arguments (internal)
727 * This descriptor implements lttng commands:
728 * LTTNG_UST_ABI_COUNTER_GLOBAL
729 * Return negative error code on error, 0 on success.
730 * LTTNG_UST_ABI_COUNTER_CPU
731 * Return negative error code on error, 0 on success.
734 long lttng_event_notifier_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
735 union lttng_ust_abi_args
*uargs
, void *owner
)
738 struct lttng_counter
*counter
= objd_private(objd
);
741 case LTTNG_UST_ABI_COUNTER_GLOBAL
:
742 ret
= -EINVAL
; /* Unimplemented. */
744 case LTTNG_UST_ABI_COUNTER_CPU
:
746 struct lttng_ust_abi_counter_cpu
*counter_cpu
=
747 (struct lttng_ust_abi_counter_cpu
*)arg
;
749 ret
= lttng_counter_set_cpu_shm(counter
->counter
,
750 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
752 /* Take ownership of the shm_fd. */
753 uargs
->counter_shm
.shm_fd
= -1;
765 __attribute__((visibility("hidden")))
766 int lttng_release_event_notifier_group_error_counter(int objd
)
768 struct lttng_counter
*counter
= objd_private(objd
);
771 return lttng_ust_abi_objd_unref(counter
->event_notifier_group
->objd
, 0);
777 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_error_counter_ops
= {
778 .release
= lttng_release_event_notifier_group_error_counter
,
779 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
783 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
784 struct lttng_ust_abi_counter_conf
*error_counter_conf
)
786 const char *counter_transport_name
;
787 struct lttng_event_notifier_group
*event_notifier_group
=
788 objd_private(event_notifier_group_objd
);
789 struct lttng_counter
*counter
;
790 int counter_objd
, ret
;
791 struct lttng_counter_dimension dimensions
[1];
794 if (event_notifier_group
->error_counter
)
797 if (error_counter_conf
->arithmetic
!= LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR
)
800 if (error_counter_conf
->number_dimensions
!= 1)
803 switch (error_counter_conf
->bitness
) {
804 case LTTNG_UST_ABI_COUNTER_BITNESS_64
:
805 counter_transport_name
= "counter-per-cpu-64-modular";
807 case LTTNG_UST_ABI_COUNTER_BITNESS_32
:
808 counter_transport_name
= "counter-per-cpu-32-modular";
814 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
815 "event_notifier group error counter");
816 if (counter_objd
< 0) {
821 counter_len
= error_counter_conf
->dimensions
[0].size
;
822 dimensions
[0].size
= counter_len
;
823 dimensions
[0].underflow_index
= 0;
824 dimensions
[0].overflow_index
= 0;
825 dimensions
[0].has_underflow
= 0;
826 dimensions
[0].has_overflow
= 0;
828 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
834 event_notifier_group
->error_counter_len
= counter_len
;
836 * store-release to publish error counter matches load-acquire
837 * in record_error. Ensures the counter is created and the
838 * error_counter_len is set before they are used.
839 * Currently a full memory barrier is used, which could be
840 * turned into acquire-release barriers.
843 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
845 counter
->objd
= counter_objd
;
846 counter
->event_notifier_group
= event_notifier_group
; /* owner */
848 objd_set_private(counter_objd
, counter
);
849 /* The error counter holds a reference on the event_notifier group. */
850 objd_ref(event_notifier_group
->objd
);
858 err
= lttng_ust_abi_objd_unref(counter_objd
, 1);
866 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
867 union lttng_ust_abi_args
*uargs
, void *owner
)
870 case LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE
:
872 struct lttng_ust_abi_event_notifier
*event_notifier_param
=
873 (struct lttng_ust_abi_event_notifier
*) arg
;
874 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
876 * If the event name is a star globbing pattern,
877 * we create the special star globbing enabler.
879 return lttng_ust_event_notifier_enabler_create(objd
,
880 owner
, event_notifier_param
,
881 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
883 return lttng_ust_event_notifier_enabler_create(objd
,
884 owner
, event_notifier_param
,
885 LTTNG_ENABLER_FORMAT_EVENT
);
888 case LTTNG_UST_ABI_COUNTER
:
890 struct lttng_ust_abi_counter_conf
*counter_conf
=
891 (struct lttng_ust_abi_counter_conf
*) uargs
->counter
.counter_data
;
892 return lttng_ust_event_notifier_group_create_error_counter(
893 objd
, owner
, counter_conf
);
901 int lttng_event_notifier_enabler_release(int objd
)
903 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
905 if (event_notifier_enabler
)
906 return lttng_ust_abi_objd_unref(event_notifier_enabler
->group
->objd
, 0);
910 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_enabler_ops
= {
911 .release
= lttng_event_notifier_enabler_release
,
912 .cmd
= lttng_event_notifier_enabler_cmd
,
916 int lttng_release_event_notifier_group(int objd
)
918 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
920 if (event_notifier_group
) {
921 lttng_event_notifier_group_destroy(event_notifier_group
);
928 static const struct lttng_ust_abi_objd_ops lttng_event_notifier_group_ops
= {
929 .release
= lttng_release_event_notifier_group
,
930 .cmd
= lttng_event_notifier_group_cmd
,
934 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
935 union lttng_ust_abi_args
*uargs
, void *owner
)
937 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
938 struct lttng_ust_abi_tracepoint_iter
*tp
=
939 (struct lttng_ust_abi_tracepoint_iter
*) arg
;
940 struct lttng_ust_abi_tracepoint_iter
*iter
;
943 case LTTNG_UST_ABI_TRACEPOINT_LIST_GET
:
945 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
947 return -LTTNG_UST_ERR_NOENT
;
948 memcpy(tp
, iter
, sizeof(*tp
));
957 int lttng_abi_tracepoint_list(void *owner
)
960 struct lttng_ust_tracepoint_list
*list
;
962 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
967 list
= zmalloc(sizeof(*list
));
972 objd_set_private(list_objd
, list
);
974 /* populate list by walking on all registered probes. */
975 ret
= lttng_probes_get_event_list(list
);
987 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
995 int lttng_release_tracepoint_list(int objd
)
997 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
1000 lttng_probes_prune_event_list(list
);
1008 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_list_ops
= {
1009 .release
= lttng_release_tracepoint_list
,
1010 .cmd
= lttng_tracepoint_list_cmd
,
1014 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1015 unsigned long arg
, union lttng_ust_abi_args
*uargs
, void *owner
)
1017 struct lttng_ust_field_list
*list
= objd_private(objd
);
1018 struct lttng_ust_abi_field_iter
*tp
= &uargs
->field_list
.entry
;
1019 struct lttng_ust_abi_field_iter
*iter
;
1022 case LTTNG_UST_ABI_TRACEPOINT_FIELD_LIST_GET
:
1024 iter
= lttng_ust_field_list_get_iter_next(list
);
1026 return -LTTNG_UST_ERR_NOENT
;
1027 memcpy(tp
, iter
, sizeof(*tp
));
1036 int lttng_abi_tracepoint_field_list(void *owner
)
1039 struct lttng_ust_field_list
*list
;
1041 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1043 if (list_objd
< 0) {
1047 list
= zmalloc(sizeof(*list
));
1052 objd_set_private(list_objd
, list
);
1054 /* populate list by walking on all registered probes. */
1055 ret
= lttng_probes_get_field_list(list
);
1067 err
= lttng_ust_abi_objd_unref(list_objd
, 1);
1075 int lttng_release_tracepoint_field_list(int objd
)
1077 struct lttng_ust_field_list
*list
= objd_private(objd
);
1080 lttng_probes_prune_field_list(list
);
1088 static const struct lttng_ust_abi_objd_ops lttng_tracepoint_field_list_ops
= {
1089 .release
= lttng_release_tracepoint_field_list
,
1090 .cmd
= lttng_tracepoint_field_list_cmd
,
1094 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_abi_stream
*info
,
1095 union lttng_ust_abi_args
*uargs
, void *owner
)
1097 struct lttng_channel
*channel
= objd_private(channel_objd
);
1100 ret
= channel_handle_add_stream(channel
->handle
,
1101 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1102 info
->stream_nr
, info
->len
);
1104 goto error_add_stream
;
1105 /* Take ownership of shm_fd and wakeup_fd. */
1106 uargs
->stream
.shm_fd
= -1;
1107 uargs
->stream
.wakeup_fd
= -1;
1116 int lttng_abi_create_event_enabler(int channel_objd
,
1117 struct lttng_ust_abi_event
*event_param
,
1119 enum lttng_enabler_format_type format_type
)
1121 struct lttng_channel
*channel
= objd_private(channel_objd
);
1122 struct lttng_event_enabler
*enabler
;
1123 int event_objd
, ret
;
1125 event_param
->name
[LTTNG_UST_ABI_SYM_NAME_LEN
- 1] = '\0';
1126 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1128 if (event_objd
< 0) {
1133 * We tolerate no failure path after event creation. It will stay
1134 * invariant for the rest of the session.
1136 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1141 objd_set_private(event_objd
, enabler
);
1142 /* The event holds a reference on the channel */
1143 objd_ref(channel_objd
);
1150 err
= lttng_ust_abi_objd_unref(event_objd
, 1);
1158 * lttng_channel_cmd - lttng control through object descriptors
1160 * @objd: the object descriptor
1163 * @uargs: UST arguments (internal)
1164 * @owner: objd owner
1166 * This object descriptor implements lttng commands:
1167 * LTTNG_UST_ABI_STREAM
1168 * Returns an event stream object descriptor or failure.
1169 * (typically, one event stream records events from one CPU)
1170 * LTTNG_UST_ABI_EVENT
1171 * Returns an event object descriptor or failure.
1172 * LTTNG_UST_ABI_CONTEXT
1173 * Prepend a context field to each event in the channel
1174 * LTTNG_UST_ABI_ENABLE
1175 * Enable recording for events in this channel (weak enable)
1176 * LTTNG_UST_ABI_DISABLE
1177 * Disable recording for events in this channel (strong disable)
1179 * Channel and event file descriptors also hold a reference on the session.
1182 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1183 union lttng_ust_abi_args
*uargs
, void *owner
)
1185 struct lttng_channel
*channel
= objd_private(objd
);
1187 if (cmd
!= LTTNG_UST_ABI_STREAM
) {
1189 * Check if channel received all streams.
1191 if (!lttng_is_channel_ready(channel
))
1196 case LTTNG_UST_ABI_STREAM
:
1198 struct lttng_ust_abi_stream
*stream
;
1200 stream
= (struct lttng_ust_abi_stream
*) arg
;
1201 /* stream used as output */
1202 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1204 case LTTNG_UST_ABI_EVENT
:
1206 struct lttng_ust_abi_event
*event_param
=
1207 (struct lttng_ust_abi_event
*) arg
;
1209 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1211 * If the event name is a star globbing pattern,
1212 * we create the special star globbing enabler.
1214 return lttng_abi_create_event_enabler(objd
, event_param
,
1215 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1217 return lttng_abi_create_event_enabler(objd
, event_param
,
1218 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1221 case LTTNG_UST_ABI_CONTEXT
:
1222 return lttng_abi_add_context(objd
,
1223 (struct lttng_ust_abi_context
*) arg
, uargs
,
1224 &channel
->ctx
, channel
->session
);
1225 case LTTNG_UST_ABI_ENABLE
:
1226 return lttng_channel_enable(channel
);
1227 case LTTNG_UST_ABI_DISABLE
:
1228 return lttng_channel_disable(channel
);
1229 case LTTNG_UST_ABI_FLUSH_BUFFER
:
1230 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1237 int lttng_channel_release(int objd
)
1239 struct lttng_channel
*channel
= objd_private(objd
);
1242 return lttng_ust_abi_objd_unref(channel
->session
->priv
->objd
, 0);
1246 static const struct lttng_ust_abi_objd_ops lttng_channel_ops
= {
1247 .release
= lttng_channel_release
,
1248 .cmd
= lttng_channel_cmd
,
1252 * lttng_enabler_cmd - lttng control through object descriptors
1254 * @objd: the object descriptor
1257 * @uargs: UST arguments (internal)
1258 * @owner: objd owner
1260 * This object descriptor implements lttng commands:
1261 * LTTNG_UST_ABI_CONTEXT
1262 * Prepend a context field to each record of events of this
1264 * LTTNG_UST_ABI_ENABLE
1265 * Enable recording for this enabler
1266 * LTTNG_UST_ABI_DISABLE
1267 * Disable recording for this enabler
1268 * LTTNG_UST_ABI_FILTER
1269 * Attach a filter to an enabler.
1270 * LTTNG_UST_ABI_EXCLUSION
1271 * Attach exclusions to an enabler.
1274 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1275 union lttng_ust_abi_args
*uargs
, void *owner
)
1277 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1280 case LTTNG_UST_ABI_CONTEXT
:
1281 return lttng_event_enabler_attach_context(enabler
,
1282 (struct lttng_ust_abi_context
*) arg
);
1283 case LTTNG_UST_ABI_ENABLE
:
1284 return lttng_event_enabler_enable(enabler
);
1285 case LTTNG_UST_ABI_DISABLE
:
1286 return lttng_event_enabler_disable(enabler
);
1287 case LTTNG_UST_ABI_FILTER
:
1291 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1292 (struct lttng_ust_bytecode_node
**) arg
);
1297 case LTTNG_UST_ABI_EXCLUSION
:
1299 return lttng_event_enabler_attach_exclusion(enabler
,
1300 (struct lttng_ust_excluder_node
**) arg
);
1308 int lttng_event_enabler_release(int objd
)
1310 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1313 return lttng_ust_abi_objd_unref(event_enabler
->chan
->objd
, 0);
1318 static const struct lttng_ust_abi_objd_ops lttng_event_enabler_ops
= {
1319 .release
= lttng_event_enabler_release
,
1320 .cmd
= lttng_event_enabler_cmd
,
1323 void lttng_ust_abi_exit(void)
1325 lttng_ust_abi_close_in_progress
= 1;
1327 objd_table_destroy();
1329 lttng_ust_abi_close_in_progress
= 0;