6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Mimic system calls for:
24 * - session creation, returns an object descriptor or failure.
25 * - channel creation, returns an object descriptor or failure.
26 * - Operates on a session object descriptor
27 * - Takes all channel options as parameters.
28 * - stream get, returns an object descriptor or failure.
29 * - Operates on a channel object descriptor.
30 * - stream notifier get, returns an object descriptor or failure.
31 * - Operates on a channel object descriptor.
32 * - event creation, returns an object descriptor or failure.
33 * - Operates on a channel object descriptor
34 * - Takes an event name as parameter
35 * - Takes an instrumentation source as parameter
36 * - e.g. tracepoints, dynamic_probes...
37 * - Takes instrumentation source specific arguments.
45 #include <urcu/compiler.h>
46 #include <urcu/list.h>
49 #include <lttng/tracepoint.h>
50 #include <lttng/ust-abi.h>
51 #include <lttng/ust-error.h>
52 #include <lttng/ust-events.h>
53 #include <lttng/ust-version.h>
55 #include <usterr-signal-safe.h>
57 #include "../libringbuffer/frontend_types.h"
58 #include "../libringbuffer/shm.h"
59 #include "../libcounter/counter.h"
60 #include "lttng-tracer.h"
61 #include "string-utils.h"
62 #include "ust-events-internal.h"
64 #define OBJ_NAME_LEN 16
66 static int lttng_ust_abi_close_in_progress
;
69 int lttng_abi_tracepoint_list(void *owner
);
71 int lttng_abi_tracepoint_field_list(void *owner
);
74 * Object descriptor table. Should be protected from concurrent access
78 struct lttng_ust_obj
{
82 const struct lttng_ust_objd_ops
*ops
;
84 int owner_ref
; /* has ref from owner */
86 char name
[OBJ_NAME_LEN
];
88 int freelist_next
; /* offset freelist. end is -1. */
92 struct lttng_ust_objd_table
{
93 struct lttng_ust_obj
*array
;
94 unsigned int len
, allocated_len
;
95 int freelist_head
; /* offset freelist head. end is -1 */
98 static struct lttng_ust_objd_table objd_table
= {
103 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
,
104 void *owner
, const char *name
)
106 struct lttng_ust_obj
*obj
;
108 if (objd_table
.freelist_head
!= -1) {
109 obj
= &objd_table
.array
[objd_table
.freelist_head
];
110 objd_table
.freelist_head
= obj
->u
.freelist_next
;
114 if (objd_table
.len
>= objd_table
.allocated_len
) {
115 unsigned int new_allocated_len
, old_allocated_len
;
116 struct lttng_ust_obj
*new_table
, *old_table
;
118 old_allocated_len
= objd_table
.allocated_len
;
119 old_table
= objd_table
.array
;
120 if (!old_allocated_len
)
121 new_allocated_len
= 1;
123 new_allocated_len
= old_allocated_len
<< 1;
124 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
127 memcpy(new_table
, old_table
,
128 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
130 objd_table
.array
= new_table
;
131 objd_table
.allocated_len
= new_allocated_len
;
133 obj
= &objd_table
.array
[objd_table
.len
];
136 obj
->u
.s
.private_data
= private_data
;
138 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
139 /* count == 2 : allocated + hold ref */
140 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
141 obj
->u
.s
.owner
= owner
;
142 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
143 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
144 return obj
- objd_table
.array
;
148 struct lttng_ust_obj
*_objd_get(int id
)
150 if (id
>= objd_table
.len
)
152 if (!objd_table
.array
[id
].u
.s
.f_count
)
154 return &objd_table
.array
[id
];
158 void *objd_private(int id
)
160 struct lttng_ust_obj
*obj
= _objd_get(id
);
162 return obj
->u
.s
.private_data
;
166 void objd_set_private(int id
, void *private_data
)
168 struct lttng_ust_obj
*obj
= _objd_get(id
);
170 obj
->u
.s
.private_data
= private_data
;
173 const struct lttng_ust_objd_ops
*objd_ops(int id
)
175 struct lttng_ust_obj
*obj
= _objd_get(id
);
183 void objd_free(int id
)
185 struct lttng_ust_obj
*obj
= _objd_get(id
);
188 obj
->u
.freelist_next
= objd_table
.freelist_head
;
189 objd_table
.freelist_head
= obj
- objd_table
.array
;
190 assert(obj
->u
.s
.f_count
== 1);
191 obj
->u
.s
.f_count
= 0; /* deallocated */
195 void objd_ref(int id
)
197 struct lttng_ust_obj
*obj
= _objd_get(id
);
202 int lttng_ust_objd_unref(int id
, int is_owner
)
204 struct lttng_ust_obj
*obj
= _objd_get(id
);
208 if (obj
->u
.s
.f_count
== 1) {
209 ERR("Reference counting error\n");
213 if (!obj
->u
.s
.owner_ref
) {
214 ERR("Error decrementing owner reference");
217 obj
->u
.s
.owner_ref
--;
219 if ((--obj
->u
.s
.f_count
) == 1) {
220 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
230 void objd_table_destroy(void)
234 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
235 struct lttng_ust_obj
*obj
;
240 if (!obj
->u
.s
.owner_ref
)
241 continue; /* only unref owner ref. */
242 (void) lttng_ust_objd_unref(i
, 1);
244 free(objd_table
.array
);
245 objd_table
.array
= NULL
;
247 objd_table
.allocated_len
= 0;
248 objd_table
.freelist_head
= -1;
251 const char *lttng_ust_obj_get_name(int id
)
253 struct lttng_ust_obj
*obj
= _objd_get(id
);
257 return obj
->u
.s
.name
;
260 void lttng_ust_objd_table_owner_cleanup(void *owner
)
264 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
265 struct lttng_ust_obj
*obj
;
271 continue; /* skip root handles */
272 if (!obj
->u
.s
.owner_ref
)
273 continue; /* only unref owner ref. */
274 if (obj
->u
.s
.owner
== owner
)
275 (void) lttng_ust_objd_unref(i
, 1);
280 * This is LTTng's own personal way to create an ABI for sessiond.
281 * We send commands over a socket.
284 static const struct lttng_ust_objd_ops lttng_ops
;
285 static const struct lttng_ust_objd_ops lttng_trigger_group_ops
;
286 static const struct lttng_ust_objd_ops lttng_session_ops
;
287 static const struct lttng_ust_objd_ops lttng_channel_ops
;
288 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
;
289 static const struct lttng_ust_objd_ops lttng_trigger_enabler_ops
;
290 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
291 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
293 int lttng_abi_create_root_handle(void)
297 /* root handles have NULL owners */
298 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
303 int lttng_is_channel_ready(struct lttng_channel
*lttng_chan
)
305 struct channel
*chan
;
306 unsigned int nr_streams
, exp_streams
;
308 chan
= lttng_chan
->chan
;
309 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->handle
);
310 exp_streams
= chan
->nr_streams
;
311 return nr_streams
== exp_streams
;
315 int lttng_abi_create_session(void *owner
)
317 struct lttng_session
*session
;
318 int session_objd
, ret
;
320 session
= lttng_session_create();
323 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
324 if (session_objd
< 0) {
328 session
->objd
= session_objd
;
329 session
->owner
= owner
;
333 lttng_session_destroy(session
);
338 long lttng_abi_tracer_version(int objd
,
339 struct lttng_ust_tracer_version
*v
)
341 v
->major
= LTTNG_UST_MAJOR_VERSION
;
342 v
->minor
= LTTNG_UST_MINOR_VERSION
;
343 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
348 int lttng_abi_trigger_send_fd(void *owner
, int trigger_notif_fd
)
350 struct lttng_trigger_group
*trigger_group
;
351 int trigger_group_objd
, ret
, fd_flag
, close_ret
;
353 trigger_group
= lttng_trigger_group_create();
358 * Set this file descriptor as NON-BLOCKING.
360 fd_flag
= fcntl(trigger_notif_fd
, F_GETFL
);
362 fd_flag
|= O_NONBLOCK
;
364 ret
= fcntl(trigger_notif_fd
, F_SETFL
, fd_flag
);
370 trigger_group_objd
= objd_alloc(trigger_group
,
371 <tng_trigger_group_ops
, owner
, "trigger_group");
372 if (trigger_group_objd
< 0) {
373 ret
= trigger_group_objd
;
377 trigger_group
->objd
= trigger_group_objd
;
378 trigger_group
->owner
= owner
;
379 trigger_group
->notification_fd
= trigger_notif_fd
;
381 return trigger_group_objd
;
384 lttng_trigger_group_destroy(trigger_group
);
386 close_ret
= close(trigger_notif_fd
);
395 long lttng_abi_add_context(int objd
,
396 struct lttng_ust_context
*context_param
,
397 union ust_args
*uargs
,
398 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
400 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
404 * lttng_cmd - lttng control through socket commands
406 * @objd: the object descriptor
409 * @uargs: UST arguments (internal)
412 * This descriptor implements lttng commands:
414 * Returns a LTTng trace session object descriptor
415 * LTTNG_UST_TRACER_VERSION
416 * Returns the LTTng kernel tracer version
417 * LTTNG_UST_TRACEPOINT_LIST
418 * Returns a file descriptor listing available tracepoints
419 * LTTNG_UST_TRACEPOINT_FIELD_LIST
420 * Returns a file descriptor listing available tracepoint fields
421 * LTTNG_UST_WAIT_QUIESCENT
422 * Returns after all previously running probes have completed
424 * The returned session will be deleted when its file descriptor is closed.
427 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
428 union ust_args
*uargs
, void *owner
)
431 case LTTNG_UST_SESSION
:
432 return lttng_abi_create_session(owner
);
433 case LTTNG_UST_TRACER_VERSION
:
434 return lttng_abi_tracer_version(objd
,
435 (struct lttng_ust_tracer_version
*) arg
);
436 case LTTNG_UST_TRACEPOINT_LIST
:
437 return lttng_abi_tracepoint_list(owner
);
438 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
439 return lttng_abi_tracepoint_field_list(owner
);
440 case LTTNG_UST_WAIT_QUIESCENT
:
443 case LTTNG_UST_TRIGGER_GROUP_CREATE
:
444 return lttng_abi_trigger_send_fd(owner
,
445 uargs
->trigger_handle
.trigger_notif_fd
);
451 static const struct lttng_ust_objd_ops lttng_ops
= {
455 int lttng_abi_map_channel(int session_objd
,
456 struct lttng_ust_channel
*ust_chan
,
457 union ust_args
*uargs
,
460 struct lttng_session
*session
= objd_private(session_objd
);
461 const char *transport_name
;
462 const struct lttng_transport
*transport
;
463 const char *chan_name
;
465 struct lttng_ust_shm_handle
*channel_handle
;
466 struct lttng_channel
*lttng_chan
;
467 struct channel
*chan
;
468 struct lttng_ust_lib_ring_buffer_config
*config
;
473 enum lttng_ust_chan_type type
;
475 chan_data
= uargs
->channel
.chan_data
;
476 wakeup_fd
= uargs
->channel
.wakeup_fd
;
478 type
= ust_chan
->type
;
481 case LTTNG_UST_CHAN_PER_CPU
:
488 if (session
->been_active
) {
490 goto active
; /* Refuse to add channel to active session */
493 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
494 if (!channel_handle
) {
499 chan
= shmp(channel_handle
, channel_handle
->chan
);
501 chan
->handle
= channel_handle
;
502 config
= &chan
->backend
.config
;
503 lttng_chan
= channel_get_private(chan
);
509 /* Lookup transport name */
511 case LTTNG_UST_CHAN_PER_CPU
:
512 if (config
->output
== RING_BUFFER_MMAP
) {
513 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
514 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
515 transport_name
= "relay-overwrite-mmap";
517 transport_name
= "relay-overwrite-rt-mmap";
520 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
521 transport_name
= "relay-discard-mmap";
523 transport_name
= "relay-discard-rt-mmap";
530 chan_name
= "channel";
536 transport
= lttng_transport_find(transport_name
);
538 DBG("LTTng transport %s not found\n",
544 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
550 /* Initialize our lttng chan */
551 lttng_chan
->chan
= chan
;
552 lttng_chan
->tstate
= 1;
553 lttng_chan
->enabled
= 1;
554 lttng_chan
->ctx
= NULL
;
555 lttng_chan
->session
= session
;
556 lttng_chan
->ops
= &transport
->ops
;
557 memcpy(<tng_chan
->chan
->backend
.config
,
558 transport
->client_config
,
559 sizeof(lttng_chan
->chan
->backend
.config
));
560 cds_list_add(<tng_chan
->node
, &session
->chan_head
);
561 lttng_chan
->header_type
= 0;
562 lttng_chan
->handle
= channel_handle
;
563 lttng_chan
->type
= type
;
566 * We tolerate no failure path after channel creation. It will stay
567 * invariant for the rest of the session.
569 objd_set_private(chan_objd
, lttng_chan
);
570 lttng_chan
->objd
= chan_objd
;
571 /* The channel created holds a reference on the session */
572 objd_ref(session_objd
);
575 /* error path after channel was created */
579 channel_destroy(chan
, channel_handle
, 0);
583 * error path before channel creation (owning chan_data and
592 lttng_ust_lock_fd_tracker();
593 close_ret
= close(wakeup_fd
);
594 lttng_ust_unlock_fd_tracker();
604 * lttng_session_cmd - lttng session object command
609 * @uargs: UST arguments (internal)
612 * This descriptor implements lttng commands:
614 * Returns a LTTng channel object descriptor
616 * Enables tracing for a session (weak enable)
618 * Disables tracing for a session (strong disable)
620 * The returned channel will be deleted when its file descriptor is closed.
623 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
624 union ust_args
*uargs
, void *owner
)
626 struct lttng_session
*session
= objd_private(objd
);
629 case LTTNG_UST_CHANNEL
:
630 return lttng_abi_map_channel(objd
,
631 (struct lttng_ust_channel
*) arg
,
633 case LTTNG_UST_SESSION_START
:
634 case LTTNG_UST_ENABLE
:
635 return lttng_session_enable(session
);
636 case LTTNG_UST_SESSION_STOP
:
637 case LTTNG_UST_DISABLE
:
638 return lttng_session_disable(session
);
639 case LTTNG_UST_SESSION_STATEDUMP
:
640 return lttng_session_statedump(session
);
641 case LTTNG_UST_COUNTER
:
642 case LTTNG_UST_COUNTER_GLOBAL
:
643 case LTTNG_UST_COUNTER_CPU
:
644 /* Not implemented yet. */
652 * Called when the last file reference is dropped.
654 * Big fat note: channels and events are invariant for the whole session after
655 * their creation. So this session destruction also destroys all channel and
656 * event structures specific to this session (they are not destroyed when their
657 * individual file is released).
660 int lttng_release_session(int objd
)
662 struct lttng_session
*session
= objd_private(objd
);
665 lttng_session_destroy(session
);
672 static const struct lttng_ust_objd_ops lttng_session_ops
= {
673 .release
= lttng_release_session
,
674 .cmd
= lttng_session_cmd
,
677 static int lttng_ust_trigger_enabler_create(int trigger_group_obj
, void *owner
,
678 struct lttng_ust_trigger
*trigger_param
,
679 enum lttng_enabler_format_type type
)
681 struct lttng_trigger_group
*trigger_group
=
682 objd_private(trigger_group_obj
);
683 struct lttng_trigger_enabler
*trigger_enabler
;
684 int trigger_objd
, ret
;
686 trigger_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
687 trigger_objd
= objd_alloc(NULL
, <tng_trigger_enabler_ops
, owner
,
689 if (trigger_objd
< 0) {
694 trigger_enabler
= lttng_trigger_enabler_create(trigger_group
, type
,
696 if (!trigger_enabler
) {
701 objd_set_private(trigger_objd
, trigger_enabler
);
702 /* The trigger holds a reference on the trigger group. */
703 objd_ref(trigger_enabler
->group
->objd
);
711 err
= lttng_ust_objd_unref(trigger_objd
, 1);
719 long lttng_trigger_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
720 union ust_args
*uargs
, void *owner
)
722 struct lttng_trigger_enabler
*trigger_enabler
= objd_private(objd
);
724 case LTTNG_UST_FILTER
:
725 return lttng_trigger_enabler_attach_filter_bytecode(
727 (struct lttng_ust_bytecode_node
*) arg
);
728 case LTTNG_UST_EXCLUSION
:
729 return lttng_trigger_enabler_attach_exclusion(trigger_enabler
,
730 (struct lttng_ust_excluder_node
*) arg
);
731 case LTTNG_UST_CAPTURE
:
732 return lttng_trigger_enabler_attach_capture_bytecode(
734 (struct lttng_ust_bytecode_node
*) arg
);
735 case LTTNG_UST_ENABLE
:
736 return lttng_trigger_enabler_enable(trigger_enabler
);
737 case LTTNG_UST_DISABLE
:
738 return lttng_trigger_enabler_disable(trigger_enabler
);
745 * lttng_trigger_group_error_counter_cmd - lttng trigger group error counter object command
750 * @uargs: UST arguments (internal)
753 * This descriptor implements lttng commands:
754 * LTTNG_UST_COUNTER_GLOBAL
755 * Return negative error code on error, 0 on success.
756 * LTTNG_UST_COUNTER_CPU
757 * Return negative error code on error, 0 on success.
760 long lttng_trigger_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
761 union ust_args
*uargs
, void *owner
)
763 struct lttng_counter
*counter
= objd_private(objd
);
766 case LTTNG_UST_COUNTER_GLOBAL
:
767 return -EINVAL
; /* Unimplemented. */
768 case LTTNG_UST_COUNTER_CPU
:
770 struct lttng_ust_counter_cpu
*counter_cpu
=
771 (struct lttng_ust_counter_cpu
*)arg
;
772 return lttng_counter_set_cpu_shm(counter
->counter
,
773 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
780 int lttng_release_trigger_group_error_counter(int objd
)
782 struct lttng_counter
*counter
= objd_private(objd
);
785 return lttng_ust_objd_unref(counter
->trigger_group
->objd
, 0);
791 static const struct lttng_ust_objd_ops lttng_trigger_group_error_counter_ops
= {
792 .release
= lttng_release_trigger_group_error_counter
,
793 .cmd
= lttng_trigger_group_error_counter_cmd
,
797 int lttng_ust_trigger_group_create_error_counter(int trigger_group_objd
, void *owner
,
798 struct lttng_ust_counter_conf
*error_counter_conf
)
800 const char *counter_transport_name
;
801 struct lttng_trigger_group
*trigger_group
=
802 objd_private(trigger_group_objd
);
803 struct lttng_counter
*counter
;
804 int counter_objd
, ret
;
805 struct lttng_counter_dimension dimensions
[1];
808 if (trigger_group
->error_counter
)
811 if (error_counter_conf
->arithmetic
!= LTTNG_UST_COUNTER_ARITHMETIC_MODULAR
)
814 if (error_counter_conf
->number_dimensions
!= 1)
817 switch (error_counter_conf
->bitness
) {
818 case LTTNG_UST_COUNTER_BITNESS_64BITS
:
819 counter_transport_name
= "counter-per-cpu-64-modular";
821 case LTTNG_UST_COUNTER_BITNESS_32BITS
:
822 counter_transport_name
= "counter-per-cpu-32-modular";
828 counter_objd
= objd_alloc(NULL
, <tng_trigger_group_error_counter_ops
, owner
,
829 "trigger group error counter");
830 if (counter_objd
< 0) {
835 counter_len
= error_counter_conf
->dimensions
[0].size
;
836 dimensions
[0].size
= counter_len
;
837 dimensions
[0].underflow_index
= 0;
838 dimensions
[0].overflow_index
= 0;
839 dimensions
[0].has_underflow
= 0;
840 dimensions
[0].has_overflow
= 0;
842 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
848 trigger_group
->error_counter
= counter
;
849 trigger_group
->error_counter_len
= counter_len
;
851 counter
->objd
= counter_objd
;
852 counter
->trigger_group
= trigger_group
; /* owner */
854 objd_set_private(counter_objd
, counter
);
855 /* The error counter holds a reference on the trigger group. */
856 objd_ref(trigger_group
->objd
);
864 err
= lttng_ust_objd_unref(counter_objd
, 1);
872 long lttng_trigger_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
873 union ust_args
*uargs
, void *owner
)
876 case LTTNG_UST_TRIGGER_CREATE
:
878 struct lttng_ust_trigger
*trigger_param
=
879 (struct lttng_ust_trigger
*) arg
;
880 if (strutils_is_star_glob_pattern(trigger_param
->name
)) {
882 * If the event name is a star globbing pattern,
883 * we create the special star globbing enabler.
885 return lttng_ust_trigger_enabler_create(objd
, owner
,
886 trigger_param
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
888 return lttng_ust_trigger_enabler_create(objd
, owner
,
889 trigger_param
, LTTNG_ENABLER_FORMAT_EVENT
);
892 case LTTNG_UST_COUNTER
:
894 struct lttng_ust_counter_conf
*counter_conf
=
895 (struct lttng_ust_counter_conf
*) uargs
->counter
.counter_data
;
896 return lttng_ust_trigger_group_create_error_counter(objd
, owner
,
905 int lttng_trigger_enabler_release(int objd
)
907 struct lttng_trigger_enabler
*trigger_enabler
= objd_private(objd
);
910 return lttng_ust_objd_unref(trigger_enabler
->group
->objd
, 0);
914 static const struct lttng_ust_objd_ops lttng_trigger_enabler_ops
= {
915 .release
= lttng_trigger_enabler_release
,
916 .cmd
= lttng_trigger_enabler_cmd
,
920 int lttng_release_trigger_group(int objd
)
922 struct lttng_trigger_group
*trigger_group
= objd_private(objd
);
925 lttng_trigger_group_destroy(trigger_group
);
932 static const struct lttng_ust_objd_ops lttng_trigger_group_ops
= {
933 .release
= lttng_release_trigger_group
,
934 .cmd
= lttng_trigger_group_cmd
,
938 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
939 union ust_args
*uargs
, void *owner
)
941 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
942 struct lttng_ust_tracepoint_iter
*tp
=
943 (struct lttng_ust_tracepoint_iter
*) arg
;
944 struct lttng_ust_tracepoint_iter
*iter
;
947 case LTTNG_UST_TRACEPOINT_LIST_GET
:
949 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
951 return -LTTNG_UST_ERR_NOENT
;
952 memcpy(tp
, iter
, sizeof(*tp
));
961 int lttng_abi_tracepoint_list(void *owner
)
964 struct lttng_ust_tracepoint_list
*list
;
966 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
971 list
= zmalloc(sizeof(*list
));
976 objd_set_private(list_objd
, list
);
978 /* populate list by walking on all registered probes. */
979 ret
= lttng_probes_get_event_list(list
);
991 err
= lttng_ust_objd_unref(list_objd
, 1);
999 int lttng_release_tracepoint_list(int objd
)
1001 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
1004 lttng_probes_prune_event_list(list
);
1012 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
1013 .release
= lttng_release_tracepoint_list
,
1014 .cmd
= lttng_tracepoint_list_cmd
,
1018 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1019 unsigned long arg
, union ust_args
*uargs
, void *owner
)
1021 struct lttng_ust_field_list
*list
= objd_private(objd
);
1022 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
1023 struct lttng_ust_field_iter
*iter
;
1026 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
1028 iter
= lttng_ust_field_list_get_iter_next(list
);
1030 return -LTTNG_UST_ERR_NOENT
;
1031 memcpy(tp
, iter
, sizeof(*tp
));
1040 int lttng_abi_tracepoint_field_list(void *owner
)
1043 struct lttng_ust_field_list
*list
;
1045 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1047 if (list_objd
< 0) {
1051 list
= zmalloc(sizeof(*list
));
1056 objd_set_private(list_objd
, list
);
1058 /* populate list by walking on all registered probes. */
1059 ret
= lttng_probes_get_field_list(list
);
1071 err
= lttng_ust_objd_unref(list_objd
, 1);
1079 int lttng_release_tracepoint_field_list(int objd
)
1081 struct lttng_ust_field_list
*list
= objd_private(objd
);
1084 lttng_probes_prune_field_list(list
);
1092 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
1093 .release
= lttng_release_tracepoint_field_list
,
1094 .cmd
= lttng_tracepoint_field_list_cmd
,
1098 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
1099 union ust_args
*uargs
, void *owner
)
1101 struct lttng_channel
*channel
= objd_private(channel_objd
);
1104 ret
= channel_handle_add_stream(channel
->handle
,
1105 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1106 info
->stream_nr
, info
->len
);
1108 goto error_add_stream
;
1117 int lttng_abi_create_event_enabler(int channel_objd
,
1118 struct lttng_ust_event
*event_param
,
1120 enum lttng_enabler_format_type format_type
)
1122 struct lttng_channel
*channel
= objd_private(channel_objd
);
1123 struct lttng_event_enabler
*enabler
;
1124 int event_objd
, ret
;
1126 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1127 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1129 if (event_objd
< 0) {
1134 * We tolerate no failure path after event creation. It will stay
1135 * invariant for the rest of the session.
1137 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1142 objd_set_private(event_objd
, enabler
);
1143 /* The event holds a reference on the channel */
1144 objd_ref(channel_objd
);
1151 err
= lttng_ust_objd_unref(event_objd
, 1);
1159 * lttng_channel_cmd - lttng control through object descriptors
1161 * @objd: the object descriptor
1164 * @uargs: UST arguments (internal)
1165 * @owner: objd owner
1167 * This object descriptor implements lttng commands:
1169 * Returns an event stream object descriptor or failure.
1170 * (typically, one event stream records events from one CPU)
1172 * Returns an event object descriptor or failure.
1174 * Prepend a context field to each event in the channel
1176 * Enable recording for events in this channel (weak enable)
1178 * Disable recording for events in this channel (strong disable)
1180 * Channel and event file descriptors also hold a reference on the session.
1183 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1184 union ust_args
*uargs
, void *owner
)
1186 struct lttng_channel
*channel
= objd_private(objd
);
1188 if (cmd
!= LTTNG_UST_STREAM
) {
1190 * Check if channel received all streams.
1192 if (!lttng_is_channel_ready(channel
))
1197 case LTTNG_UST_STREAM
:
1199 struct lttng_ust_stream
*stream
;
1201 stream
= (struct lttng_ust_stream
*) arg
;
1202 /* stream used as output */
1203 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1205 case LTTNG_UST_EVENT
:
1207 struct lttng_ust_event
*event_param
=
1208 (struct lttng_ust_event
*) arg
;
1210 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1212 * If the event name is a star globbing pattern,
1213 * we create the special star globbing enabler.
1215 return lttng_abi_create_event_enabler(objd
, event_param
,
1216 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1218 return lttng_abi_create_event_enabler(objd
, event_param
,
1219 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1222 case LTTNG_UST_CONTEXT
:
1223 return lttng_abi_add_context(objd
,
1224 (struct lttng_ust_context
*) arg
, uargs
,
1225 &channel
->ctx
, channel
->session
);
1226 case LTTNG_UST_ENABLE
:
1227 return lttng_channel_enable(channel
);
1228 case LTTNG_UST_DISABLE
:
1229 return lttng_channel_disable(channel
);
1230 case LTTNG_UST_FLUSH_BUFFER
:
1231 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1238 int lttng_channel_release(int objd
)
1240 struct lttng_channel
*channel
= objd_private(objd
);
1243 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1247 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1248 .release
= lttng_channel_release
,
1249 .cmd
= lttng_channel_cmd
,
1253 * lttng_enabler_cmd - lttng control through object descriptors
1255 * @objd: the object descriptor
1258 * @uargs: UST arguments (internal)
1259 * @owner: objd owner
1261 * This object descriptor implements lttng commands:
1263 * Prepend a context field to each record of events of this
1266 * Enable recording for this enabler
1268 * Disable recording for this enabler
1270 * Attach a filter to an enabler.
1271 * LTTNG_UST_EXCLUSION
1272 * Attach exclusions to an enabler.
1275 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1276 union ust_args
*uargs
, void *owner
)
1278 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1281 case LTTNG_UST_CONTEXT
:
1282 return lttng_event_enabler_attach_context(enabler
,
1283 (struct lttng_ust_context
*) arg
);
1284 case LTTNG_UST_ENABLE
:
1285 return lttng_event_enabler_enable(enabler
);
1286 case LTTNG_UST_DISABLE
:
1287 return lttng_event_enabler_disable(enabler
);
1288 case LTTNG_UST_FILTER
:
1292 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1293 (struct lttng_ust_bytecode_node
*) arg
);
1298 case LTTNG_UST_EXCLUSION
:
1300 return lttng_event_enabler_attach_exclusion(enabler
,
1301 (struct lttng_ust_excluder_node
*) arg
);
1309 int lttng_event_enabler_release(int objd
)
1311 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1314 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1319 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1320 .release
= lttng_event_enabler_release
,
1321 .cmd
= lttng_event_enabler_cmd
,
1324 void lttng_ust_abi_exit(void)
1326 lttng_ust_abi_close_in_progress
= 1;
1328 objd_table_destroy();
1330 lttng_ust_abi_close_in_progress
= 0;