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.
40 #include <lttng/ust-abi.h>
41 #include <lttng/ust-error.h>
42 #include <urcu/compiler.h>
43 #include <urcu/list.h>
44 #include <lttng/ust-events.h>
45 #include <lttng/ust-version.h>
46 #include <lttng/tracepoint.h>
47 #include "tracepoint-internal.h"
48 #include <usterr-signal-safe.h>
50 #include "lttng-tracer.h"
52 static int lttng_ust_abi_close_in_progress
;
55 int lttng_abi_tracepoint_list(void *owner
);
57 int lttng_abi_tracepoint_field_list(void *owner
);
60 * Object descriptor table. Should be protected from concurrent access
64 struct lttng_ust_obj
{
68 const struct lttng_ust_objd_ops
*ops
;
72 int freelist_next
; /* offset freelist. end is -1. */
76 struct lttng_ust_objd_table
{
77 struct lttng_ust_obj
*array
;
78 unsigned int len
, allocated_len
;
79 int freelist_head
; /* offset freelist head. end is -1 */
82 static struct lttng_ust_objd_table objd_table
= {
87 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
,
90 struct lttng_ust_obj
*obj
;
92 if (objd_table
.freelist_head
!= -1) {
93 obj
= &objd_table
.array
[objd_table
.freelist_head
];
94 objd_table
.freelist_head
= obj
->u
.freelist_next
;
98 if (objd_table
.len
>= objd_table
.allocated_len
) {
99 unsigned int new_allocated_len
, old_allocated_len
;
100 struct lttng_ust_obj
*new_table
, *old_table
;
102 old_allocated_len
= objd_table
.allocated_len
;
103 old_table
= objd_table
.array
;
104 if (!old_allocated_len
)
105 new_allocated_len
= 1;
107 new_allocated_len
= old_allocated_len
<< 1;
108 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
111 memcpy(new_table
, old_table
,
112 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
114 objd_table
.array
= new_table
;
115 objd_table
.allocated_len
= new_allocated_len
;
117 obj
= &objd_table
.array
[objd_table
.len
];
120 obj
->u
.s
.private_data
= private_data
;
122 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
123 /* count == 2 : allocated + hold ref */
124 obj
->u
.s
.owner
= owner
;
125 return obj
- objd_table
.array
;
129 struct lttng_ust_obj
*_objd_get(int id
)
131 if (id
>= objd_table
.len
)
133 if (!objd_table
.array
[id
].u
.s
.f_count
)
135 return &objd_table
.array
[id
];
139 void *objd_private(int id
)
141 struct lttng_ust_obj
*obj
= _objd_get(id
);
143 return obj
->u
.s
.private_data
;
147 void objd_set_private(int id
, void *private_data
)
149 struct lttng_ust_obj
*obj
= _objd_get(id
);
151 obj
->u
.s
.private_data
= private_data
;
154 const struct lttng_ust_objd_ops
*objd_ops(int id
)
156 struct lttng_ust_obj
*obj
= _objd_get(id
);
164 void objd_free(int id
)
166 struct lttng_ust_obj
*obj
= _objd_get(id
);
169 obj
->u
.freelist_next
= objd_table
.freelist_head
;
170 objd_table
.freelist_head
= obj
- objd_table
.array
;
171 assert(obj
->u
.s
.f_count
== 1);
172 obj
->u
.s
.f_count
= 0; /* deallocated */
176 void objd_ref(int id
)
178 struct lttng_ust_obj
*obj
= _objd_get(id
);
182 int lttng_ust_objd_unref(int id
)
184 struct lttng_ust_obj
*obj
= _objd_get(id
);
188 if (obj
->u
.s
.f_count
== 1) {
189 ERR("Reference counting error\n");
192 if ((--obj
->u
.s
.f_count
) == 1) {
193 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
203 void objd_table_destroy(void)
207 for (i
= 0; i
< objd_table
.allocated_len
; i
++)
208 (void) lttng_ust_objd_unref(i
);
209 free(objd_table
.array
);
210 objd_table
.array
= NULL
;
212 objd_table
.allocated_len
= 0;
213 objd_table
.freelist_head
= -1;
216 void lttng_ust_objd_table_owner_cleanup(void *owner
)
220 for (i
= 0; i
< objd_table
.allocated_len
; i
++) {
221 struct lttng_ust_obj
*obj
;
227 continue; /* skip root handles */
228 if (obj
->u
.s
.owner
== owner
)
229 (void) lttng_ust_objd_unref(i
);
234 * This is LTTng's own personal way to create an ABI for sessiond.
235 * We send commands over a socket.
238 static const struct lttng_ust_objd_ops lttng_ops
;
239 static const struct lttng_ust_objd_ops lttng_session_ops
;
240 static const struct lttng_ust_objd_ops lttng_channel_ops
;
241 static const struct lttng_ust_objd_ops lttng_metadata_ops
;
242 static const struct lttng_ust_objd_ops lttng_event_ops
;
243 static const struct lttng_ust_objd_ops lttng_wildcard_ops
;
244 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops
;
245 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
246 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
253 int lttng_abi_create_root_handle(void)
257 /* root handles have NULL owners */
258 root_handle
= objd_alloc(NULL
, <tng_ops
, NULL
);
263 int lttng_abi_create_session(void *owner
)
265 struct lttng_session
*session
;
266 int session_objd
, ret
;
268 session
= lttng_session_create();
271 session_objd
= objd_alloc(session
, <tng_session_ops
, owner
);
272 if (session_objd
< 0) {
276 session
->objd
= session_objd
;
280 lttng_session_destroy(session
);
285 long lttng_abi_tracer_version(int objd
,
286 struct lttng_ust_tracer_version
*v
)
288 v
->major
= LTTNG_UST_INTERNAL_MAJOR_VERSION
;
289 v
->minor
= LTTNG_UST_INTERNAL_MINOR_VERSION
;
290 v
->patchlevel
= LTTNG_UST_INTERNAL_PATCHLEVEL_VERSION
;
295 long lttng_abi_add_context(int objd
,
296 struct lttng_ust_context
*context_param
,
297 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
299 if (session
->been_active
)
302 switch (context_param
->ctx
) {
303 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
304 return lttng_add_pthread_id_to_ctx(ctx
);
305 case LTTNG_UST_CONTEXT_VTID
:
306 return lttng_add_vtid_to_ctx(ctx
);
307 case LTTNG_UST_CONTEXT_VPID
:
308 return lttng_add_vpid_to_ctx(ctx
);
309 case LTTNG_UST_CONTEXT_PROCNAME
:
310 return lttng_add_procname_to_ctx(ctx
);
317 * lttng_cmd - lttng control through socket commands
319 * @objd: the object descriptor
322 * @uargs: UST arguments (internal)
325 * This descriptor implements lttng commands:
327 * Returns a LTTng trace session object descriptor
328 * LTTNG_UST_TRACER_VERSION
329 * Returns the LTTng kernel tracer version
330 * LTTNG_UST_TRACEPOINT_LIST
331 * Returns a file descriptor listing available tracepoints
332 * LTTNG_UST_TRACEPOINT_FIELD_LIST
333 * Returns a file descriptor listing available tracepoint fields
334 * LTTNG_UST_WAIT_QUIESCENT
335 * Returns after all previously running probes have completed
337 * The returned session will be deleted when its file descriptor is closed.
340 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
341 union ust_args
*uargs
, void *owner
)
344 case LTTNG_UST_SESSION
:
345 return lttng_abi_create_session(owner
);
346 case LTTNG_UST_TRACER_VERSION
:
347 return lttng_abi_tracer_version(objd
,
348 (struct lttng_ust_tracer_version
*) arg
);
349 case LTTNG_UST_TRACEPOINT_LIST
:
350 return lttng_abi_tracepoint_list(owner
);
351 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
352 return lttng_abi_tracepoint_field_list(owner
);
353 case LTTNG_UST_WAIT_QUIESCENT
:
361 static const struct lttng_ust_objd_ops lttng_ops
= {
366 * We tolerate no failure in this function (if one happens, we print a dmesg
367 * error, but cannot return any error, because the channel information is
371 void lttng_metadata_create_events(int channel_objd
)
373 struct lttng_channel
*channel
= objd_private(channel_objd
);
374 static struct lttng_ust_event metadata_params
= {
375 .instrumentation
= LTTNG_UST_TRACEPOINT
,
376 .name
= "lttng_ust:metadata",
377 .loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
,
378 .loglevel
= TRACE_DEFAULT
,
380 struct lttng_event
*event
;
384 * We tolerate no failure path after event creation. It will stay
385 * invariant for the rest of the session.
387 ret
= lttng_event_create(channel
, &metadata_params
, &event
);
395 return; /* not allowed to return error */
398 int lttng_abi_create_channel(int session_objd
,
399 struct lttng_ust_channel
*chan_param
,
400 enum channel_type channel_type
,
401 union ust_args
*uargs
,
404 struct lttng_session
*session
= objd_private(session_objd
);
405 const struct lttng_ust_objd_ops
*ops
;
406 const char *transport_name
;
407 struct lttng_channel
*chan
;
410 struct lttng_channel chan_priv_init
;
412 switch (channel_type
) {
413 case PER_CPU_CHANNEL
:
414 if (chan_param
->output
== LTTNG_UST_MMAP
) {
415 transport_name
= chan_param
->overwrite
?
416 "relay-overwrite-mmap" : "relay-discard-mmap";
420 ops
= <tng_channel_ops
;
422 case METADATA_CHANNEL
:
423 if (chan_param
->output
== LTTNG_UST_MMAP
)
424 transport_name
= "relay-metadata-mmap";
427 ops
= <tng_metadata_ops
;
430 transport_name
= "<unknown>";
433 chan_objd
= objd_alloc(NULL
, ops
, owner
);
438 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
439 /* Copy of session UUID for consumer (availability through shm) */
440 memcpy(chan_priv_init
.uuid
, session
->uuid
, sizeof(session
->uuid
));
443 * We tolerate no failure path after channel creation. It will stay
444 * invariant for the rest of the session.
446 chan
= lttng_channel_create(session
, transport_name
, NULL
,
447 chan_param
->subbuf_size
,
448 chan_param
->num_subbuf
,
449 chan_param
->switch_timer_interval
,
450 chan_param
->read_timer_interval
,
451 &uargs
->channel
.shm_fd
,
452 &uargs
->channel
.wait_fd
,
453 &uargs
->channel
.memory_map_size
,
459 objd_set_private(chan_objd
, chan
);
460 chan
->objd
= chan_objd
;
461 if (channel_type
== METADATA_CHANNEL
) {
462 session
->metadata
= chan
;
463 lttng_metadata_create_events(chan_objd
);
465 /* The channel created holds a reference on the session */
466 objd_ref(session_objd
);
474 err
= lttng_ust_objd_unref(chan_objd
);
482 * lttng_session_cmd - lttng session object command
487 * @uargs: UST arguments (internal)
490 * This descriptor implements lttng commands:
492 * Returns a LTTng channel object descriptor
494 * Enables tracing for a session (weak enable)
496 * Disables tracing for a session (strong disable)
498 * Returns a LTTng metadata object descriptor
500 * The returned channel will be deleted when its file descriptor is closed.
503 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
504 union ust_args
*uargs
, void *owner
)
506 struct lttng_session
*session
= objd_private(objd
);
509 case LTTNG_UST_CHANNEL
:
510 return lttng_abi_create_channel(objd
,
511 (struct lttng_ust_channel
*) arg
,
512 PER_CPU_CHANNEL
, uargs
, owner
);
513 case LTTNG_UST_SESSION_START
:
514 case LTTNG_UST_ENABLE
:
515 return lttng_session_enable(session
);
516 case LTTNG_UST_SESSION_STOP
:
517 case LTTNG_UST_DISABLE
:
518 return lttng_session_disable(session
);
519 case LTTNG_UST_METADATA
:
520 return lttng_abi_create_channel(objd
,
521 (struct lttng_ust_channel
*) arg
,
522 METADATA_CHANNEL
, uargs
, owner
);
529 * Called when the last file reference is dropped.
531 * Big fat note: channels and events are invariant for the whole session after
532 * their creation. So this session destruction also destroys all channel and
533 * event structures specific to this session (they are not destroyed when their
534 * individual file is released).
537 int lttng_release_session(int objd
)
539 struct lttng_session
*session
= objd_private(objd
);
542 lttng_session_destroy(session
);
549 static const struct lttng_ust_objd_ops lttng_session_ops
= {
550 .release
= lttng_release_session
,
551 .cmd
= lttng_session_cmd
,
555 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
556 union ust_args
*uargs
, void *owner
)
558 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
559 struct lttng_ust_tracepoint_iter
*tp
=
560 (struct lttng_ust_tracepoint_iter
*) arg
;
561 struct lttng_ust_tracepoint_iter
*iter
;
564 case LTTNG_UST_TRACEPOINT_LIST_GET
:
567 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
569 return -LTTNG_UST_ERR_NOENT
;
570 if (!strcmp(iter
->name
, "lttng_ust:metadata"))
572 memcpy(tp
, iter
, sizeof(*tp
));
581 int lttng_abi_tracepoint_list(void *owner
)
584 struct lttng_ust_tracepoint_list
*list
;
586 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
, owner
);
591 list
= zmalloc(sizeof(*list
));
596 objd_set_private(list_objd
, list
);
598 /* populate list by walking on all registered probes. */
599 ret
= lttng_probes_get_event_list(list
);
611 err
= lttng_ust_objd_unref(list_objd
);
619 int lttng_release_tracepoint_list(int objd
)
621 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
624 lttng_probes_prune_event_list(list
);
632 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
633 .release
= lttng_release_tracepoint_list
,
634 .cmd
= lttng_tracepoint_list_cmd
,
638 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
639 unsigned long arg
, union ust_args
*uargs
, void *owner
)
641 struct lttng_ust_field_list
*list
= objd_private(objd
);
642 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
643 struct lttng_ust_field_iter
*iter
;
646 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
649 iter
= lttng_ust_field_list_get_iter_next(list
);
651 return -LTTNG_UST_ERR_NOENT
;
652 if (!strcmp(iter
->event_name
, "lttng_ust:metadata"))
654 memcpy(tp
, iter
, sizeof(*tp
));
663 int lttng_abi_tracepoint_field_list(void *owner
)
666 struct lttng_ust_field_list
*list
;
668 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
, owner
);
673 list
= zmalloc(sizeof(*list
));
678 objd_set_private(list_objd
, list
);
680 /* populate list by walking on all registered probes. */
681 ret
= lttng_probes_get_field_list(list
);
693 err
= lttng_ust_objd_unref(list_objd
);
701 int lttng_release_tracepoint_field_list(int objd
)
703 struct lttng_ust_field_list
*list
= objd_private(objd
);
706 lttng_probes_prune_field_list(list
);
714 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
715 .release
= lttng_release_tracepoint_field_list
,
716 .cmd
= lttng_tracepoint_field_list_cmd
,
719 struct stream_priv_data
{
720 struct lttng_ust_lib_ring_buffer
*buf
;
721 struct lttng_channel
*lttng_chan
;
725 int lttng_abi_open_stream(int channel_objd
, struct lttng_ust_stream
*info
,
726 union ust_args
*uargs
, void *owner
)
728 struct lttng_channel
*channel
= objd_private(channel_objd
);
729 struct lttng_ust_lib_ring_buffer
*buf
;
730 struct stream_priv_data
*priv
;
731 int stream_objd
, ret
;
733 buf
= channel
->ops
->buffer_read_open(channel
->chan
, channel
->handle
,
734 &uargs
->stream
.shm_fd
,
735 &uargs
->stream
.wait_fd
,
736 &uargs
->stream
.memory_map_size
);
740 priv
= zmalloc(sizeof(*priv
));
746 priv
->lttng_chan
= channel
;
747 stream_objd
= objd_alloc(priv
, &lib_ring_buffer_objd_ops
, owner
);
748 if (stream_objd
< 0) {
752 /* Hold a reference on the channel object descriptor */
753 objd_ref(channel_objd
);
759 channel
->ops
->buffer_read_close(buf
, channel
->handle
);
764 int lttng_abi_create_event(int channel_objd
,
765 struct lttng_ust_event
*event_param
,
768 struct lttng_channel
*channel
= objd_private(channel_objd
);
769 struct lttng_event
*event
;
772 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
773 event_objd
= objd_alloc(NULL
, <tng_event_ops
, owner
);
774 if (event_objd
< 0) {
779 * We tolerate no failure path after event creation. It will stay
780 * invariant for the rest of the session.
782 ret
= lttng_event_create(channel
, event_param
, &event
);
786 objd_set_private(event_objd
, event
);
787 /* The event holds a reference on the channel */
788 objd_ref(channel_objd
);
795 err
= lttng_ust_objd_unref(event_objd
);
803 int lttng_abi_create_wildcard(int channel_objd
,
804 struct lttng_ust_event
*event_param
,
807 struct lttng_channel
*channel
= objd_private(channel_objd
);
808 struct session_wildcard
*wildcard
;
809 int wildcard_objd
, ret
;
811 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
812 wildcard_objd
= objd_alloc(NULL
, <tng_wildcard_ops
, owner
);
813 if (wildcard_objd
< 0) {
818 * We tolerate no failure path after wildcard creation. It will
819 * stay invariant for the rest of the session.
821 ret
= lttng_wildcard_create(channel
, event_param
, &wildcard
);
825 objd_set_private(wildcard_objd
, wildcard
);
826 /* The wildcard holds a reference on the channel */
827 objd_ref(channel_objd
);
828 return wildcard_objd
;
834 err
= lttng_ust_objd_unref(wildcard_objd
);
842 * lttng_channel_cmd - lttng control through object descriptors
844 * @objd: the object descriptor
847 * @uargs: UST arguments (internal)
850 * This object descriptor implements lttng commands:
852 * Returns an event stream object descriptor or failure.
853 * (typically, one event stream records events from one CPU)
855 * Returns an event object descriptor or failure.
857 * Prepend a context field to each event in the channel
859 * Enable recording for events in this channel (weak enable)
861 * Disable recording for events in this channel (strong disable)
863 * Channel and event file descriptors also hold a reference on the session.
866 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
867 union ust_args
*uargs
, void *owner
)
869 struct lttng_channel
*channel
= objd_private(objd
);
872 case LTTNG_UST_STREAM
:
874 struct lttng_ust_stream
*stream
;
876 stream
= (struct lttng_ust_stream
*) arg
;
877 /* stream used as output */
878 return lttng_abi_open_stream(objd
, stream
, uargs
, owner
);
880 case LTTNG_UST_EVENT
:
882 struct lttng_ust_event
*event_param
=
883 (struct lttng_ust_event
*) arg
;
884 if (event_param
->name
[strlen(event_param
->name
) - 1] == '*') {
885 /* If ends with wildcard, create wildcard. */
886 return lttng_abi_create_wildcard(objd
, event_param
,
889 return lttng_abi_create_event(objd
, event_param
,
893 case LTTNG_UST_CONTEXT
:
894 return lttng_abi_add_context(objd
,
895 (struct lttng_ust_context
*) arg
,
896 &channel
->ctx
, channel
->session
);
897 case LTTNG_UST_ENABLE
:
898 return lttng_channel_enable(channel
);
899 case LTTNG_UST_DISABLE
:
900 return lttng_channel_disable(channel
);
901 case LTTNG_UST_FLUSH_BUFFER
:
902 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
909 * lttng_metadata_cmd - lttng control through object descriptors
911 * @objd: the object descriptor
914 * @uargs: UST arguments (internal)
917 * This object descriptor implements lttng commands:
919 * Returns an event stream file descriptor or failure.
921 * Channel and event file descriptors also hold a reference on the session.
924 long lttng_metadata_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
925 union ust_args
*uargs
, void *owner
)
927 struct lttng_channel
*channel
= objd_private(objd
);
930 case LTTNG_UST_STREAM
:
932 struct lttng_ust_stream
*stream
;
934 stream
= (struct lttng_ust_stream
*) arg
;
935 /* stream used as output */
936 return lttng_abi_open_stream(objd
, stream
, uargs
, owner
);
938 case LTTNG_UST_FLUSH_BUFFER
:
939 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
947 * lttng_channel_poll - lttng stream addition/removal monitoring
952 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
954 struct lttng_channel
*channel
= file
->private_data
;
955 unsigned int mask
= 0;
957 if (file
->f_mode
& FMODE_READ
) {
958 poll_wait_set_exclusive(wait
);
959 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
962 if (channel
->ops
->is_disabled(channel
->chan
))
964 if (channel
->ops
->is_finalized(channel
->chan
))
966 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
967 return POLLIN
| POLLRDNORM
;
976 int lttng_channel_release(int objd
)
978 struct lttng_channel
*channel
= objd_private(objd
);
981 return lttng_ust_objd_unref(channel
->session
->objd
);
985 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
986 .release
= lttng_channel_release
,
987 //.poll = lttng_channel_poll,
988 .cmd
= lttng_channel_cmd
,
991 static const struct lttng_ust_objd_ops lttng_metadata_ops
= {
992 .release
= lttng_channel_release
,
993 .cmd
= lttng_metadata_cmd
,
997 * lttng_rb_cmd - lttng ring buffer control through object descriptors
999 * @objd: the object descriptor
1002 * @uargs: UST arguments (internal)
1003 * @owner: objd owner
1005 * This object descriptor implements lttng commands:
1006 * (None for now. Access is done directly though shm.)
1009 long lttng_rb_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1010 union ust_args
*uargs
, void *owner
)
1019 int lttng_rb_release(int objd
)
1021 struct stream_priv_data
*priv
= objd_private(objd
);
1022 struct lttng_ust_lib_ring_buffer
*buf
;
1023 struct lttng_channel
*channel
;
1027 channel
= priv
->lttng_chan
;
1030 * If we are at ABI exit, we don't want to close the
1031 * buffer opened for read: it is being shared between
1032 * the parent and child (right after fork), and we don't
1033 * want the child to close it for the parent. For a real
1034 * exit, we don't care about marking it as closed, as
1035 * the consumer daemon (if there is one) will do fine
1036 * even if we don't mark it as "closed" for reading on
1038 * We only mark it as closed if it is being explicitely
1039 * released by the session daemon with an explicit
1042 if (!lttng_ust_abi_close_in_progress
)
1043 channel
->ops
->buffer_read_close(buf
, channel
->handle
);
1045 return lttng_ust_objd_unref(channel
->objd
);
1050 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops
= {
1051 .release
= lttng_rb_release
,
1052 .cmd
= lttng_rb_cmd
,
1056 * lttng_event_cmd - lttng control through object descriptors
1058 * @objd: the object descriptor
1061 * @uargs: UST arguments (internal)
1062 * @owner: objd owner
1064 * This object descriptor implements lttng commands:
1066 * Prepend a context field to each record of this event
1068 * Enable recording for this event (weak enable)
1070 * Disable recording for this event (strong disable)
1072 * Attach a filter to an event.
1075 long lttng_event_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1076 union ust_args
*uargs
, void *owner
)
1078 struct lttng_event
*event
= objd_private(objd
);
1081 case LTTNG_UST_CONTEXT
:
1082 return lttng_abi_add_context(objd
,
1083 (struct lttng_ust_context
*) arg
,
1084 &event
->ctx
, event
->chan
->session
);
1085 case LTTNG_UST_ENABLE
:
1086 return lttng_event_enable(event
);
1087 case LTTNG_UST_DISABLE
:
1088 return lttng_event_disable(event
);
1089 case LTTNG_UST_FILTER
:
1092 ret
= lttng_filter_event_attach_bytecode(event
,
1093 (struct lttng_ust_filter_bytecode_node
*) arg
);
1096 lttng_filter_event_link_bytecode(event
);
1105 int lttng_event_release(int objd
)
1107 struct lttng_event
*event
= objd_private(objd
);
1110 return lttng_ust_objd_unref(event
->chan
->objd
);
1114 /* TODO: filter control ioctl */
1115 static const struct lttng_ust_objd_ops lttng_event_ops
= {
1116 .release
= lttng_event_release
,
1117 .cmd
= lttng_event_cmd
,
1121 * lttng_wildcard_cmd - lttng control through object descriptors
1123 * @objd: the object descriptor
1126 * @uargs: UST arguments (internal)
1127 * @owner: objd owner
1129 * This object descriptor implements lttng commands:
1131 * Prepend a context field to each record of events of this
1134 * Enable recording for these wildcard events (weak enable)
1136 * Disable recording for these wildcard events (strong disable)
1138 * Attach a filter to a wildcard.
1141 long lttng_wildcard_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1142 union ust_args
*uargs
, void *owner
)
1144 struct session_wildcard
*wildcard
= objd_private(objd
);
1147 case LTTNG_UST_CONTEXT
:
1148 return -ENOSYS
; /* not implemented yet */
1150 return lttng_abi_add_context(objd
,
1151 (struct lttng_ust_context
*) arg
,
1152 &wildcard
->ctx
, wildcard
->chan
->session
);
1154 case LTTNG_UST_ENABLE
:
1155 return lttng_wildcard_enable(wildcard
);
1156 case LTTNG_UST_DISABLE
:
1157 return lttng_wildcard_disable(wildcard
);
1158 case LTTNG_UST_FILTER
:
1162 ret
= lttng_filter_wildcard_attach_bytecode(wildcard
,
1163 (struct lttng_ust_filter_bytecode_node
*) arg
);
1166 lttng_filter_wildcard_link_bytecode(wildcard
);
1175 int lttng_wildcard_release(int objd
)
1177 struct session_wildcard
*wildcard
= objd_private(objd
);
1180 return lttng_ust_objd_unref(wildcard
->chan
->objd
);
1184 /* TODO: filter control ioctl */
1185 static const struct lttng_ust_objd_ops lttng_wildcard_ops
= {
1186 .release
= lttng_wildcard_release
,
1187 .cmd
= lttng_wildcard_cmd
,
1190 void lttng_ust_abi_exit(void)
1192 lttng_ust_abi_close_in_progress
= 1;
1193 objd_table_destroy();
1194 lttng_ust_abi_close_in_progress
= 0;