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_filter_bytecode(
720 event_notifier_enabler
,
721 (struct lttng_ust_bytecode_node
*) arg
);
722 case LTTNG_UST_EXCLUSION
:
723 return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler
,
724 (struct lttng_ust_excluder_node
*) arg
);
725 case LTTNG_UST_CAPTURE
:
726 return lttng_event_notifier_enabler_attach_capture_bytecode(
727 event_notifier_enabler
,
728 (struct lttng_ust_bytecode_node
*) arg
);
729 case LTTNG_UST_ENABLE
:
730 return lttng_event_notifier_enabler_enable(event_notifier_enabler
);
731 case LTTNG_UST_DISABLE
:
732 return lttng_event_notifier_enabler_disable(event_notifier_enabler
);
739 long lttng_event_notifier_group_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
740 union ust_args
*uargs
, void *owner
)
743 case LTTNG_UST_EVENT_NOTIFIER_CREATE
:
745 struct lttng_ust_event_notifier
*event_notifier_param
=
746 (struct lttng_ust_event_notifier
*) arg
;
747 if (strutils_is_star_glob_pattern(event_notifier_param
->event
.name
)) {
749 * If the event name is a star globbing pattern,
750 * we create the special star globbing enabler.
752 return lttng_ust_event_notifier_enabler_create(objd
,
753 owner
, event_notifier_param
,
754 LTTNG_ENABLER_FORMAT_STAR_GLOB
);
756 return lttng_ust_event_notifier_enabler_create(objd
,
757 owner
, event_notifier_param
,
758 LTTNG_ENABLER_FORMAT_EVENT
);
767 int lttng_event_notifier_enabler_release(int objd
)
769 struct lttng_event_notifier_enabler
*event_notifier_enabler
= objd_private(objd
);
771 if (event_notifier_enabler
)
772 return lttng_ust_objd_unref(event_notifier_enabler
->group
->objd
, 0);
776 static const struct lttng_ust_objd_ops lttng_event_notifier_enabler_ops
= {
777 .release
= lttng_event_notifier_enabler_release
,
778 .cmd
= lttng_event_notifier_enabler_cmd
,
782 int lttng_release_event_notifier_group(int objd
)
784 struct lttng_event_notifier_group
*event_notifier_group
= objd_private(objd
);
786 if (event_notifier_group
) {
787 lttng_event_notifier_group_destroy(event_notifier_group
);
794 static const struct lttng_ust_objd_ops lttng_event_notifier_group_ops
= {
795 .release
= lttng_release_event_notifier_group
,
796 .cmd
= lttng_event_notifier_group_cmd
,
800 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
801 union ust_args
*uargs
, void *owner
)
803 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
804 struct lttng_ust_tracepoint_iter
*tp
=
805 (struct lttng_ust_tracepoint_iter
*) arg
;
806 struct lttng_ust_tracepoint_iter
*iter
;
809 case LTTNG_UST_TRACEPOINT_LIST_GET
:
811 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
813 return -LTTNG_UST_ERR_NOENT
;
814 memcpy(tp
, iter
, sizeof(*tp
));
823 int lttng_abi_tracepoint_list(void *owner
)
826 struct lttng_ust_tracepoint_list
*list
;
828 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
, "tp_list");
833 list
= zmalloc(sizeof(*list
));
838 objd_set_private(list_objd
, list
);
840 /* populate list by walking on all registered probes. */
841 ret
= lttng_probes_get_event_list(list
);
853 err
= lttng_ust_objd_unref(list_objd
, 1);
861 int lttng_release_tracepoint_list(int objd
)
863 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
866 lttng_probes_prune_event_list(list
);
874 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
875 .release
= lttng_release_tracepoint_list
,
876 .cmd
= lttng_tracepoint_list_cmd
,
880 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
881 unsigned long arg
, union ust_args
*uargs
, void *owner
)
883 struct lttng_ust_field_list
*list
= objd_private(objd
);
884 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
885 struct lttng_ust_field_iter
*iter
;
888 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
890 iter
= lttng_ust_field_list_get_iter_next(list
);
892 return -LTTNG_UST_ERR_NOENT
;
893 memcpy(tp
, iter
, sizeof(*tp
));
902 int lttng_abi_tracepoint_field_list(void *owner
)
905 struct lttng_ust_field_list
*list
;
907 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
,
913 list
= zmalloc(sizeof(*list
));
918 objd_set_private(list_objd
, list
);
920 /* populate list by walking on all registered probes. */
921 ret
= lttng_probes_get_field_list(list
);
933 err
= lttng_ust_objd_unref(list_objd
, 1);
941 int lttng_release_tracepoint_field_list(int objd
)
943 struct lttng_ust_field_list
*list
= objd_private(objd
);
946 lttng_probes_prune_field_list(list
);
954 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
955 .release
= lttng_release_tracepoint_field_list
,
956 .cmd
= lttng_tracepoint_field_list_cmd
,
960 int lttng_abi_map_stream(int channel_objd
, struct lttng_ust_stream
*info
,
961 union ust_args
*uargs
, void *owner
)
963 struct lttng_channel
*channel
= objd_private(channel_objd
);
966 ret
= channel_handle_add_stream(channel
->handle
,
967 uargs
->stream
.shm_fd
, uargs
->stream
.wakeup_fd
,
968 info
->stream_nr
, info
->len
);
970 goto error_add_stream
;
979 int lttng_abi_create_event_enabler(int channel_objd
,
980 struct lttng_ust_event
*event_param
,
982 enum lttng_enabler_format_type format_type
)
984 struct lttng_channel
*channel
= objd_private(channel_objd
);
985 struct lttng_event_enabler
*enabler
;
988 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
989 event_objd
= objd_alloc(NULL
, <tng_event_enabler_ops
, owner
,
991 if (event_objd
< 0) {
996 * We tolerate no failure path after event creation. It will stay
997 * invariant for the rest of the session.
999 enabler
= lttng_event_enabler_create(format_type
, event_param
, channel
);
1004 objd_set_private(event_objd
, enabler
);
1005 /* The event holds a reference on the channel */
1006 objd_ref(channel_objd
);
1013 err
= lttng_ust_objd_unref(event_objd
, 1);
1021 * lttng_channel_cmd - lttng control through object descriptors
1023 * @objd: the object descriptor
1026 * @uargs: UST arguments (internal)
1027 * @owner: objd owner
1029 * This object descriptor implements lttng commands:
1031 * Returns an event stream object descriptor or failure.
1032 * (typically, one event stream records events from one CPU)
1034 * Returns an event object descriptor or failure.
1036 * Prepend a context field to each event in the channel
1038 * Enable recording for events in this channel (weak enable)
1040 * Disable recording for events in this channel (strong disable)
1042 * Channel and event file descriptors also hold a reference on the session.
1045 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1046 union ust_args
*uargs
, void *owner
)
1048 struct lttng_channel
*channel
= objd_private(objd
);
1050 if (cmd
!= LTTNG_UST_STREAM
) {
1052 * Check if channel received all streams.
1054 if (!lttng_is_channel_ready(channel
))
1059 case LTTNG_UST_STREAM
:
1061 struct lttng_ust_stream
*stream
;
1063 stream
= (struct lttng_ust_stream
*) arg
;
1064 /* stream used as output */
1065 return lttng_abi_map_stream(objd
, stream
, uargs
, owner
);
1067 case LTTNG_UST_EVENT
:
1069 struct lttng_ust_event
*event_param
=
1070 (struct lttng_ust_event
*) arg
;
1072 if (strutils_is_star_glob_pattern(event_param
->name
)) {
1074 * If the event name is a star globbing pattern,
1075 * we create the special star globbing enabler.
1077 return lttng_abi_create_event_enabler(objd
, event_param
,
1078 owner
, LTTNG_ENABLER_FORMAT_STAR_GLOB
);
1080 return lttng_abi_create_event_enabler(objd
, event_param
,
1081 owner
, LTTNG_ENABLER_FORMAT_EVENT
);
1084 case LTTNG_UST_CONTEXT
:
1085 return lttng_abi_add_context(objd
,
1086 (struct lttng_ust_context
*) arg
, uargs
,
1087 &channel
->ctx
, channel
->session
);
1088 case LTTNG_UST_ENABLE
:
1089 return lttng_channel_enable(channel
);
1090 case LTTNG_UST_DISABLE
:
1091 return lttng_channel_disable(channel
);
1092 case LTTNG_UST_FLUSH_BUFFER
:
1093 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
1100 int lttng_channel_release(int objd
)
1102 struct lttng_channel
*channel
= objd_private(objd
);
1105 return lttng_ust_objd_unref(channel
->session
->objd
, 0);
1109 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
1110 .release
= lttng_channel_release
,
1111 .cmd
= lttng_channel_cmd
,
1115 * lttng_enabler_cmd - lttng control through object descriptors
1117 * @objd: the object descriptor
1120 * @uargs: UST arguments (internal)
1121 * @owner: objd owner
1123 * This object descriptor implements lttng commands:
1125 * Prepend a context field to each record of events of this
1128 * Enable recording for this enabler
1130 * Disable recording for this enabler
1132 * Attach a filter to an enabler.
1133 * LTTNG_UST_EXCLUSION
1134 * Attach exclusions to an enabler.
1137 long lttng_event_enabler_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1138 union ust_args
*uargs
, void *owner
)
1140 struct lttng_event_enabler
*enabler
= objd_private(objd
);
1143 case LTTNG_UST_CONTEXT
:
1144 return lttng_event_enabler_attach_context(enabler
,
1145 (struct lttng_ust_context
*) arg
);
1146 case LTTNG_UST_ENABLE
:
1147 return lttng_event_enabler_enable(enabler
);
1148 case LTTNG_UST_DISABLE
:
1149 return lttng_event_enabler_disable(enabler
);
1150 case LTTNG_UST_FILTER
:
1154 ret
= lttng_event_enabler_attach_filter_bytecode(enabler
,
1155 (struct lttng_ust_bytecode_node
*) arg
);
1160 case LTTNG_UST_EXCLUSION
:
1162 return lttng_event_enabler_attach_exclusion(enabler
,
1163 (struct lttng_ust_excluder_node
*) arg
);
1171 int lttng_event_enabler_release(int objd
)
1173 struct lttng_event_enabler
*event_enabler
= objd_private(objd
);
1176 return lttng_ust_objd_unref(event_enabler
->chan
->objd
, 0);
1181 static const struct lttng_ust_objd_ops lttng_event_enabler_ops
= {
1182 .release
= lttng_event_enabler_release
,
1183 .cmd
= lttng_event_enabler_cmd
,
1186 void lttng_ust_abi_exit(void)
1188 lttng_ust_abi_close_in_progress
= 1;
1190 objd_table_destroy();
1192 lttng_ust_abi_close_in_progress
= 0;