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 <urcu/compiler.h>
42 #include <urcu/list.h>
43 #include <lttng/ust-events.h>
44 #include <lttng/ust-version.h>
45 #include <lttng/tracepoint.h>
46 #include "tracepoint-internal.h"
47 #include <usterr-signal-safe.h>
49 #include "ltt-tracer.h"
51 static int lttng_ust_abi_close_in_progress
;
54 int lttng_abi_tracepoint_list(void);
56 int lttng_abi_tracepoint_field_list(void);
59 * Object descriptor table. Should be protected from concurrent access
63 struct lttng_ust_obj
{
67 const struct lttng_ust_objd_ops
*ops
;
70 int freelist_next
; /* offset freelist. end is -1. */
74 struct lttng_ust_objd_table
{
75 struct lttng_ust_obj
*array
;
76 unsigned int len
, allocated_len
;
77 int freelist_head
; /* offset freelist head. end is -1 */
80 static struct lttng_ust_objd_table objd_table
= {
85 int objd_alloc(void *private_data
, const struct lttng_ust_objd_ops
*ops
)
87 struct lttng_ust_obj
*obj
;
89 if (objd_table
.freelist_head
!= -1) {
90 obj
= &objd_table
.array
[objd_table
.freelist_head
];
91 objd_table
.freelist_head
= obj
->u
.freelist_next
;
95 if (objd_table
.len
>= objd_table
.allocated_len
) {
96 unsigned int new_allocated_len
, old_allocated_len
;
97 struct lttng_ust_obj
*new_table
, *old_table
;
99 old_allocated_len
= objd_table
.allocated_len
;
100 old_table
= objd_table
.array
;
101 if (!old_allocated_len
)
102 new_allocated_len
= 1;
104 new_allocated_len
= old_allocated_len
<< 1;
105 new_table
= zmalloc(sizeof(struct lttng_ust_obj
) * new_allocated_len
);
108 memcpy(new_table
, old_table
,
109 sizeof(struct lttng_ust_obj
) * old_allocated_len
);
111 objd_table
.array
= new_table
;
112 objd_table
.allocated_len
= new_allocated_len
;
114 obj
= &objd_table
.array
[objd_table
.len
];
117 obj
->u
.s
.private_data
= private_data
;
119 obj
->u
.s
.f_count
= 2; /* count == 1 : object is allocated */
120 /* count == 2 : allocated + hold ref */
121 return obj
- objd_table
.array
;
125 struct lttng_ust_obj
*_objd_get(int id
)
127 if (id
>= objd_table
.len
)
129 if (!objd_table
.array
[id
].u
.s
.f_count
)
131 return &objd_table
.array
[id
];
135 void *objd_private(int id
)
137 struct lttng_ust_obj
*obj
= _objd_get(id
);
139 return obj
->u
.s
.private_data
;
143 void objd_set_private(int id
, void *private_data
)
145 struct lttng_ust_obj
*obj
= _objd_get(id
);
147 obj
->u
.s
.private_data
= private_data
;
150 const struct lttng_ust_objd_ops
*objd_ops(int id
)
152 struct lttng_ust_obj
*obj
= _objd_get(id
);
160 void objd_free(int id
)
162 struct lttng_ust_obj
*obj
= _objd_get(id
);
165 obj
->u
.freelist_next
= objd_table
.freelist_head
;
166 objd_table
.freelist_head
= obj
- objd_table
.array
;
167 assert(obj
->u
.s
.f_count
== 1);
168 obj
->u
.s
.f_count
= 0; /* deallocated */
172 void objd_ref(int id
)
174 struct lttng_ust_obj
*obj
= _objd_get(id
);
178 int lttng_ust_objd_unref(int id
)
180 struct lttng_ust_obj
*obj
= _objd_get(id
);
184 if (obj
->u
.s
.f_count
== 1) {
185 ERR("Reference counting error\n");
188 if ((--obj
->u
.s
.f_count
) == 1) {
189 const struct lttng_ust_objd_ops
*ops
= objd_ops(id
);
199 void objd_table_destroy(void)
203 for (i
= 0; i
< objd_table
.allocated_len
; i
++)
204 (void) lttng_ust_objd_unref(i
);
205 free(objd_table
.array
);
206 objd_table
.array
= NULL
;
208 objd_table
.allocated_len
= 0;
209 objd_table
.freelist_head
= -1;
213 * This is LTTng's own personal way to create an ABI for sessiond.
214 * We send commands over a socket.
217 static const struct lttng_ust_objd_ops lttng_ops
;
218 static const struct lttng_ust_objd_ops lttng_session_ops
;
219 static const struct lttng_ust_objd_ops lttng_channel_ops
;
220 static const struct lttng_ust_objd_ops lttng_metadata_ops
;
221 static const struct lttng_ust_objd_ops lttng_event_ops
;
222 static const struct lttng_ust_objd_ops lttng_wildcard_ops
;
223 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops
;
224 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
;
225 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
;
232 int lttng_abi_create_root_handle(void)
236 root_handle
= objd_alloc(NULL
, <tng_ops
);
241 int lttng_abi_create_session(void)
243 struct ltt_session
*session
;
244 int session_objd
, ret
;
246 session
= ltt_session_create();
249 session_objd
= objd_alloc(session
, <tng_session_ops
);
250 if (session_objd
< 0) {
254 session
->objd
= session_objd
;
258 ltt_session_destroy(session
);
263 long lttng_abi_tracer_version(int objd
,
264 struct lttng_ust_tracer_version
*v
)
266 v
->major
= LTTNG_UST_INTERNAL_MAJOR_VERSION
;
267 v
->minor
= LTTNG_UST_INTERNAL_MINOR_VERSION
;
268 v
->patchlevel
= LTTNG_UST_INTERNAL_PATCHLEVEL_VERSION
;
273 long lttng_abi_add_context(int objd
,
274 struct lttng_ust_context
*context_param
,
275 struct lttng_ctx
**ctx
, struct ltt_session
*session
)
277 if (session
->been_active
)
280 switch (context_param
->ctx
) {
281 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
282 return lttng_add_pthread_id_to_ctx(ctx
);
283 case LTTNG_UST_CONTEXT_VTID
:
284 return lttng_add_vtid_to_ctx(ctx
);
285 case LTTNG_UST_CONTEXT_VPID
:
286 return lttng_add_vpid_to_ctx(ctx
);
287 case LTTNG_UST_CONTEXT_PROCNAME
:
288 return lttng_add_procname_to_ctx(ctx
);
289 case LTTNG_UST_CONTEXT_IP
:
290 return lttng_add_ip_to_ctx(ctx
);
297 * lttng_cmd - lttng control through socket commands
299 * @objd: the object descriptor
302 * @uargs: UST arguments (internal)
304 * This descriptor implements lttng commands:
306 * Returns a LTTng trace session object descriptor
307 * LTTNG_UST_TRACER_VERSION
308 * Returns the LTTng kernel tracer version
309 * LTTNG_UST_TRACEPOINT_LIST
310 * Returns a file descriptor listing available tracepoints
311 * LTTNG_UST_TRACEPOINT_FIELD_LIST
312 * Returns a file descriptor listing available tracepoint fields
313 * LTTNG_UST_WAIT_QUIESCENT
314 * Returns after all previously running probes have completed
316 * The returned session will be deleted when its file descriptor is closed.
319 long lttng_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
320 union ust_args
*uargs
)
323 case LTTNG_UST_SESSION
:
324 return lttng_abi_create_session();
325 case LTTNG_UST_TRACER_VERSION
:
326 return lttng_abi_tracer_version(objd
,
327 (struct lttng_ust_tracer_version
*) arg
);
328 case LTTNG_UST_TRACEPOINT_LIST
:
329 return lttng_abi_tracepoint_list();
330 case LTTNG_UST_TRACEPOINT_FIELD_LIST
:
331 return lttng_abi_tracepoint_field_list();
332 case LTTNG_UST_WAIT_QUIESCENT
:
340 static const struct lttng_ust_objd_ops lttng_ops
= {
345 * We tolerate no failure in this function (if one happens, we print a dmesg
346 * error, but cannot return any error, because the channel information is
350 void lttng_metadata_create_events(int channel_objd
)
352 struct ltt_channel
*channel
= objd_private(channel_objd
);
353 static struct lttng_ust_event metadata_params
= {
354 .instrumentation
= LTTNG_UST_TRACEPOINT
,
355 .name
= "lttng_ust:metadata",
356 .loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
,
357 .loglevel
= TRACE_DEFAULT
,
359 struct ltt_event
*event
;
363 * We tolerate no failure path after event creation. It will stay
364 * invariant for the rest of the session.
366 ret
= ltt_event_create(channel
, &metadata_params
, &event
);
374 return; /* not allowed to return error */
377 int lttng_abi_create_channel(int session_objd
,
378 struct lttng_ust_channel
*chan_param
,
379 enum channel_type channel_type
,
380 union ust_args
*uargs
)
382 struct ltt_session
*session
= objd_private(session_objd
);
383 const struct lttng_ust_objd_ops
*ops
;
384 const char *transport_name
;
385 struct ltt_channel
*chan
;
388 struct ltt_channel chan_priv_init
;
390 switch (channel_type
) {
391 case PER_CPU_CHANNEL
:
392 if (chan_param
->output
== LTTNG_UST_MMAP
) {
393 transport_name
= chan_param
->overwrite
?
394 "relay-overwrite-mmap" : "relay-discard-mmap";
398 ops
= <tng_channel_ops
;
400 case METADATA_CHANNEL
:
401 if (chan_param
->output
== LTTNG_UST_MMAP
)
402 transport_name
= "relay-metadata-mmap";
405 ops
= <tng_metadata_ops
;
408 transport_name
= "<unknown>";
411 chan_objd
= objd_alloc(NULL
, ops
);
416 memset(&chan_priv_init
, 0, sizeof(chan_priv_init
));
417 /* Copy of session UUID for consumer (availability through shm) */
418 memcpy(chan_priv_init
.uuid
, session
->uuid
, sizeof(session
->uuid
));
421 * We tolerate no failure path after channel creation. It will stay
422 * invariant for the rest of the session.
424 chan
= ltt_channel_create(session
, transport_name
, NULL
,
425 chan_param
->subbuf_size
,
426 chan_param
->num_subbuf
,
427 chan_param
->switch_timer_interval
,
428 chan_param
->read_timer_interval
,
429 &uargs
->channel
.shm_fd
,
430 &uargs
->channel
.wait_fd
,
431 &uargs
->channel
.memory_map_size
,
437 objd_set_private(chan_objd
, chan
);
438 chan
->objd
= chan_objd
;
439 if (channel_type
== METADATA_CHANNEL
) {
440 session
->metadata
= chan
;
441 lttng_metadata_create_events(chan_objd
);
443 /* The channel created holds a reference on the session */
444 objd_ref(session_objd
);
452 err
= lttng_ust_objd_unref(chan_objd
);
460 * lttng_session_cmd - lttng session object command
465 * @uargs: UST arguments (internal)
467 * This descriptor implements lttng commands:
469 * Returns a LTTng channel object descriptor
471 * Enables tracing for a session (weak enable)
473 * Disables tracing for a session (strong disable)
475 * Returns a LTTng metadata object descriptor
477 * The returned channel will be deleted when its file descriptor is closed.
480 long lttng_session_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
481 union ust_args
*uargs
)
483 struct ltt_session
*session
= objd_private(objd
);
486 case LTTNG_UST_CHANNEL
:
487 return lttng_abi_create_channel(objd
,
488 (struct lttng_ust_channel
*) arg
,
489 PER_CPU_CHANNEL
, uargs
);
490 case LTTNG_UST_SESSION_START
:
491 case LTTNG_UST_ENABLE
:
492 return ltt_session_enable(session
);
493 case LTTNG_UST_SESSION_STOP
:
494 case LTTNG_UST_DISABLE
:
495 return ltt_session_disable(session
);
496 case LTTNG_UST_METADATA
:
497 return lttng_abi_create_channel(objd
,
498 (struct lttng_ust_channel
*) arg
,
499 METADATA_CHANNEL
, uargs
);
506 * Called when the last file reference is dropped.
508 * Big fat note: channels and events are invariant for the whole session after
509 * their creation. So this session destruction also destroys all channel and
510 * event structures specific to this session (they are not destroyed when their
511 * individual file is released).
514 int lttng_release_session(int objd
)
516 struct ltt_session
*session
= objd_private(objd
);
519 ltt_session_destroy(session
);
526 static const struct lttng_ust_objd_ops lttng_session_ops
= {
527 .release
= lttng_release_session
,
528 .cmd
= lttng_session_cmd
,
532 long lttng_tracepoint_list_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
533 union ust_args
*uargs
)
535 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
536 struct lttng_ust_tracepoint_iter
*tp
=
537 (struct lttng_ust_tracepoint_iter
*) arg
;
538 struct lttng_ust_tracepoint_iter
*iter
;
541 case LTTNG_UST_TRACEPOINT_LIST_GET
:
544 iter
= lttng_ust_tracepoint_list_get_iter_next(list
);
547 if (!strcmp(iter
->name
, "lttng_ust:metadata"))
549 memcpy(tp
, iter
, sizeof(*tp
));
558 int lttng_abi_tracepoint_list(void)
561 struct lttng_ust_tracepoint_list
*list
;
563 list_objd
= objd_alloc(NULL
, <tng_tracepoint_list_ops
);
568 list
= zmalloc(sizeof(*list
));
573 objd_set_private(list_objd
, list
);
575 /* populate list by walking on all registered probes. */
576 ret
= ltt_probes_get_event_list(list
);
588 err
= lttng_ust_objd_unref(list_objd
);
596 int lttng_release_tracepoint_list(int objd
)
598 struct lttng_ust_tracepoint_list
*list
= objd_private(objd
);
601 ltt_probes_prune_event_list(list
);
609 static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops
= {
610 .release
= lttng_release_tracepoint_list
,
611 .cmd
= lttng_tracepoint_list_cmd
,
615 long lttng_tracepoint_field_list_cmd(int objd
, unsigned int cmd
,
616 unsigned long arg
, union ust_args
*uargs
)
618 struct lttng_ust_field_list
*list
= objd_private(objd
);
619 struct lttng_ust_field_iter
*tp
= &uargs
->field_list
.entry
;
620 struct lttng_ust_field_iter
*iter
;
623 case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
:
626 iter
= lttng_ust_field_list_get_iter_next(list
);
629 if (!strcmp(iter
->event_name
, "lttng_ust:metadata"))
631 memcpy(tp
, iter
, sizeof(*tp
));
640 int lttng_abi_tracepoint_field_list(void)
643 struct lttng_ust_field_list
*list
;
645 list_objd
= objd_alloc(NULL
, <tng_tracepoint_field_list_ops
);
650 list
= zmalloc(sizeof(*list
));
655 objd_set_private(list_objd
, list
);
657 /* populate list by walking on all registered probes. */
658 ret
= ltt_probes_get_field_list(list
);
670 err
= lttng_ust_objd_unref(list_objd
);
678 int lttng_release_tracepoint_field_list(int objd
)
680 struct lttng_ust_field_list
*list
= objd_private(objd
);
683 ltt_probes_prune_field_list(list
);
691 static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops
= {
692 .release
= lttng_release_tracepoint_field_list
,
693 .cmd
= lttng_tracepoint_field_list_cmd
,
696 struct stream_priv_data
{
697 struct lttng_ust_lib_ring_buffer
*buf
;
698 struct ltt_channel
*ltt_chan
;
702 int lttng_abi_open_stream(int channel_objd
, struct lttng_ust_stream
*info
,
703 union ust_args
*uargs
)
705 struct ltt_channel
*channel
= objd_private(channel_objd
);
706 struct lttng_ust_lib_ring_buffer
*buf
;
707 struct stream_priv_data
*priv
;
708 int stream_objd
, ret
;
710 buf
= channel
->ops
->buffer_read_open(channel
->chan
, channel
->handle
,
711 &uargs
->stream
.shm_fd
,
712 &uargs
->stream
.wait_fd
,
713 &uargs
->stream
.memory_map_size
);
717 priv
= zmalloc(sizeof(*priv
));
723 priv
->ltt_chan
= channel
;
724 stream_objd
= objd_alloc(priv
, &lib_ring_buffer_objd_ops
);
725 if (stream_objd
< 0) {
729 /* Hold a reference on the channel object descriptor */
730 objd_ref(channel_objd
);
736 channel
->ops
->buffer_read_close(buf
, channel
->handle
);
741 int lttng_abi_create_event(int channel_objd
,
742 struct lttng_ust_event
*event_param
)
744 struct ltt_channel
*channel
= objd_private(channel_objd
);
745 struct ltt_event
*event
;
748 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
749 event_objd
= objd_alloc(NULL
, <tng_event_ops
);
750 if (event_objd
< 0) {
755 * We tolerate no failure path after event creation. It will stay
756 * invariant for the rest of the session.
758 ret
= ltt_event_create(channel
, event_param
, &event
);
762 objd_set_private(event_objd
, event
);
763 /* The event holds a reference on the channel */
764 objd_ref(channel_objd
);
771 err
= lttng_ust_objd_unref(event_objd
);
779 int lttng_abi_create_wildcard(int channel_objd
,
780 struct lttng_ust_event
*event_param
)
782 struct ltt_channel
*channel
= objd_private(channel_objd
);
783 struct session_wildcard
*wildcard
;
784 int wildcard_objd
, ret
;
786 event_param
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
787 wildcard_objd
= objd_alloc(NULL
, <tng_wildcard_ops
);
788 if (wildcard_objd
< 0) {
793 * We tolerate no failure path after wildcard creation. It will
794 * stay invariant for the rest of the session.
796 ret
= ltt_wildcard_create(channel
, event_param
, &wildcard
);
800 objd_set_private(wildcard_objd
, wildcard
);
801 /* The wildcard holds a reference on the channel */
802 objd_ref(channel_objd
);
803 return wildcard_objd
;
809 err
= lttng_ust_objd_unref(wildcard_objd
);
817 * lttng_channel_cmd - lttng control through object descriptors
819 * @objd: the object descriptor
822 * @uargs: UST arguments (internal)
824 * This object descriptor implements lttng commands:
826 * Returns an event stream object descriptor or failure.
827 * (typically, one event stream records events from one CPU)
829 * Returns an event object descriptor or failure.
831 * Prepend a context field to each event in the channel
833 * Enable recording for events in this channel (weak enable)
835 * Disable recording for events in this channel (strong disable)
837 * Channel and event file descriptors also hold a reference on the session.
840 long lttng_channel_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
841 union ust_args
*uargs
)
843 struct ltt_channel
*channel
= objd_private(objd
);
846 case LTTNG_UST_STREAM
:
848 struct lttng_ust_stream
*stream
;
850 stream
= (struct lttng_ust_stream
*) arg
;
851 /* stream used as output */
852 return lttng_abi_open_stream(objd
, stream
, uargs
);
854 case LTTNG_UST_EVENT
:
856 struct lttng_ust_event
*event_param
=
857 (struct lttng_ust_event
*) arg
;
858 if (event_param
->name
[strlen(event_param
->name
) - 1] == '*') {
859 /* If ends with wildcard, create wildcard. */
860 return lttng_abi_create_wildcard(objd
, event_param
);
862 return lttng_abi_create_event(objd
, event_param
);
865 case LTTNG_UST_CONTEXT
:
866 return lttng_abi_add_context(objd
,
867 (struct lttng_ust_context
*) arg
,
868 &channel
->ctx
, channel
->session
);
869 case LTTNG_UST_ENABLE
:
870 return ltt_channel_enable(channel
);
871 case LTTNG_UST_DISABLE
:
872 return ltt_channel_disable(channel
);
873 case LTTNG_UST_FLUSH_BUFFER
:
874 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
881 * lttng_metadata_cmd - lttng control through object descriptors
883 * @objd: the object descriptor
886 * @uargs: UST arguments (internal)
888 * This object descriptor implements lttng commands:
890 * Returns an event stream file descriptor or failure.
892 * Channel and event file descriptors also hold a reference on the session.
895 long lttng_metadata_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
896 union ust_args
*uargs
)
898 struct ltt_channel
*channel
= objd_private(objd
);
901 case LTTNG_UST_STREAM
:
903 struct lttng_ust_stream
*stream
;
905 stream
= (struct lttng_ust_stream
*) arg
;
906 /* stream used as output */
907 return lttng_abi_open_stream(objd
, stream
, uargs
);
909 case LTTNG_UST_FLUSH_BUFFER
:
910 return channel
->ops
->flush_buffer(channel
->chan
, channel
->handle
);
918 * lttng_channel_poll - lttng stream addition/removal monitoring
923 unsigned int lttng_channel_poll(struct file
*file
, poll_table
*wait
)
925 struct ltt_channel
*channel
= file
->private_data
;
926 unsigned int mask
= 0;
928 if (file
->f_mode
& FMODE_READ
) {
929 poll_wait_set_exclusive(wait
);
930 poll_wait(file
, channel
->ops
->get_hp_wait_queue(channel
->chan
),
933 if (channel
->ops
->is_disabled(channel
->chan
))
935 if (channel
->ops
->is_finalized(channel
->chan
))
937 if (channel
->ops
->buffer_has_read_closed_stream(channel
->chan
))
938 return POLLIN
| POLLRDNORM
;
947 int lttng_channel_release(int objd
)
949 struct ltt_channel
*channel
= objd_private(objd
);
952 return lttng_ust_objd_unref(channel
->session
->objd
);
956 static const struct lttng_ust_objd_ops lttng_channel_ops
= {
957 .release
= lttng_channel_release
,
958 //.poll = lttng_channel_poll,
959 .cmd
= lttng_channel_cmd
,
962 static const struct lttng_ust_objd_ops lttng_metadata_ops
= {
963 .release
= lttng_channel_release
,
964 .cmd
= lttng_metadata_cmd
,
968 * lttng_rb_cmd - lttng ring buffer control through object descriptors
970 * @objd: the object descriptor
973 * @uargs: UST arguments (internal)
975 * This object descriptor implements lttng commands:
976 * (None for now. Access is done directly though shm.)
979 long lttng_rb_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
980 union ust_args
*uargs
)
989 int lttng_rb_release(int objd
)
991 struct stream_priv_data
*priv
= objd_private(objd
);
992 struct lttng_ust_lib_ring_buffer
*buf
;
993 struct ltt_channel
*channel
;
997 channel
= priv
->ltt_chan
;
1000 * If we are at ABI exit, we don't want to close the
1001 * buffer opened for read: it is being shared between
1002 * the parent and child (right after fork), and we don't
1003 * want the child to close it for the parent. For a real
1004 * exit, we don't care about marking it as closed, as
1005 * the consumer daemon (if there is one) will do fine
1006 * even if we don't mark it as "closed" for reading on
1008 * We only mark it as closed if it is being explicitely
1009 * released by the session daemon with an explicit
1012 if (!lttng_ust_abi_close_in_progress
)
1013 channel
->ops
->buffer_read_close(buf
, channel
->handle
);
1015 return lttng_ust_objd_unref(channel
->objd
);
1020 static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops
= {
1021 .release
= lttng_rb_release
,
1022 .cmd
= lttng_rb_cmd
,
1026 * lttng_event_cmd - lttng control through object descriptors
1028 * @objd: the object descriptor
1031 * @uargs: UST arguments (internal)
1033 * This object descriptor implements lttng commands:
1035 * Prepend a context field to each record of this event
1037 * Enable recording for this event (weak enable)
1039 * Disable recording for this event (strong disable)
1041 * Attach a filter to an event.
1044 long lttng_event_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1045 union ust_args
*uargs
)
1047 struct ltt_event
*event
= objd_private(objd
);
1050 case LTTNG_UST_CONTEXT
:
1051 return lttng_abi_add_context(objd
,
1052 (struct lttng_ust_context
*) arg
,
1053 &event
->ctx
, event
->chan
->session
);
1054 case LTTNG_UST_ENABLE
:
1055 return ltt_event_enable(event
);
1056 case LTTNG_UST_DISABLE
:
1057 return ltt_event_disable(event
);
1058 case LTTNG_UST_FILTER
:
1061 ret
= lttng_filter_event_attach_bytecode(event
,
1062 (struct lttng_ust_filter_bytecode
*) arg
);
1065 lttng_filter_event_link_bytecode(event
,
1066 event
->filter_bytecode
);
1075 int lttng_event_release(int objd
)
1077 struct ltt_event
*event
= objd_private(objd
);
1080 return lttng_ust_objd_unref(event
->chan
->objd
);
1084 /* TODO: filter control ioctl */
1085 static const struct lttng_ust_objd_ops lttng_event_ops
= {
1086 .release
= lttng_event_release
,
1087 .cmd
= lttng_event_cmd
,
1091 * lttng_wildcard_cmd - lttng control through object descriptors
1093 * @objd: the object descriptor
1096 * @uargs: UST arguments (internal)
1098 * This object descriptor implements lttng commands:
1100 * Prepend a context field to each record of events of this
1103 * Enable recording for these wildcard events (weak enable)
1105 * Disable recording for these wildcard events (strong disable)
1107 * Attach a filter to a wildcard.
1110 long lttng_wildcard_cmd(int objd
, unsigned int cmd
, unsigned long arg
,
1111 union ust_args
*uargs
)
1113 struct session_wildcard
*wildcard
= objd_private(objd
);
1116 case LTTNG_UST_CONTEXT
:
1117 return -ENOSYS
; /* not implemented yet */
1119 return lttng_abi_add_context(objd
,
1120 (struct lttng_ust_context
*) arg
,
1121 &wildcard
->ctx
, wildcard
->chan
->session
);
1123 case LTTNG_UST_ENABLE
:
1124 return ltt_wildcard_enable(wildcard
);
1125 case LTTNG_UST_DISABLE
:
1126 return ltt_wildcard_disable(wildcard
);
1127 case LTTNG_UST_FILTER
:
1131 ret
= lttng_filter_wildcard_attach_bytecode(wildcard
,
1132 (struct lttng_ust_filter_bytecode
*) arg
);
1135 lttng_filter_wildcard_link_bytecode(wildcard
);
1144 int lttng_wildcard_release(int objd
)
1146 struct session_wildcard
*wildcard
= objd_private(objd
);
1149 return lttng_ust_objd_unref(wildcard
->chan
->objd
);
1153 /* TODO: filter control ioctl */
1154 static const struct lttng_ust_objd_ops lttng_wildcard_ops
= {
1155 .release
= lttng_wildcard_release
,
1156 .cmd
= lttng_wildcard_cmd
,
1159 void lttng_ust_abi_exit(void)
1161 lttng_ust_abi_close_in_progress
= 1;
1162 objd_table_destroy();
1163 lttng_ust_abi_close_in_progress
= 0;