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 "tracepoint-internal.h"
61 #include "lttng-tracer.h"
62 #include "string-utils.h"
63 #include "ust-events-internal.h"
65 #define OBJ_NAME_LEN 16
67 static int lttng_ust_abi_close_in_progress
;
70 int lttng_abi_tracepoint_list(void *owner
);
72 int lttng_abi_tracepoint_field_list(void *owner
);
75 * Object descriptor table. Should be protected from concurrent access
79 struct lttng_ust_obj
{
83 const struct lttng_ust_objd_ops
*ops
;
85 int owner_ref
; /* has ref from owner */
87 char name
[OBJ_NAME_LEN
];
89 int freelist_next
; /* offset freelist. end is -1. */
93 struct lttng_ust_objd_table
{
94 struct lttng_ust_obj
*array
;
95 unsigned int len
, allocated_len
;
96 int freelist_head
; /* offset freelist head. end is -1 */
99 static struct lttng_ust_objd_table objd_table
= {
104 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
,
105 void *owner
, const char *name
)
107 struct lttng_ust_obj
*obj
;
109 if (objd_table
.freelist_head
!= -1) {
110 obj
= &objd_table
.array
[objd_table
.freelist_head
];
111 objd_table
.freelist_head
= obj
->u
.freelist_next
;
115 if (objd_table
.len
>= objd_table
.allocated_len
) {
116 unsigned int new_allocated_len
, old_allocated_len
;
117 struct lttng_ust_obj
*new_table
, *old_table
;
119 old_allocated_len
= objd_table
.allocated_len
;
120 old_table
= objd_table
.array
;
121 if (!old_allocated_len
)
122 new_allocated_len
= 1;
124 new_allocated_len
= old_allocated_len
<< 1;
125 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
128 memcpy(new_table
, old_table
,
129 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
131 objd_table
.array
= new_table
;
132 objd_table
.allocated_len
= new_allocated_len
;
134 obj
= &objd_table
.array
[objd_table
.len
];
137 obj
->u
.s
.private_data
= private_data
;
139 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
140 /* count == 2 : allocated + hold ref */
141 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
142 obj
->u
.s
.owner
= owner
;
143 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
144 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
145 return obj
- objd_table
.array
;
149 struct lttng_ust_obj
*_objd_get(int id
)
151 if (id
>= objd_table
.len
)
153 if (!objd_table
.array
[id
].u
.s
.f_count
)
155 return &objd_table
.array
[id
];
159 void *objd_private(int id
)
161 struct lttng_ust_obj
*obj
= _objd_get(id
);
163 return obj
->u
.s
.private_data
;
167 void objd_set_private(int id
, void *private_data
)
169 struct lttng_ust_obj
*obj
= _objd_get(id
);
171 obj
->u
.s
.private_data
= private_data
;
174 const struct lttng_ust_objd_ops
*objd_ops(int id
)
176 struct lttng_ust_obj
*obj
= _objd_get(id
);
184 void objd_free(int id
)
186 struct lttng_ust_obj
*obj
= _objd_get(id
);
189 obj
->u
.freelist_next
= objd_table
.freelist_head
;
190 objd_table
.freelist_head
= obj
- objd_table
.array
;
191 assert(obj
->u
.s
.f_count
== 1);
192 obj
->u
.s
.f_count
= 0; /* deallocated */
196 void objd_ref(int id
)
198 struct lttng_ust_obj
*obj
= _objd_get(id
);
203 int lttng_ust_objd_unref(int id
, int is_owner
)
205 struct lttng_ust_obj
*obj
= _objd_get(id
);
209 if (obj
->u
.s
.f_count
== 1) {
210 ERR("Reference counting error\n");
214 if (!obj
->u
.s
.owner_ref
) {
215 ERR("Error decrementing owner reference");
218 obj
->u
.s
.owner_ref
--;
220 if ((--obj
->u
.s
.f_count
) == 1) {
221 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
231 void objd_table_destroy(void)
235 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
236 struct lttng_ust_obj
*obj
;
241 if (!obj
->u
.s
.owner_ref
)
242 continue; /* only unref owner ref. */
243 (void) lttng_ust_objd_unref(i
, 1);
245 free(objd_table
.array
);
246 objd_table
.array
= NULL
;
248 objd_table
.allocated_len
= 0;
249 objd_table
.freelist_head
= -1;
252 const char *lttng_ust_obj_get_name(int id
)
254 struct lttng_ust_obj
*obj
= _objd_get(id
);
258 return obj
->u
.s
.name
;
261 void lttng_ust_objd_table_owner_cleanup(void *owner
)
265 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
266 struct lttng_ust_obj
*obj
;
272 continue; /* skip root handles */
273 if (!obj
->u
.s
.owner_ref
)
274 continue; /* only unref owner ref. */
275 if (obj
->u
.s
.owner
== owner
)
276 (void) lttng_ust_objd_unref(i
, 1);
281 * This is LTTng's own personal way to create an ABI for sessiond.
282 * We send commands over a socket.
285 static const struct lttng_ust_objd_ops lttng_ops
;
286 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
;
287 static const struct lttng_ust_objd_ops lttng_session_ops
;
288 static const struct lttng_ust_objd_ops lttng_channel_ops
;
289 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
;
290 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
;
291 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
292 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
294 int lttng_abi_create_root_handle(void)
298 /* root handles have NULL owners */
299 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
304 int lttng_is_channel_ready(struct lttng_channel
*lttng_chan
)
306 struct channel
*chan
;
307 unsigned int nr_streams
, exp_streams
;
309 chan
= lttng_chan
->chan
;
310 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->handle
);
311 exp_streams
= chan
->nr_streams
;
312 return nr_streams
== exp_streams
;
316 int lttng_abi_create_session(void *owner
)
318 struct lttng_session
*session
;
319 int session_objd
, ret
;
321 session
= lttng_session_create();
324 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
325 if (session_objd
< 0) {
329 session
->objd
= session_objd
;
330 session
->owner
= owner
;
334 lttng_session_destroy(session
);
339 long lttng_abi_tracer_version(int objd
,
340 struct lttng_ust_tracer_version
*v
)
342 v
->major
= LTTNG_UST_MAJOR_VERSION
;
343 v
->minor
= LTTNG_UST_MINOR_VERSION
;
344 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
349 int lttng_abi_event_notifier_send_fd(void *owner
, int event_notifier_notif_fd
)
351 struct lttng_event_notifier_group
*event_notifier_group
;
352 int event_notifier_group_objd
, ret
, fd_flag
, close_ret
;
354 event_notifier_group
= lttng_event_notifier_group_create();
355 if (!event_notifier_group
)
359 * Set this file descriptor as NON-BLOCKING.
361 fd_flag
= fcntl(event_notifier_notif_fd
, F_GETFL
);
363 fd_flag
|= O_NONBLOCK
;
365 ret
= fcntl(event_notifier_notif_fd
, F_SETFL
, fd_flag
);
371 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
372 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
373 if (event_notifier_group_objd
< 0) {
374 ret
= event_notifier_group_objd
;
378 event_notifier_group
->objd
= event_notifier_group_objd
;
379 event_notifier_group
->owner
= owner
;
380 event_notifier_group
->notification_fd
= event_notifier_notif_fd
;
382 return event_notifier_group_objd
;
385 lttng_event_notifier_group_destroy(event_notifier_group
);
387 close_ret
= close(event_notifier_notif_fd
);
396 long lttng_abi_add_context(int objd
,
397 struct lttng_ust_context
*context_param
,
398 union ust_args
*uargs
,
399 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
401 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
405 * lttng_cmd - lttng control through socket commands
407 * @objd: the object descriptor
410 * @uargs: UST arguments (internal)
413 * This descriptor implements lttng commands:
415 * Returns a LTTng trace session object descriptor
416 * LTTNG_UST_TRACER_VERSION
417 * Returns the LTTng kernel tracer version
418 * LTTNG_UST_TRACEPOINT_LIST
419 * Returns a file descriptor listing available tracepoints
420 * LTTNG_UST_TRACEPOINT_FIELD_LIST
421 * Returns a file descriptor listing available tracepoint fields
422 * LTTNG_UST_WAIT_QUIESCENT
423 * Returns after all previously running probes have completed
425 * The returned session will be deleted when its file descriptor is closed.
428 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
429 union ust_args
*uargs
, void *owner
)
432 case LTTNG_UST_SESSION
:
433 return lttng_abi_create_session(owner
);
434 case LTTNG_UST_TRACER_VERSION
:
435 return lttng_abi_tracer_version(objd
,
436 (struct lttng_ust_tracer_version
*) arg
);
437 case LTTNG_UST_TRACEPOINT_LIST
:
438 return lttng_abi_tracepoint_list(owner
);
439 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
440 return lttng_abi_tracepoint_field_list(owner
);
441 case LTTNG_UST_WAIT_QUIESCENT
:
442 lttng_ust_synchronize_trace();
444 case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE
:
445 return lttng_abi_event_notifier_send_fd(owner
,
446 uargs
->event_notifier_handle
.event_notifier_notif_fd
);
452 static const struct lttng_ust_objd_ops lttng_ops
= {
457 int lttng_abi_map_channel(int session_objd
,
458 struct lttng_ust_channel
*ust_chan
,
459 union ust_args
*uargs
,
462 struct lttng_session
*session
= objd_private(session_objd
);
463 const char *transport_name
;
464 const struct lttng_transport
*transport
;
465 const char *chan_name
;
467 struct lttng_ust_shm_handle
*channel_handle
;
468 struct lttng_channel
*lttng_chan
;
469 struct channel
*chan
;
470 struct lttng_ust_lib_ring_buffer_config
*config
;
475 enum lttng_ust_chan_type type
;
477 chan_data
= uargs
->channel
.chan_data
;
478 wakeup_fd
= uargs
->channel
.wakeup_fd
;
480 type
= ust_chan
->type
;
483 case LTTNG_UST_CHAN_PER_CPU
:
490 if (session
->been_active
) {
492 goto active
; /* Refuse to add channel to active session */
495 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
496 if (!channel_handle
) {
501 /* Ownership of chan_data and wakeup_fd taken by channel handle. */
502 uargs
->channel
.chan_data
= NULL
;
503 uargs
->channel
.wakeup_fd
= -1;
505 chan
= shmp(channel_handle
, channel_handle
->chan
);
507 chan
->handle
= channel_handle
;
508 config
= &chan
->backend
.config
;
509 lttng_chan
= channel_get_private(chan
);
515 /* Lookup transport name */
517 case LTTNG_UST_CHAN_PER_CPU
:
518 if (config
->output
== RING_BUFFER_MMAP
) {
519 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
520 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
521 transport_name
= "relay-overwrite-mmap";
523 transport_name
= "relay-overwrite-rt-mmap";
526 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
527 transport_name
= "relay-discard-mmap";
529 transport_name
= "relay-discard-rt-mmap";
536 chan_name
= "channel";
542 transport
= lttng_transport_find(transport_name
);
544 DBG("LTTng transport %s not found\n",
550 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
556 /* Initialize our lttng chan */
557 lttng_chan
->chan
= chan
;
558 lttng_chan
->tstate
= 1;
559 lttng_chan
->enabled
= 1;
560 lttng_chan
->ctx
= NULL
;
561 lttng_chan
->session
= session
;
562 lttng_chan
->ops
= &transport
->ops
;
563 memcpy(<tng_chan
->chan
->backend
.config
,
564 transport
->client_config
,
565 sizeof(lttng_chan
->chan
->backend
.config
));
566 cds_list_add(<tng_chan
->node
, &session
->chan_head
);
567 lttng_chan
->header_type
= 0;
568 lttng_chan
->handle
= channel_handle
;
569 lttng_chan
->type
= type
;
572 * We tolerate no failure path after channel creation. It will stay
573 * invariant for the rest of the session.
575 objd_set_private(chan_objd
, lttng_chan
);
576 lttng_chan
->objd
= chan_objd
;
577 /* The channel created holds a reference on the session */
578 objd_ref(session_objd
);
581 /* error path after channel was created */
585 channel_destroy(chan
, channel_handle
, 0);
595 * lttng_session_cmd - lttng session object command
600 * @uargs: UST arguments (internal)
603 * This descriptor implements lttng commands:
605 * Returns a LTTng channel object descriptor
607 * Enables tracing for a session (weak enable)
609 * Disables tracing for a session (strong disable)
611 * The returned channel will be deleted when its file descriptor is closed.
614 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
615 union ust_args
*uargs
, void *owner
)
617 struct lttng_session
*session
= objd_private(objd
);
620 case LTTNG_UST_CHANNEL
:
621 return lttng_abi_map_channel(objd
,
622 (struct lttng_ust_channel
*) arg
,
624 case LTTNG_UST_SESSION_START
:
625 case LTTNG_UST_ENABLE
:
626 return lttng_session_enable(session
);
627 case LTTNG_UST_SESSION_STOP
:
628 case LTTNG_UST_DISABLE
:
629 return lttng_session_disable(session
);
630 case LTTNG_UST_SESSION_STATEDUMP
:
631 return lttng_session_statedump(session
);
632 case LTTNG_UST_COUNTER
:
633 case LTTNG_UST_COUNTER_GLOBAL
:
634 case LTTNG_UST_COUNTER_CPU
:
635 /* Not implemented yet. */
643 * Called when the last file reference is dropped.
645 * Big fat note: channels and events are invariant for the whole session after
646 * their creation. So this session destruction also destroys all channel and
647 * event structures specific to this session (they are not destroyed when their
648 * individual file is released).
651 int lttng_release_session(int objd
)
653 struct lttng_session
*session
= objd_private(objd
);
656 lttng_session_destroy(session
);
663 static const struct lttng_ust_objd_ops lttng_session_ops
= {
664 .release
= lttng_release_session
,
665 .cmd
= lttng_session_cmd
,
668 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
669 void *owner
, struct lttng_ust_event_notifier
*event_notifier_param
,
670 enum lttng_enabler_format_type type
)
672 struct lttng_event_notifier_group
*event_notifier_group
=
673 objd_private(event_notifier_group_obj
);
674 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
675 int event_notifier_objd
, ret
;
677 event_notifier_param
->event
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
678 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
679 "event_notifier enabler");
680 if (event_notifier_objd
< 0) {
681 ret
= event_notifier_objd
;
685 event_notifier_enabler
= lttng_event_notifier_enabler_create(
686 event_notifier_group
, type
, event_notifier_param
);
687 if (!event_notifier_enabler
) {
689 goto event_notifier_error
;
692 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
693 /* The event_notifier holds a reference on the event_notifier group. */
694 objd_ref(event_notifier_enabler
->group
->objd
);
696 return event_notifier_objd
;
698 event_notifier_error
:
702 err
= lttng_ust_objd_unref(event_notifier_objd
, 1);
710 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
711 union ust_args
*uargs
, void *owner
)
713 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
715 case LTTNG_UST_FILTER
:
716 return lttng_event_notifier_enabler_attach_filter_bytecode(
717 event_notifier_enabler
,
718 (struct lttng_ust_bytecode_node
*) arg
);
719 case LTTNG_UST_EXCLUSION
:
720 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
721 (struct lttng_ust_excluder_node
*) arg
);
722 case LTTNG_UST_CAPTURE
:
723 return lttng_event_notifier_enabler_attach_capture_bytecode(
724 event_notifier_enabler
,
725 (struct lttng_ust_bytecode_node
*) arg
);
726 case LTTNG_UST_ENABLE
:
727 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
728 case LTTNG_UST_DISABLE
:
729 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
736 * lttng_event_notifier_group_error_counter_cmd - lttng event_notifier group error counter object command
741 * @uargs: UST arguments (internal)
744 * This descriptor implements lttng commands:
745 * LTTNG_UST_COUNTER_GLOBAL
746 * Return negative error code on error, 0 on success.
747 * LTTNG_UST_COUNTER_CPU
748 * Return negative error code on error, 0 on success.
751 long lttng_event_notifier_group_error_counter_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
752 union ust_args
*uargs
, void *owner
)
754 struct lttng_counter
*counter
= objd_private(objd
);
757 case LTTNG_UST_COUNTER_GLOBAL
:
758 return -EINVAL
; /* Unimplemented. */
759 case LTTNG_UST_COUNTER_CPU
:
761 struct lttng_ust_counter_cpu
*counter_cpu
=
762 (struct lttng_ust_counter_cpu
*)arg
;
763 return lttng_counter_set_cpu_shm(counter
->counter
,
764 counter_cpu
->cpu_nr
, uargs
->counter_shm
.shm_fd
);
771 int lttng_release_event_notifier_group_error_counter(int objd
)
773 struct lttng_counter
*counter
= objd_private(objd
);
776 return lttng_ust_objd_unref(counter
->event_notifier_group
->objd
, 0);
782 static const struct lttng_ust_objd_ops lttng_event_notifier_group_error_counter_ops
= {
783 .release
= lttng_release_event_notifier_group_error_counter
,
784 .cmd
= lttng_event_notifier_group_error_counter_cmd
,
788 int lttng_ust_event_notifier_group_create_error_counter(int event_notifier_group_objd
, void *owner
,
789 struct lttng_ust_counter_conf
*error_counter_conf
)
791 const char *counter_transport_name
;
792 struct lttng_event_notifier_group
*event_notifier_group
=
793 objd_private(event_notifier_group_objd
);
794 struct lttng_counter
*counter
;
795 int counter_objd
, ret
;
796 struct lttng_counter_dimension dimensions
[1];
799 if (event_notifier_group
->error_counter
)
802 if (error_counter_conf
->arithmetic
!= LTTNG_UST_COUNTER_ARITHMETIC_MODULAR
)
805 if (error_counter_conf
->number_dimensions
!= 1)
808 switch (error_counter_conf
->bitness
) {
809 case LTTNG_UST_COUNTER_BITNESS_64
:
810 counter_transport_name
= "counter-per-cpu-64-modular";
812 case LTTNG_UST_COUNTER_BITNESS_32
:
813 counter_transport_name
= "counter-per-cpu-32-modular";
819 counter_objd
= objd_alloc(NULL
, <tng_event_notifier_group_error_counter_ops
, owner
,
820 "event_notifier group error counter");
821 if (counter_objd
< 0) {
826 counter_len
= error_counter_conf
->dimensions
[0].size
;
827 dimensions
[0].size
= counter_len
;
828 dimensions
[0].underflow_index
= 0;
829 dimensions
[0].overflow_index
= 0;
830 dimensions
[0].has_underflow
= 0;
831 dimensions
[0].has_overflow
= 0;
833 counter
= lttng_ust_counter_create(counter_transport_name
, 1, dimensions
);
839 event_notifier_group
->error_counter_len
= counter_len
;
841 * store-release to publish error counter matches load-acquire
842 * in record_error. Ensures the counter is created and the
843 * error_counter_len is set before they are used.
844 * Currently a full memory barrier is used, which could be
845 * turned into acquire-release barriers.
848 CMM_STORE_SHARED(event_notifier_group
->error_counter
, counter
);
850 counter
->objd
= counter_objd
;
851 counter
->event_notifier_group
= event_notifier_group
; /* owner */
853 objd_set_private(counter_objd
, counter
);
854 /* The error counter holds a reference on the event_notifier group. */
855 objd_ref(event_notifier_group
->objd
);
863 err
= lttng_ust_objd_unref(counter_objd
, 1);
871 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
872 union ust_args
*uargs
, void *owner
)
875 case LTTNG_UST_EVENT_NOTIFIER_CREATE
:
877 struct lttng_ust_event_notifier
*event_notifier_param
=
878 (struct lttng_ust_event_notifier
*) arg
;
879 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
881 * If the event name is a star globbing pattern,
882 * we create the special star globbing enabler.
884 return lttng_ust_event_notifier_enabler_create(objd
,
885 owner
, event_notifier_param
,
886 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
888 return lttng_ust_event_notifier_enabler_create(objd
,
889 owner
, event_notifier_param
,
890 LTTNG_ENABLER_FORMAT_EVENT
);
893 case LTTNG_UST_COUNTER
:
895 struct lttng_ust_counter_conf
*counter_conf
=
896 (struct lttng_ust_counter_conf
*) uargs
->counter
.counter_data
;
897 return lttng_ust_event_notifier_group_create_error_counter(
898 objd
, owner
, counter_conf
);
906 int lttng_event_notifier_enabler_release(int objd
)
908 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
910 if (event_notifier_enabler
)
911 return lttng_ust_objd_unref(event_notifier_enabler
->group
->objd
, 0);
915 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
= {
916 .release
= lttng_event_notifier_enabler_release
,
917 .cmd
= lttng_event_notifier_enabler_cmd
,
921 int lttng_release_event_notifier_group(int objd
)
923 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
925 if (event_notifier_group
) {
926 lttng_event_notifier_group_destroy(event_notifier_group
);
933 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
= {
934 .release
= lttng_release_event_notifier_group
,
935 .cmd
= lttng_event_notifier_group_cmd
,
939 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
940 union ust_args
*uargs
, void *owner
)
942 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
943 struct lttng_ust_tracepoint_iter
*tp
=
944 (struct lttng_ust_tracepoint_iter
*) arg
;
945 struct lttng_ust_tracepoint_iter
*iter
;
948 case LTTNG_UST_TRACEPOINT_LIST_GET
:
950 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
952 return -LTTNG_UST_ERR_NOENT
;
953 memcpy(tp
, iter
, sizeof(*tp
));
962 int lttng_abi_tracepoint_list(void *owner
)
965 struct lttng_ust_tracepoint_list
*list
;
967 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
972 list
= zmalloc(sizeof(*list
));
977 objd_set_private(list_objd
, list
);
979 /* populate list by walking on all registered probes. */
980 ret
= lttng_probes_get_event_list(list
);
992 err
= lttng_ust_objd_unref(list_objd
, 1);
1000 int lttng_release_tracepoint_list(int objd
)
1002 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
1005 lttng_probes_prune_event_list(list
);
1013 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
1014 .release
= lttng_release_tracepoint_list
,
1015 .cmd
= lttng_tracepoint_list_cmd
,
1019 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
1020 unsigned long arg
, union ust_args
*uargs
, void *owner
)
1022 struct lttng_ust_field_list
*list
= objd_private(objd
);
1023 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
1024 struct lttng_ust_field_iter
*iter
;
1027 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
1029 iter
= lttng_ust_field_list_get_iter_next(list
);
1031 return -LTTNG_UST_ERR_NOENT
;
1032 memcpy(tp
, iter
, sizeof(*tp
));
1041 int lttng_abi_tracepoint_field_list(void *owner
)
1044 struct lttng_ust_field_list
*list
;
1046 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
1048 if (list_objd
< 0) {
1052 list
= zmalloc(sizeof(*list
));
1057 objd_set_private(list_objd
, list
);
1059 /* populate list by walking on all registered probes. */
1060 ret
= lttng_probes_get_field_list(list
);
1072 err
= lttng_ust_objd_unref(list_objd
, 1);
1080 int lttng_release_tracepoint_field_list(int objd
)
1082 struct lttng_ust_field_list
*list
= objd_private(objd
);
1085 lttng_probes_prune_field_list(list
);
1093 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
1094 .release
= lttng_release_tracepoint_field_list
,
1095 .cmd
= lttng_tracepoint_field_list_cmd
,
1099 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
1100 union ust_args
*uargs
, void *owner
)
1102 struct lttng_channel
*channel
= objd_private(channel_objd
);
1105 ret
= channel_handle_add_stream(channel
->handle
,
1106 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
1107 info
->stream_nr
, info
->len
);
1109 goto error_add_stream
;
1110 /* Take ownership of shm_fd and wakeup_fd. */
1111 uargs
->stream
.shm_fd
= -1;
1112 uargs
->stream
.wakeup_fd
= -1;
1121 int lttng_abi_create_event_enabler(int channel_objd
,
1122 struct lttng_ust_event
*event_param
,
1124 enum lttng_enabler_format_type format_type
)
1126 struct lttng_channel
*channel
= objd_private(channel_objd
);
1127 struct lttng_event_enabler
*enabler
;
1128 int event_objd
, ret
;
1130 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1131 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
1133 if (event_objd
< 0) {
1138 * We tolerate no failure path after event creation. It will stay
1139 * invariant for the rest of the session.
1141 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1146 objd_set_private(event_objd
, enabler
);
1147 /* The event holds a reference on the channel */
1148 objd_ref(channel_objd
);
1155 err
= lttng_ust_objd_unref(event_objd
, 1);
1163 * lttng_channel_cmd - lttng control through object descriptors
1165 * @objd: the object descriptor
1168 * @uargs: UST arguments (internal)
1169 * @owner: objd owner
1171 * This object descriptor implements lttng commands:
1173 * Returns an event stream object descriptor or failure.
1174 * (typically, one event stream records events from one CPU)
1176 * Returns an event object descriptor or failure.
1178 * Prepend a context field to each event in the channel
1180 * Enable recording for events in this channel (weak enable)
1182 * Disable recording for events in this channel (strong disable)
1184 * Channel and event file descriptors also hold a reference on the session.
1187 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1188 union ust_args
*uargs
, void *owner
)
1190 struct lttng_channel
*channel
= objd_private(objd
);
1192 if (cmd
!= LTTNG_UST_STREAM
) {
1194 * Check if channel received all streams.
1196 if (!lttng_is_channel_ready(channel
))
1201 case LTTNG_UST_STREAM
:
1203 struct lttng_ust_stream
*stream
;
1205 stream
= (struct lttng_ust_stream
*) arg
;
1206 /* stream used as output */
1207 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1209 case LTTNG_UST_EVENT
:
1211 struct lttng_ust_event
*event_param
=
1212 (struct lttng_ust_event
*) arg
;
1214 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1216 * If the event name is a star globbing pattern,
1217 * we create the special star globbing enabler.
1219 return lttng_abi_create_event_enabler(objd
, event_param
,
1220 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1222 return lttng_abi_create_event_enabler(objd
, event_param
,
1223 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1226 case LTTNG_UST_CONTEXT
:
1227 return lttng_abi_add_context(objd
,
1228 (struct lttng_ust_context
*) arg
, uargs
,
1229 &channel
->ctx
, channel
->session
);
1230 case LTTNG_UST_ENABLE
:
1231 return lttng_channel_enable(channel
);
1232 case LTTNG_UST_DISABLE
:
1233 return lttng_channel_disable(channel
);
1234 case LTTNG_UST_FLUSH_BUFFER
:
1235 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1242 int lttng_channel_release(int objd
)
1244 struct lttng_channel
*channel
= objd_private(objd
);
1247 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1251 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1252 .release
= lttng_channel_release
,
1253 .cmd
= lttng_channel_cmd
,
1257 * lttng_enabler_cmd - lttng control through object descriptors
1259 * @objd: the object descriptor
1262 * @uargs: UST arguments (internal)
1263 * @owner: objd owner
1265 * This object descriptor implements lttng commands:
1267 * Prepend a context field to each record of events of this
1270 * Enable recording for this enabler
1272 * Disable recording for this enabler
1274 * Attach a filter to an enabler.
1275 * LTTNG_UST_EXCLUSION
1276 * Attach exclusions to an enabler.
1279 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1280 union ust_args
*uargs
, void *owner
)
1282 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1285 case LTTNG_UST_CONTEXT
:
1286 return lttng_event_enabler_attach_context(enabler
,
1287 (struct lttng_ust_context
*) arg
);
1288 case LTTNG_UST_ENABLE
:
1289 return lttng_event_enabler_enable(enabler
);
1290 case LTTNG_UST_DISABLE
:
1291 return lttng_event_enabler_disable(enabler
);
1292 case LTTNG_UST_FILTER
:
1296 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1297 (struct lttng_ust_bytecode_node
*) arg
);
1302 case LTTNG_UST_EXCLUSION
:
1304 return lttng_event_enabler_attach_exclusion(enabler
,
1305 (struct lttng_ust_excluder_node
*) arg
);
1313 int lttng_event_enabler_release(int objd
)
1315 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1318 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1323 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1324 .release
= lttng_event_enabler_release
,
1325 .cmd
= lttng_event_enabler_cmd
,
1328 void lttng_ust_abi_exit(void)
1330 lttng_ust_abi_close_in_progress
= 1;
1332 objd_table_destroy();
1334 lttng_ust_abi_close_in_progress
= 0;