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
)
736 struct lttng_counter
*counter
= objd_private(objd
);
739 case LTTNG_UST_COUNTER_GLOBAL
:
740 return -EINVAL
; /* Unimplemented. */
741 case LTTNG_UST_COUNTER_CPU
:
743 struct lttng_ust_counter_cpu
*counter_cpu
=
744 (struct lttng_ust_counter_cpu
*)arg
;
745 return lttng_counter_set_cpu_shm(counter
->counter
,
746 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
754 int lttng_release_event_notifier_group_error_counter(int objd
)
756 struct lttng_counter
*counter
= objd_private(objd
);
759 return lttng_ust_objd_unref(counter
->event_notifier_group
->objd
, 0);
765 static const struct lttng_ust_objd_ops lttng_event_notifier_group_error_counter_ops
= {
766 .release
= lttng_release_event_notifier_group_error_counter
,
767 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
771 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
772 struct lttng_ust_counter_conf
*error_counter_conf
)
774 const char *counter_transport_name
;
775 struct lttng_event_notifier_group
*event_notifier_group
=
776 objd_private(event_notifier_group_objd
);
777 struct lttng_counter
*counter
;
778 int counter_objd
, ret
;
779 struct lttng_counter_dimension dimensions
[1];
782 if (event_notifier_group
->error_counter
)
785 if (error_counter_conf
->arithmetic
!= LTTNG_UST_COUNTER_ARITHMETIC_MODULAR
)
788 if (error_counter_conf
->number_dimensions
!= 1)
791 switch (error_counter_conf
->bitness
) {
792 case LTTNG_UST_COUNTER_BITNESS_64
:
793 counter_transport_name
= "counter-per-cpu-64-modular";
795 case LTTNG_UST_COUNTER_BITNESS_32
:
796 counter_transport_name
= "counter-per-cpu-32-modular";
802 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
803 "event_notifier group error counter");
804 if (counter_objd
< 0) {
809 counter_len
= error_counter_conf
->dimensions
[0].size
;
810 dimensions
[0].size
= counter_len
;
811 dimensions
[0].underflow_index
= 0;
812 dimensions
[0].overflow_index
= 0;
813 dimensions
[0].has_underflow
= 0;
814 dimensions
[0].has_overflow
= 0;
816 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
822 event_notifier_group
->error_counter_len
= counter_len
;
824 * store-release to publish error counter matches load-acquire
825 * in record_error. Ensures the counter is created and the
826 * error_counter_len is set before they are used.
827 * Currently a full memory barrier is used, which could be
828 * turned into acquire-release barriers.
831 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
833 counter
->objd
= counter_objd
;
834 counter
->event_notifier_group
= event_notifier_group
; /* owner */
836 objd_set_private(counter_objd
, counter
);
837 /* The error counter holds a reference on the event_notifier group. */
838 objd_ref(event_notifier_group
->objd
);
846 err
= lttng_ust_objd_unref(counter_objd
, 1);
854 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
855 union ust_args
*uargs
, void *owner
)
858 case LTTNG_UST_EVENT_NOTIFIER_CREATE
:
860 struct lttng_ust_event_notifier
*event_notifier_param
=
861 (struct lttng_ust_event_notifier
*) arg
;
862 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
864 * If the event name is a star globbing pattern,
865 * we create the special star globbing enabler.
867 return lttng_ust_event_notifier_enabler_create(objd
,
868 owner
, event_notifier_param
,
869 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
871 return lttng_ust_event_notifier_enabler_create(objd
,
872 owner
, event_notifier_param
,
873 LTTNG_ENABLER_FORMAT_EVENT
);
876 case LTTNG_UST_COUNTER
:
878 struct lttng_ust_counter_conf
*counter_conf
=
879 (struct lttng_ust_counter_conf
*) uargs
->counter
.counter_data
;
880 return lttng_ust_event_notifier_group_create_error_counter(
881 objd
, owner
, counter_conf
);
889 int lttng_event_notifier_enabler_release(int objd
)
891 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
893 if (event_notifier_enabler
)
894 return lttng_ust_objd_unref(event_notifier_enabler
->group
->objd
, 0);
898 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
= {
899 .release
= lttng_event_notifier_enabler_release
,
900 .cmd
= lttng_event_notifier_enabler_cmd
,
904 int lttng_release_event_notifier_group(int objd
)
906 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
908 if (event_notifier_group
) {
909 lttng_event_notifier_group_destroy(event_notifier_group
);
916 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
= {
917 .release
= lttng_release_event_notifier_group
,
918 .cmd
= lttng_event_notifier_group_cmd
,
922 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
923 union ust_args
*uargs
, void *owner
)
925 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
926 struct lttng_ust_tracepoint_iter
*tp
=
927 (struct lttng_ust_tracepoint_iter
*) arg
;
928 struct lttng_ust_tracepoint_iter
*iter
;
931 case LTTNG_UST_TRACEPOINT_LIST_GET
:
933 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
935 return -LTTNG_UST_ERR_NOENT
;
936 memcpy(tp
, iter
, sizeof(*tp
));
945 int lttng_abi_tracepoint_list(void *owner
)
948 struct lttng_ust_tracepoint_list
*list
;
950 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
955 list
= zmalloc(sizeof(*list
));
960 objd_set_private(list_objd
, list
);
962 /* populate list by walking on all registered probes. */
963 ret
= lttng_probes_get_event_list(list
);
975 err
= lttng_ust_objd_unref(list_objd
, 1);
983 int lttng_release_tracepoint_list(int objd
)
985 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
988 lttng_probes_prune_event_list(list
);
996 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
997 .release
= lttng_release_tracepoint_list
,
998 .cmd
= lttng_tracepoint_list_cmd
,
1002 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1003 unsigned long arg
, union ust_args
*uargs
, void *owner
)
1005 struct lttng_ust_field_list
*list
= objd_private(objd
);
1006 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
1007 struct lttng_ust_field_iter
*iter
;
1010 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
1012 iter
= lttng_ust_field_list_get_iter_next(list
);
1014 return -LTTNG_UST_ERR_NOENT
;
1015 memcpy(tp
, iter
, sizeof(*tp
));
1024 int lttng_abi_tracepoint_field_list(void *owner
)
1027 struct lttng_ust_field_list
*list
;
1029 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1031 if (list_objd
< 0) {
1035 list
= zmalloc(sizeof(*list
));
1040 objd_set_private(list_objd
, list
);
1042 /* populate list by walking on all registered probes. */
1043 ret
= lttng_probes_get_field_list(list
);
1055 err
= lttng_ust_objd_unref(list_objd
, 1);
1063 int lttng_release_tracepoint_field_list(int objd
)
1065 struct lttng_ust_field_list
*list
= objd_private(objd
);
1068 lttng_probes_prune_field_list(list
);
1076 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
1077 .release
= lttng_release_tracepoint_field_list
,
1078 .cmd
= lttng_tracepoint_field_list_cmd
,
1082 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
1083 union ust_args
*uargs
, void *owner
)
1085 struct lttng_channel
*channel
= objd_private(channel_objd
);
1088 ret
= channel_handle_add_stream(channel
->handle
,
1089 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1090 info
->stream_nr
, info
->len
);
1092 goto error_add_stream
;
1093 /* Take ownership of shm_fd and wakeup_fd. */
1094 uargs
->stream
.shm_fd
= -1;
1095 uargs
->stream
.wakeup_fd
= -1;
1104 int lttng_abi_create_event_enabler(int channel_objd
,
1105 struct lttng_ust_event
*event_param
,
1107 enum lttng_enabler_format_type format_type
)
1109 struct lttng_channel
*channel
= objd_private(channel_objd
);
1110 struct lttng_event_enabler
*enabler
;
1111 int event_objd
, ret
;
1113 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1114 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1116 if (event_objd
< 0) {
1121 * We tolerate no failure path after event creation. It will stay
1122 * invariant for the rest of the session.
1124 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1129 objd_set_private(event_objd
, enabler
);
1130 /* The event holds a reference on the channel */
1131 objd_ref(channel_objd
);
1138 err
= lttng_ust_objd_unref(event_objd
, 1);
1146 * lttng_channel_cmd - lttng control through object descriptors
1148 * @objd: the object descriptor
1151 * @uargs: UST arguments (internal)
1152 * @owner: objd owner
1154 * This object descriptor implements lttng commands:
1156 * Returns an event stream object descriptor or failure.
1157 * (typically, one event stream records events from one CPU)
1159 * Returns an event object descriptor or failure.
1161 * Prepend a context field to each event in the channel
1163 * Enable recording for events in this channel (weak enable)
1165 * Disable recording for events in this channel (strong disable)
1167 * Channel and event file descriptors also hold a reference on the session.
1170 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1171 union ust_args
*uargs
, void *owner
)
1173 struct lttng_channel
*channel
= objd_private(objd
);
1175 if (cmd
!= LTTNG_UST_STREAM
) {
1177 * Check if channel received all streams.
1179 if (!lttng_is_channel_ready(channel
))
1184 case LTTNG_UST_STREAM
:
1186 struct lttng_ust_stream
*stream
;
1188 stream
= (struct lttng_ust_stream
*) arg
;
1189 /* stream used as output */
1190 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1192 case LTTNG_UST_EVENT
:
1194 struct lttng_ust_event
*event_param
=
1195 (struct lttng_ust_event
*) arg
;
1197 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1199 * If the event name is a star globbing pattern,
1200 * we create the special star globbing enabler.
1202 return lttng_abi_create_event_enabler(objd
, event_param
,
1203 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1205 return lttng_abi_create_event_enabler(objd
, event_param
,
1206 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1209 case LTTNG_UST_CONTEXT
:
1210 return lttng_abi_add_context(objd
,
1211 (struct lttng_ust_context
*) arg
, uargs
,
1212 &channel
->ctx
, channel
->session
);
1213 case LTTNG_UST_ENABLE
:
1214 return lttng_channel_enable(channel
);
1215 case LTTNG_UST_DISABLE
:
1216 return lttng_channel_disable(channel
);
1217 case LTTNG_UST_FLUSH_BUFFER
:
1218 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1225 int lttng_channel_release(int objd
)
1227 struct lttng_channel
*channel
= objd_private(objd
);
1230 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1234 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1235 .release
= lttng_channel_release
,
1236 .cmd
= lttng_channel_cmd
,
1240 * lttng_enabler_cmd - lttng control through object descriptors
1242 * @objd: the object descriptor
1245 * @uargs: UST arguments (internal)
1246 * @owner: objd owner
1248 * This object descriptor implements lttng commands:
1250 * Prepend a context field to each record of events of this
1253 * Enable recording for this enabler
1255 * Disable recording for this enabler
1257 * Attach a filter to an enabler.
1258 * LTTNG_UST_EXCLUSION
1259 * Attach exclusions to an enabler.
1262 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1263 union ust_args
*uargs
, void *owner
)
1265 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1268 case LTTNG_UST_CONTEXT
:
1269 return lttng_event_enabler_attach_context(enabler
,
1270 (struct lttng_ust_context
*) arg
);
1271 case LTTNG_UST_ENABLE
:
1272 return lttng_event_enabler_enable(enabler
);
1273 case LTTNG_UST_DISABLE
:
1274 return lttng_event_enabler_disable(enabler
);
1275 case LTTNG_UST_FILTER
:
1279 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1280 (struct lttng_ust_bytecode_node
**) arg
);
1285 case LTTNG_UST_EXCLUSION
:
1287 return lttng_event_enabler_attach_exclusion(enabler
,
1288 (struct lttng_ust_excluder_node
**) arg
);
1296 int lttng_event_enabler_release(int objd
)
1298 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1301 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1306 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1307 .release
= lttng_event_enabler_release
,
1308 .cmd
= lttng_event_enabler_cmd
,
1311 void lttng_ust_abi_exit(void)
1313 lttng_ust_abi_close_in_progress
= 1;
1315 objd_table_destroy();
1317 lttng_ust_abi_close_in_progress
= 0;