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 "lttng-tracer.h"
60 #include "string-utils.h"
61 #include "ust-events-internal.h"
63 #define OBJ_NAME_LEN 16
65 static int lttng_ust_abi_close_in_progress
;
68 int lttng_abi_tracepoint_list(void *owner
);
70 int lttng_abi_tracepoint_field_list(void *owner
);
73 * Object descriptor table. Should be protected from concurrent access
77 struct lttng_ust_obj
{
81 const struct lttng_ust_objd_ops
*ops
;
83 int owner_ref
; /* has ref from owner */
85 char name
[OBJ_NAME_LEN
];
87 int freelist_next
; /* offset freelist. end is -1. */
91 struct lttng_ust_objd_table
{
92 struct lttng_ust_obj
*array
;
93 unsigned int len
, allocated_len
;
94 int freelist_head
; /* offset freelist head. end is -1 */
97 static struct lttng_ust_objd_table objd_table
= {
102 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
,
103 void *owner
, const char *name
)
105 struct lttng_ust_obj
*obj
;
107 if (objd_table
.freelist_head
!= -1) {
108 obj
= &objd_table
.array
[objd_table
.freelist_head
];
109 objd_table
.freelist_head
= obj
->u
.freelist_next
;
113 if (objd_table
.len
>= objd_table
.allocated_len
) {
114 unsigned int new_allocated_len
, old_allocated_len
;
115 struct lttng_ust_obj
*new_table
, *old_table
;
117 old_allocated_len
= objd_table
.allocated_len
;
118 old_table
= objd_table
.array
;
119 if (!old_allocated_len
)
120 new_allocated_len
= 1;
122 new_allocated_len
= old_allocated_len
<< 1;
123 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
126 memcpy(new_table
, old_table
,
127 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
129 objd_table
.array
= new_table
;
130 objd_table
.allocated_len
= new_allocated_len
;
132 obj
= &objd_table
.array
[objd_table
.len
];
135 obj
->u
.s
.private_data
= private_data
;
137 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
138 /* count == 2 : allocated + hold ref */
139 obj
->u
.s
.owner_ref
= 1; /* One owner reference */
140 obj
->u
.s
.owner
= owner
;
141 strncpy(obj
->u
.s
.name
, name
, OBJ_NAME_LEN
);
142 obj
->u
.s
.name
[OBJ_NAME_LEN
- 1] = '\0';
143 return obj
- objd_table
.array
;
147 struct lttng_ust_obj
*_objd_get(int id
)
149 if (id
>= objd_table
.len
)
151 if (!objd_table
.array
[id
].u
.s
.f_count
)
153 return &objd_table
.array
[id
];
157 void *objd_private(int id
)
159 struct lttng_ust_obj
*obj
= _objd_get(id
);
161 return obj
->u
.s
.private_data
;
165 void objd_set_private(int id
, void *private_data
)
167 struct lttng_ust_obj
*obj
= _objd_get(id
);
169 obj
->u
.s
.private_data
= private_data
;
172 const struct lttng_ust_objd_ops
*objd_ops(int id
)
174 struct lttng_ust_obj
*obj
= _objd_get(id
);
182 void objd_free(int id
)
184 struct lttng_ust_obj
*obj
= _objd_get(id
);
187 obj
->u
.freelist_next
= objd_table
.freelist_head
;
188 objd_table
.freelist_head
= obj
- objd_table
.array
;
189 assert(obj
->u
.s
.f_count
== 1);
190 obj
->u
.s
.f_count
= 0; /* deallocated */
194 void objd_ref(int id
)
196 struct lttng_ust_obj
*obj
= _objd_get(id
);
201 int lttng_ust_objd_unref(int id
, int is_owner
)
203 struct lttng_ust_obj
*obj
= _objd_get(id
);
207 if (obj
->u
.s
.f_count
== 1) {
208 ERR("Reference counting error\n");
212 if (!obj
->u
.s
.owner_ref
) {
213 ERR("Error decrementing owner reference");
216 obj
->u
.s
.owner_ref
--;
218 if ((--obj
->u
.s
.f_count
) == 1) {
219 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
229 void objd_table_destroy(void)
233 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
234 struct lttng_ust_obj
*obj
;
239 if (!obj
->u
.s
.owner_ref
)
240 continue; /* only unref owner ref. */
241 (void) lttng_ust_objd_unref(i
, 1);
243 free(objd_table
.array
);
244 objd_table
.array
= NULL
;
246 objd_table
.allocated_len
= 0;
247 objd_table
.freelist_head
= -1;
250 const char *lttng_ust_obj_get_name(int id
)
252 struct lttng_ust_obj
*obj
= _objd_get(id
);
256 return obj
->u
.s
.name
;
259 void lttng_ust_objd_table_owner_cleanup(void *owner
)
263 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
264 struct lttng_ust_obj
*obj
;
270 continue; /* skip root handles */
271 if (!obj
->u
.s
.owner_ref
)
272 continue; /* only unref owner ref. */
273 if (obj
->u
.s
.owner
== owner
)
274 (void) lttng_ust_objd_unref(i
, 1);
279 * This is LTTng's own personal way to create an ABI for sessiond.
280 * We send commands over a socket.
283 static const struct lttng_ust_objd_ops lttng_ops
;
284 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
;
285 static const struct lttng_ust_objd_ops lttng_session_ops
;
286 static const struct lttng_ust_objd_ops lttng_channel_ops
;
287 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
;
288 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
;
289 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
290 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
292 int lttng_abi_create_root_handle(void)
296 /* root handles have NULL owners */
297 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
, "root");
302 int lttng_is_channel_ready(struct lttng_channel
*lttng_chan
)
304 struct channel
*chan
;
305 unsigned int nr_streams
, exp_streams
;
307 chan
= lttng_chan
->chan
;
308 nr_streams
= channel_handle_get_nr_streams(lttng_chan
->handle
);
309 exp_streams
= chan
->nr_streams
;
310 return nr_streams
== exp_streams
;
314 int lttng_abi_create_session(void *owner
)
316 struct lttng_session
*session
;
317 int session_objd
, ret
;
319 session
= lttng_session_create();
322 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
, "session");
323 if (session_objd
< 0) {
327 session
->objd
= session_objd
;
328 session
->owner
= owner
;
332 lttng_session_destroy(session
);
337 long lttng_abi_tracer_version(int objd
,
338 struct lttng_ust_tracer_version
*v
)
340 v
->major
= LTTNG_UST_MAJOR_VERSION
;
341 v
->minor
= LTTNG_UST_MINOR_VERSION
;
342 v
->patchlevel
= LTTNG_UST_PATCHLEVEL_VERSION
;
347 int lttng_abi_event_notifier_send_fd(void *owner
, int event_notifier_notif_fd
)
349 struct lttng_event_notifier_group
*event_notifier_group
;
350 int event_notifier_group_objd
, ret
, fd_flag
, close_ret
;
352 event_notifier_group
= lttng_event_notifier_group_create();
353 if (!event_notifier_group
)
357 * Set this file descriptor as NON-BLOCKING.
359 fd_flag
= fcntl(event_notifier_notif_fd
, F_GETFL
);
361 fd_flag
|= O_NONBLOCK
;
363 ret
= fcntl(event_notifier_notif_fd
, F_SETFL
, fd_flag
);
369 event_notifier_group_objd
= objd_alloc(event_notifier_group
,
370 <tng_event_notifier_group_ops
, owner
, "event_notifier_group");
371 if (event_notifier_group_objd
< 0) {
372 ret
= event_notifier_group_objd
;
376 event_notifier_group
->objd
= event_notifier_group_objd
;
377 event_notifier_group
->owner
= owner
;
378 event_notifier_group
->notification_fd
= event_notifier_notif_fd
;
380 return event_notifier_group_objd
;
383 lttng_event_notifier_group_destroy(event_notifier_group
);
385 close_ret
= close(event_notifier_notif_fd
);
394 long lttng_abi_add_context(int objd
,
395 struct lttng_ust_context
*context_param
,
396 union ust_args
*uargs
,
397 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
399 return lttng_attach_context(context_param
, uargs
, ctx
, session
);
403 * lttng_cmd - lttng control through socket commands
405 * @objd: the object descriptor
408 * @uargs: UST arguments (internal)
411 * This descriptor implements lttng commands:
413 * Returns a LTTng trace session object descriptor
414 * LTTNG_UST_TRACER_VERSION
415 * Returns the LTTng kernel tracer version
416 * LTTNG_UST_TRACEPOINT_LIST
417 * Returns a file descriptor listing available tracepoints
418 * LTTNG_UST_TRACEPOINT_FIELD_LIST
419 * Returns a file descriptor listing available tracepoint fields
420 * LTTNG_UST_WAIT_QUIESCENT
421 * Returns after all previously running probes have completed
423 * The returned session will be deleted when its file descriptor is closed.
426 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
427 union ust_args
*uargs
, void *owner
)
430 case LTTNG_UST_SESSION
:
431 return lttng_abi_create_session(owner
);
432 case LTTNG_UST_TRACER_VERSION
:
433 return lttng_abi_tracer_version(objd
,
434 (struct lttng_ust_tracer_version
*) arg
);
435 case LTTNG_UST_TRACEPOINT_LIST
:
436 return lttng_abi_tracepoint_list(owner
);
437 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
438 return lttng_abi_tracepoint_field_list(owner
);
439 case LTTNG_UST_WAIT_QUIESCENT
:
442 case LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE
:
443 return lttng_abi_event_notifier_send_fd(owner
,
444 uargs
->event_notifier_handle
.event_notifier_notif_fd
);
450 static const struct lttng_ust_objd_ops lttng_ops
= {
454 int lttng_abi_map_channel(int session_objd
,
455 struct lttng_ust_channel
*ust_chan
,
456 union ust_args
*uargs
,
459 struct lttng_session
*session
= objd_private(session_objd
);
460 const char *transport_name
;
461 const struct lttng_transport
*transport
;
462 const char *chan_name
;
464 struct lttng_ust_shm_handle
*channel_handle
;
465 struct lttng_channel
*lttng_chan
;
466 struct channel
*chan
;
467 struct lttng_ust_lib_ring_buffer_config
*config
;
472 enum lttng_ust_chan_type type
;
474 chan_data
= uargs
->channel
.chan_data
;
475 wakeup_fd
= uargs
->channel
.wakeup_fd
;
477 type
= ust_chan
->type
;
480 case LTTNG_UST_CHAN_PER_CPU
:
487 if (session
->been_active
) {
489 goto active
; /* Refuse to add channel to active session */
492 channel_handle
= channel_handle_create(chan_data
, len
, wakeup_fd
);
493 if (!channel_handle
) {
498 chan
= shmp(channel_handle
, channel_handle
->chan
);
500 chan
->handle
= channel_handle
;
501 config
= &chan
->backend
.config
;
502 lttng_chan
= channel_get_private(chan
);
508 /* Lookup transport name */
510 case LTTNG_UST_CHAN_PER_CPU
:
511 if (config
->output
== RING_BUFFER_MMAP
) {
512 if (config
->mode
== RING_BUFFER_OVERWRITE
) {
513 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
514 transport_name
= "relay-overwrite-mmap";
516 transport_name
= "relay-overwrite-rt-mmap";
519 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
) {
520 transport_name
= "relay-discard-mmap";
522 transport_name
= "relay-discard-rt-mmap";
529 chan_name
= "channel";
535 transport
= lttng_transport_find(transport_name
);
537 DBG("LTTng transport %s not found\n",
543 chan_objd
= objd_alloc(NULL
, <tng_channel_ops
, owner
, chan_name
);
549 /* Initialize our lttng chan */
550 lttng_chan
->chan
= chan
;
551 lttng_chan
->tstate
= 1;
552 lttng_chan
->enabled
= 1;
553 lttng_chan
->ctx
= NULL
;
554 lttng_chan
->session
= session
;
555 lttng_chan
->ops
= &transport
->ops
;
556 memcpy(<tng_chan
->chan
->backend
.config
,
557 transport
->client_config
,
558 sizeof(lttng_chan
->chan
->backend
.config
));
559 cds_list_add(<tng_chan
->node
, &session
->chan_head
);
560 lttng_chan
->header_type
= 0;
561 lttng_chan
->handle
= channel_handle
;
562 lttng_chan
->type
= type
;
565 * We tolerate no failure path after channel creation. It will stay
566 * invariant for the rest of the session.
568 objd_set_private(chan_objd
, lttng_chan
);
569 lttng_chan
->objd
= chan_objd
;
570 /* The channel created holds a reference on the session */
571 objd_ref(session_objd
);
574 /* error path after channel was created */
578 channel_destroy(chan
, channel_handle
, 0);
582 * error path before channel creation (owning chan_data and
591 lttng_ust_lock_fd_tracker();
592 close_ret
= close(wakeup_fd
);
593 lttng_ust_unlock_fd_tracker();
603 * lttng_session_cmd - lttng session object command
608 * @uargs: UST arguments (internal)
611 * This descriptor implements lttng commands:
613 * Returns a LTTng channel object descriptor
615 * Enables tracing for a session (weak enable)
617 * Disables tracing for a session (strong disable)
619 * The returned channel will be deleted when its file descriptor is closed.
622 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
623 union ust_args
*uargs
, void *owner
)
625 struct lttng_session
*session
= objd_private(objd
);
628 case LTTNG_UST_CHANNEL
:
629 return lttng_abi_map_channel(objd
,
630 (struct lttng_ust_channel
*) arg
,
632 case LTTNG_UST_SESSION_START
:
633 case LTTNG_UST_ENABLE
:
634 return lttng_session_enable(session
);
635 case LTTNG_UST_SESSION_STOP
:
636 case LTTNG_UST_DISABLE
:
637 return lttng_session_disable(session
);
638 case LTTNG_UST_SESSION_STATEDUMP
:
639 return lttng_session_statedump(session
);
646 * Called when the last file reference is dropped.
648 * Big fat note: channels and events are invariant for the whole session after
649 * their creation. So this session destruction also destroys all channel and
650 * event structures specific to this session (they are not destroyed when their
651 * individual file is released).
654 int lttng_release_session(int objd
)
656 struct lttng_session
*session
= objd_private(objd
);
659 lttng_session_destroy(session
);
666 static const struct lttng_ust_objd_ops lttng_session_ops
= {
667 .release
= lttng_release_session
,
668 .cmd
= lttng_session_cmd
,
671 static int lttng_ust_event_notifier_enabler_create(int event_notifier_group_obj
,
672 void *owner
, struct lttng_ust_event_notifier
*event_notifier_param
,
673 enum lttng_enabler_format_type type
)
675 struct lttng_event_notifier_group
*event_notifier_group
=
676 objd_private(event_notifier_group_obj
);
677 struct lttng_event_notifier_enabler
*event_notifier_enabler
;
678 int event_notifier_objd
, ret
;
680 event_notifier_param
->event
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
681 event_notifier_objd
= objd_alloc(NULL
, <tng_event_notifier_enabler_ops
, owner
,
682 "event_notifier enabler");
683 if (event_notifier_objd
< 0) {
684 ret
= event_notifier_objd
;
688 event_notifier_enabler
= lttng_event_notifier_enabler_create(
689 event_notifier_group
, type
, event_notifier_param
);
690 if (!event_notifier_enabler
) {
692 goto event_notifier_error
;
695 objd_set_private(event_notifier_objd
, event_notifier_enabler
);
696 /* The event_notifier holds a reference on the event_notifier group. */
697 objd_ref(event_notifier_enabler
->group
->objd
);
699 return event_notifier_objd
;
701 event_notifier_error
:
705 err
= lttng_ust_objd_unref(event_notifier_objd
, 1);
713 long lttng_event_notifier_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
714 union ust_args
*uargs
, void *owner
)
716 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
718 case LTTNG_UST_FILTER
:
719 return lttng_event_notifier_enabler_attach_bytecode(event_notifier_enabler
,
720 (struct lttng_ust_filter_bytecode_node
*) arg
);
721 case LTTNG_UST_EXCLUSION
:
722 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
723 (struct lttng_ust_excluder_node
*) arg
);
724 case LTTNG_UST_ENABLE
:
725 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
726 case LTTNG_UST_DISABLE
:
727 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
734 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
735 union ust_args
*uargs
, void *owner
)
738 case LTTNG_UST_EVENT_NOTIFIER_CREATE
:
740 struct lttng_ust_event_notifier
*event_notifier_param
=
741 (struct lttng_ust_event_notifier
*) arg
;
742 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
744 * If the event name is a star globbing pattern,
745 * we create the special star globbing enabler.
747 return lttng_ust_event_notifier_enabler_create(objd
,
748 owner
, event_notifier_param
,
749 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
751 return lttng_ust_event_notifier_enabler_create(objd
,
752 owner
, event_notifier_param
,
753 LTTNG_ENABLER_FORMAT_EVENT
);
762 int lttng_event_notifier_enabler_release(int objd
)
764 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
766 if (event_notifier_enabler
)
767 return lttng_ust_objd_unref(event_notifier_enabler
->group
->objd
, 0);
771 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
= {
772 .release
= lttng_event_notifier_enabler_release
,
773 .cmd
= lttng_event_notifier_enabler_cmd
,
777 int lttng_release_event_notifier_group(int objd
)
779 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
781 if (event_notifier_group
) {
782 lttng_event_notifier_group_destroy(event_notifier_group
);
789 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
= {
790 .release
= lttng_release_event_notifier_group
,
791 .cmd
= lttng_event_notifier_group_cmd
,
795 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
796 union ust_args
*uargs
, void *owner
)
798 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
799 struct lttng_ust_tracepoint_iter
*tp
=
800 (struct lttng_ust_tracepoint_iter
*) arg
;
801 struct lttng_ust_tracepoint_iter
*iter
;
804 case LTTNG_UST_TRACEPOINT_LIST_GET
:
806 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
808 return -LTTNG_UST_ERR_NOENT
;
809 memcpy(tp
, iter
, sizeof(*tp
));
818 int lttng_abi_tracepoint_list(void *owner
)
821 struct lttng_ust_tracepoint_list
*list
;
823 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
828 list
= zmalloc(sizeof(*list
));
833 objd_set_private(list_objd
, list
);
835 /* populate list by walking on all registered probes. */
836 ret
= lttng_probes_get_event_list(list
);
848 err
= lttng_ust_objd_unref(list_objd
, 1);
856 int lttng_release_tracepoint_list(int objd
)
858 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
861 lttng_probes_prune_event_list(list
);
869 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
870 .release
= lttng_release_tracepoint_list
,
871 .cmd
= lttng_tracepoint_list_cmd
,
875 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
876 unsigned long arg
, union ust_args
*uargs
, void *owner
)
878 struct lttng_ust_field_list
*list
= objd_private(objd
);
879 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
880 struct lttng_ust_field_iter
*iter
;
883 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
885 iter
= lttng_ust_field_list_get_iter_next(list
);
887 return -LTTNG_UST_ERR_NOENT
;
888 memcpy(tp
, iter
, sizeof(*tp
));
897 int lttng_abi_tracepoint_field_list(void *owner
)
900 struct lttng_ust_field_list
*list
;
902 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
908 list
= zmalloc(sizeof(*list
));
913 objd_set_private(list_objd
, list
);
915 /* populate list by walking on all registered probes. */
916 ret
= lttng_probes_get_field_list(list
);
928 err
= lttng_ust_objd_unref(list_objd
, 1);
936 int lttng_release_tracepoint_field_list(int objd
)
938 struct lttng_ust_field_list
*list
= objd_private(objd
);
941 lttng_probes_prune_field_list(list
);
949 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
950 .release
= lttng_release_tracepoint_field_list
,
951 .cmd
= lttng_tracepoint_field_list_cmd
,
955 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
956 union ust_args
*uargs
, void *owner
)
958 struct lttng_channel
*channel
= objd_private(channel_objd
);
961 ret
= channel_handle_add_stream(channel
->handle
,
962 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
963 info
->stream_nr
, info
->len
);
965 goto error_add_stream
;
974 int lttng_abi_create_event_enabler(int channel_objd
,
975 struct lttng_ust_event
*event_param
,
977 enum lttng_enabler_format_type format_type
)
979 struct lttng_channel
*channel
= objd_private(channel_objd
);
980 struct lttng_event_enabler
*enabler
;
983 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
984 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
986 if (event_objd
< 0) {
991 * We tolerate no failure path after event creation. It will stay
992 * invariant for the rest of the session.
994 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
999 objd_set_private(event_objd
, enabler
);
1000 /* The event holds a reference on the channel */
1001 objd_ref(channel_objd
);
1008 err
= lttng_ust_objd_unref(event_objd
, 1);
1016 * lttng_channel_cmd - lttng control through object descriptors
1018 * @objd: the object descriptor
1021 * @uargs: UST arguments (internal)
1022 * @owner: objd owner
1024 * This object descriptor implements lttng commands:
1026 * Returns an event stream object descriptor or failure.
1027 * (typically, one event stream records events from one CPU)
1029 * Returns an event object descriptor or failure.
1031 * Prepend a context field to each event in the channel
1033 * Enable recording for events in this channel (weak enable)
1035 * Disable recording for events in this channel (strong disable)
1037 * Channel and event file descriptors also hold a reference on the session.
1040 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1041 union ust_args
*uargs
, void *owner
)
1043 struct lttng_channel
*channel
= objd_private(objd
);
1045 if (cmd
!= LTTNG_UST_STREAM
) {
1047 * Check if channel received all streams.
1049 if (!lttng_is_channel_ready(channel
))
1054 case LTTNG_UST_STREAM
:
1056 struct lttng_ust_stream
*stream
;
1058 stream
= (struct lttng_ust_stream
*) arg
;
1059 /* stream used as output */
1060 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1062 case LTTNG_UST_EVENT
:
1064 struct lttng_ust_event
*event_param
=
1065 (struct lttng_ust_event
*) arg
;
1067 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1069 * If the event name is a star globbing pattern,
1070 * we create the special star globbing enabler.
1072 return lttng_abi_create_event_enabler(objd
, event_param
,
1073 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1075 return lttng_abi_create_event_enabler(objd
, event_param
,
1076 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1079 case LTTNG_UST_CONTEXT
:
1080 return lttng_abi_add_context(objd
,
1081 (struct lttng_ust_context
*) arg
, uargs
,
1082 &channel
->ctx
, channel
->session
);
1083 case LTTNG_UST_ENABLE
:
1084 return lttng_channel_enable(channel
);
1085 case LTTNG_UST_DISABLE
:
1086 return lttng_channel_disable(channel
);
1087 case LTTNG_UST_FLUSH_BUFFER
:
1088 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1095 int lttng_channel_release(int objd
)
1097 struct lttng_channel
*channel
= objd_private(objd
);
1100 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1104 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1105 .release
= lttng_channel_release
,
1106 .cmd
= lttng_channel_cmd
,
1110 * lttng_enabler_cmd - lttng control through object descriptors
1112 * @objd: the object descriptor
1115 * @uargs: UST arguments (internal)
1116 * @owner: objd owner
1118 * This object descriptor implements lttng commands:
1120 * Prepend a context field to each record of events of this
1123 * Enable recording for this enabler
1125 * Disable recording for this enabler
1127 * Attach a filter to an enabler.
1128 * LTTNG_UST_EXCLUSION
1129 * Attach exclusions to an enabler.
1132 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1133 union ust_args
*uargs
, void *owner
)
1135 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1138 case LTTNG_UST_CONTEXT
:
1139 return lttng_event_enabler_attach_context(enabler
,
1140 (struct lttng_ust_context
*) arg
);
1141 case LTTNG_UST_ENABLE
:
1142 return lttng_event_enabler_enable(enabler
);
1143 case LTTNG_UST_DISABLE
:
1144 return lttng_event_enabler_disable(enabler
);
1145 case LTTNG_UST_FILTER
:
1149 ret
= lttng_event_enabler_attach_bytecode(enabler
,
1150 (struct lttng_ust_filter_bytecode_node
*) arg
);
1155 case LTTNG_UST_EXCLUSION
:
1157 return lttng_event_enabler_attach_exclusion(enabler
,
1158 (struct lttng_ust_excluder_node
*) arg
);
1166 int lttng_event_enabler_release(int objd
)
1168 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1171 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1176 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1177 .release
= lttng_event_enabler_release
,
1178 .cmd
= lttng_event_enabler_cmd
,
1181 void lttng_ust_abi_exit(void)
1183 lttng_ust_abi_close_in_progress
= 1;
1185 objd_table_destroy();
1187 lttng_ust_abi_close_in_progress
= 0;