2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011-2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License only.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/ust-events.h>
27 #include <usterr-signal-safe.h>
31 #include "../libringbuffer/backend.h"
32 #include "../libringbuffer/frontend.h"
33 #include "../liblttng-ust/wait.h"
34 #include "../liblttng-ust/lttng-rb-clients.h"
35 #include "../liblttng-ust/clock.h"
38 * Number of milliseconds to retry before failing metadata writes on
39 * buffer full condition. (10 seconds)
41 #define LTTNG_METADATA_TIMEOUT_MSEC 10000
44 * Channel representation within consumer.
46 struct ustctl_consumer_channel
{
47 struct lttng_channel
*chan
; /* lttng channel buffers */
49 /* initial attributes */
50 struct ustctl_consumer_channel_attr attr
;
51 int wait_fd
; /* monitor close() */
52 int wakeup_fd
; /* monitor close() */
56 * Stream representation within consumer.
58 struct ustctl_consumer_stream
{
59 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
60 struct lttng_ust_lib_ring_buffer
*buf
;
61 struct ustctl_consumer_channel
*chan
;
62 int shm_fd
, wait_fd
, wakeup_fd
;
64 uint64_t memory_map_size
;
67 extern void lttng_ring_buffer_client_overwrite_init(void);
68 extern void lttng_ring_buffer_client_overwrite_rt_init(void);
69 extern void lttng_ring_buffer_client_discard_init(void);
70 extern void lttng_ring_buffer_client_discard_rt_init(void);
71 extern void lttng_ring_buffer_metadata_client_init(void);
72 extern void lttng_ring_buffer_client_overwrite_exit(void);
73 extern void lttng_ring_buffer_client_overwrite_rt_exit(void);
74 extern void lttng_ring_buffer_client_discard_exit(void);
75 extern void lttng_ring_buffer_client_discard_rt_exit(void);
76 extern void lttng_ring_buffer_metadata_client_exit(void);
78 volatile enum ust_loglevel ust_loglevel
;
80 int ustctl_release_handle(int sock
, int handle
)
82 struct ustcomm_ust_msg lum
;
83 struct ustcomm_ust_reply lur
;
85 if (sock
< 0 || handle
< 0)
87 memset(&lum
, 0, sizeof(lum
));
89 lum
.cmd
= LTTNG_UST_RELEASE
;
90 return ustcomm_send_app_cmd(sock
, &lum
, &lur
);
94 * If sock is negative, it means we don't have to notify the other side
95 * (e.g. application has already vanished).
97 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
104 switch (data
->type
) {
105 case LTTNG_UST_OBJECT_TYPE_CHANNEL
:
106 if (data
->u
.channel
.wakeup_fd
>= 0) {
107 ret
= close(data
->u
.channel
.wakeup_fd
);
113 free(data
->u
.channel
.data
);
115 case LTTNG_UST_OBJECT_TYPE_STREAM
:
116 if (data
->u
.stream
.shm_fd
>= 0) {
117 ret
= close(data
->u
.stream
.shm_fd
);
123 if (data
->u
.stream
.wakeup_fd
>= 0) {
124 ret
= close(data
->u
.stream
.wakeup_fd
);
131 case LTTNG_UST_OBJECT_TYPE_EVENT
:
132 case LTTNG_UST_OBJECT_TYPE_CONTEXT
:
137 return ustctl_release_handle(sock
, data
->handle
);
141 * Send registration done packet to the application.
143 int ustctl_register_done(int sock
)
145 struct ustcomm_ust_msg lum
;
146 struct ustcomm_ust_reply lur
;
149 DBG("Sending register done command to %d", sock
);
150 memset(&lum
, 0, sizeof(lum
));
151 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
152 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
153 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
160 * returns session handle.
162 int ustctl_create_session(int sock
)
164 struct ustcomm_ust_msg lum
;
165 struct ustcomm_ust_reply lur
;
166 int ret
, session_handle
;
169 memset(&lum
, 0, sizeof(lum
));
170 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
171 lum
.cmd
= LTTNG_UST_SESSION
;
172 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
175 session_handle
= lur
.ret_val
;
176 DBG("received session handle %u", session_handle
);
177 return session_handle
;
180 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
181 struct lttng_ust_object_data
*channel_data
,
182 struct lttng_ust_object_data
**_event_data
)
184 struct ustcomm_ust_msg lum
;
185 struct ustcomm_ust_reply lur
;
186 struct lttng_ust_object_data
*event_data
;
189 if (!channel_data
|| !_event_data
)
192 event_data
= zmalloc(sizeof(*event_data
));
195 event_data
->type
= LTTNG_UST_OBJECT_TYPE_EVENT
;
196 memset(&lum
, 0, sizeof(lum
));
197 lum
.handle
= channel_data
->handle
;
198 lum
.cmd
= LTTNG_UST_EVENT
;
199 strncpy(lum
.u
.event
.name
, ev
->name
,
200 LTTNG_UST_SYM_NAME_LEN
);
201 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
202 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
203 lum
.u
.event
.loglevel
= ev
->loglevel
;
204 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
209 event_data
->handle
= lur
.ret_val
;
210 DBG("received event handle %u", event_data
->handle
);
211 *_event_data
= event_data
;
215 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
216 struct lttng_ust_object_data
*obj_data
,
217 struct lttng_ust_object_data
**_context_data
)
219 struct ustcomm_ust_msg lum
;
220 struct ustcomm_ust_reply lur
;
221 struct lttng_ust_object_data
*context_data
;
224 if (!obj_data
|| !_context_data
)
227 context_data
= zmalloc(sizeof(*context_data
));
230 context_data
->type
= LTTNG_UST_OBJECT_TYPE_CONTEXT
;
231 memset(&lum
, 0, sizeof(lum
));
232 lum
.handle
= obj_data
->handle
;
233 lum
.cmd
= LTTNG_UST_CONTEXT
;
234 lum
.u
.context
= *ctx
;
235 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
240 context_data
->handle
= -1;
241 DBG("Context created successfully");
242 *_context_data
= context_data
;
246 int ustctl_set_filter(int sock
, struct lttng_ust_filter_bytecode
*bytecode
,
247 struct lttng_ust_object_data
*obj_data
)
249 struct ustcomm_ust_msg lum
;
250 struct ustcomm_ust_reply lur
;
256 memset(&lum
, 0, sizeof(lum
));
257 lum
.handle
= obj_data
->handle
;
258 lum
.cmd
= LTTNG_UST_FILTER
;
259 lum
.u
.filter
.data_size
= bytecode
->len
;
260 lum
.u
.filter
.reloc_offset
= bytecode
->reloc_offset
;
261 lum
.u
.filter
.seqnum
= bytecode
->seqnum
;
263 ret
= ustcomm_send_app_msg(sock
, &lum
);
266 /* send var len bytecode */
267 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
272 if (ret
!= bytecode
->len
)
274 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
277 int ustctl_set_exclusion(int sock
, struct lttng_ust_event_exclusion
*exclusion
,
278 struct lttng_ust_object_data
*obj_data
)
280 struct ustcomm_ust_msg lum
;
281 struct ustcomm_ust_reply lur
;
288 memset(&lum
, 0, sizeof(lum
));
289 lum
.handle
= obj_data
->handle
;
290 lum
.cmd
= LTTNG_UST_EXCLUSION
;
291 lum
.u
.exclusion
.count
= exclusion
->count
;
293 ret
= ustcomm_send_app_msg(sock
, &lum
);
298 /* send var len exclusion names */
299 ret
= ustcomm_send_unix_sock(sock
,
301 exclusion
->count
* LTTNG_UST_SYM_NAME_LEN
);
305 if (ret
!= exclusion
->count
* LTTNG_UST_SYM_NAME_LEN
) {
308 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
311 /* Enable event, channel and session ioctl */
312 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
314 struct ustcomm_ust_msg lum
;
315 struct ustcomm_ust_reply lur
;
321 memset(&lum
, 0, sizeof(lum
));
322 lum
.handle
= object
->handle
;
323 lum
.cmd
= LTTNG_UST_ENABLE
;
324 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
327 DBG("enabled handle %u", object
->handle
);
331 /* Disable event, channel and session ioctl */
332 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
334 struct ustcomm_ust_msg lum
;
335 struct ustcomm_ust_reply lur
;
341 memset(&lum
, 0, sizeof(lum
));
342 lum
.handle
= object
->handle
;
343 lum
.cmd
= LTTNG_UST_DISABLE
;
344 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
347 DBG("disable handle %u", object
->handle
);
351 int ustctl_start_session(int sock
, int handle
)
353 struct lttng_ust_object_data obj
;
356 return ustctl_enable(sock
, &obj
);
359 int ustctl_stop_session(int sock
, int handle
)
361 struct lttng_ust_object_data obj
;
364 return ustctl_disable(sock
, &obj
);
367 int ustctl_tracepoint_list(int sock
)
369 struct ustcomm_ust_msg lum
;
370 struct ustcomm_ust_reply lur
;
371 int ret
, tp_list_handle
;
373 memset(&lum
, 0, sizeof(lum
));
374 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
375 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
376 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
379 tp_list_handle
= lur
.ret_val
;
380 DBG("received tracepoint list handle %u", tp_list_handle
);
381 return tp_list_handle
;
384 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
385 struct lttng_ust_tracepoint_iter
*iter
)
387 struct ustcomm_ust_msg lum
;
388 struct ustcomm_ust_reply lur
;
394 memset(&lum
, 0, sizeof(lum
));
395 lum
.handle
= tp_list_handle
;
396 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
397 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
400 DBG("received tracepoint list entry name %s loglevel %d",
401 lur
.u
.tracepoint
.name
,
402 lur
.u
.tracepoint
.loglevel
);
403 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
407 int ustctl_tracepoint_field_list(int sock
)
409 struct ustcomm_ust_msg lum
;
410 struct ustcomm_ust_reply lur
;
411 int ret
, tp_field_list_handle
;
413 memset(&lum
, 0, sizeof(lum
));
414 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
415 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST
;
416 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
419 tp_field_list_handle
= lur
.ret_val
;
420 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
421 return tp_field_list_handle
;
424 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
425 struct lttng_ust_field_iter
*iter
)
427 struct ustcomm_ust_msg lum
;
428 struct ustcomm_ust_reply lur
;
435 memset(&lum
, 0, sizeof(lum
));
436 lum
.handle
= tp_field_list_handle
;
437 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
;
438 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
441 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
442 if (len
!= sizeof(*iter
)) {
445 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
453 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
455 struct ustcomm_ust_msg lum
;
456 struct ustcomm_ust_reply lur
;
462 memset(&lum
, 0, sizeof(lum
));
463 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
464 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
465 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
468 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
469 DBG("received tracer version");
473 int ustctl_wait_quiescent(int sock
)
475 struct ustcomm_ust_msg lum
;
476 struct ustcomm_ust_reply lur
;
479 memset(&lum
, 0, sizeof(lum
));
480 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
481 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
482 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
485 DBG("waited for quiescent state");
489 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
497 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
499 struct ustcomm_ust_msg lum
;
500 struct ustcomm_ust_reply lur
;
506 memset(&lum
, 0, sizeof(lum
));
507 lum
.handle
= object
->handle
;
508 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
509 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
512 DBG("flushed buffer handle %u", object
->handle
);
517 int ustctl_send_channel(int sock
,
518 enum lttng_ust_chan_type type
,
528 len
= ustcomm_send_unix_sock(sock
, &size
, sizeof(size
));
529 if (len
!= sizeof(size
)) {
536 /* Send channel type */
537 len
= ustcomm_send_unix_sock(sock
, &type
, sizeof(type
));
538 if (len
!= sizeof(type
)) {
546 /* Send channel data */
547 len
= ustcomm_send_unix_sock(sock
, data
, size
);
556 len
= ustcomm_send_fds_unix_sock(sock
, &wakeup_fd
, 1);
567 int ustctl_send_stream(int sock
,
569 uint64_t memory_map_size
,
570 int shm_fd
, int wakeup_fd
,
578 /* finish iteration */
581 len
= ustcomm_send_unix_sock(sock
, &v
, sizeof(v
));
582 if (len
!= sizeof(v
)) {
592 len
= ustcomm_send_unix_sock(sock
, &memory_map_size
,
593 sizeof(memory_map_size
));
594 if (len
!= sizeof(memory_map_size
)) {
602 len
= ustcomm_send_unix_sock(sock
, &stream_nr
,
604 if (len
!= sizeof(stream_nr
)) {
612 /* Send shm fd and wakeup fd */
615 len
= ustcomm_send_fds_unix_sock(sock
, fds
, 2);
625 int ustctl_recv_channel_from_consumer(int sock
,
626 struct lttng_ust_object_data
**_channel_data
)
628 struct lttng_ust_object_data
*channel_data
;
633 channel_data
= zmalloc(sizeof(*channel_data
));
638 channel_data
->type
= LTTNG_UST_OBJECT_TYPE_CHANNEL
;
639 channel_data
->handle
= -1;
642 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->size
,
643 sizeof(channel_data
->size
));
644 if (len
!= sizeof(channel_data
->size
)) {
652 /* recv channel type */
653 len
= ustcomm_recv_unix_sock(sock
, &channel_data
->u
.channel
.type
,
654 sizeof(channel_data
->u
.channel
.type
));
655 if (len
!= sizeof(channel_data
->u
.channel
.type
)) {
663 /* recv channel data */
664 channel_data
->u
.channel
.data
= zmalloc(channel_data
->size
);
665 if (!channel_data
->u
.channel
.data
) {
669 len
= ustcomm_recv_unix_sock(sock
, channel_data
->u
.channel
.data
,
671 if (len
!= channel_data
->size
) {
676 goto error_recv_data
;
679 len
= ustcomm_recv_fds_unix_sock(sock
, &wakeup_fd
, 1);
683 goto error_recv_data
;
686 goto error_recv_data
;
689 channel_data
->u
.channel
.wakeup_fd
= wakeup_fd
;
690 *_channel_data
= channel_data
;
694 free(channel_data
->u
.channel
.data
);
701 int ustctl_recv_stream_from_consumer(int sock
,
702 struct lttng_ust_object_data
**_stream_data
)
704 struct lttng_ust_object_data
*stream_data
;
709 stream_data
= zmalloc(sizeof(*stream_data
));
715 stream_data
->type
= LTTNG_UST_OBJECT_TYPE_STREAM
;
716 stream_data
->handle
= -1;
719 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->size
,
720 sizeof(stream_data
->size
));
721 if (len
!= sizeof(stream_data
->size
)) {
728 if (stream_data
->size
== -1) {
729 ret
= -LTTNG_UST_ERR_NOENT
;
734 len
= ustcomm_recv_unix_sock(sock
, &stream_data
->u
.stream
.stream_nr
,
735 sizeof(stream_data
->u
.stream
.stream_nr
));
736 if (len
!= sizeof(stream_data
->u
.stream
.stream_nr
)) {
744 /* recv shm fd and wakeup fd */
745 len
= ustcomm_recv_fds_unix_sock(sock
, fds
, 2);
755 stream_data
->u
.stream
.shm_fd
= fds
[0];
756 stream_data
->u
.stream
.wakeup_fd
= fds
[1];
757 *_stream_data
= stream_data
;
766 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
767 struct lttng_ust_object_data
*channel_data
)
769 struct ustcomm_ust_msg lum
;
770 struct ustcomm_ust_reply lur
;
776 memset(&lum
, 0, sizeof(lum
));
777 lum
.handle
= session_handle
;
778 lum
.cmd
= LTTNG_UST_CHANNEL
;
779 lum
.u
.channel
.len
= channel_data
->size
;
780 lum
.u
.channel
.type
= channel_data
->u
.channel
.type
;
781 ret
= ustcomm_send_app_msg(sock
, &lum
);
785 ret
= ustctl_send_channel(sock
,
786 channel_data
->u
.channel
.type
,
787 channel_data
->u
.channel
.data
,
789 channel_data
->u
.channel
.wakeup_fd
,
793 ret
= ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
795 channel_data
->handle
= lur
.ret_val
;
800 int ustctl_send_stream_to_ust(int sock
,
801 struct lttng_ust_object_data
*channel_data
,
802 struct lttng_ust_object_data
*stream_data
)
804 struct ustcomm_ust_msg lum
;
805 struct ustcomm_ust_reply lur
;
808 memset(&lum
, 0, sizeof(lum
));
809 lum
.handle
= channel_data
->handle
;
810 lum
.cmd
= LTTNG_UST_STREAM
;
811 lum
.u
.stream
.len
= stream_data
->size
;
812 lum
.u
.stream
.stream_nr
= stream_data
->u
.stream
.stream_nr
;
813 ret
= ustcomm_send_app_msg(sock
, &lum
);
818 assert(stream_data
->type
== LTTNG_UST_OBJECT_TYPE_STREAM
);
820 ret
= ustctl_send_stream(sock
,
821 stream_data
->u
.stream
.stream_nr
,
823 stream_data
->u
.stream
.shm_fd
,
824 stream_data
->u
.stream
.wakeup_fd
, 1);
827 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
830 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data
**dest
,
831 struct lttng_ust_object_data
*src
)
833 struct lttng_ust_object_data
*obj
;
836 if (src
->handle
!= -1) {
841 obj
= zmalloc(sizeof(*obj
));
847 obj
->type
= src
->type
;
848 obj
->handle
= src
->handle
;
849 obj
->size
= src
->size
;
852 case LTTNG_UST_OBJECT_TYPE_CHANNEL
:
854 obj
->u
.channel
.type
= src
->u
.channel
.type
;
855 if (src
->u
.channel
.wakeup_fd
>= 0) {
856 obj
->u
.channel
.wakeup_fd
=
857 dup(src
->u
.channel
.wakeup_fd
);
858 if (obj
->u
.channel
.wakeup_fd
< 0) {
860 goto chan_error_wakeup_fd
;
863 obj
->u
.channel
.wakeup_fd
=
864 src
->u
.channel
.wakeup_fd
;
866 obj
->u
.channel
.data
= zmalloc(obj
->size
);
867 if (!obj
->u
.channel
.data
) {
869 goto chan_error_alloc
;
871 memcpy(obj
->u
.channel
.data
, src
->u
.channel
.data
, obj
->size
);
875 if (src
->u
.channel
.wakeup_fd
>= 0) {
878 closeret
= close(obj
->u
.channel
.wakeup_fd
);
883 chan_error_wakeup_fd
:
888 case LTTNG_UST_OBJECT_TYPE_STREAM
:
890 obj
->u
.stream
.stream_nr
= src
->u
.stream
.stream_nr
;
891 if (src
->u
.stream
.wakeup_fd
>= 0) {
892 obj
->u
.stream
.wakeup_fd
=
893 dup(src
->u
.stream
.wakeup_fd
);
894 if (obj
->u
.stream
.wakeup_fd
< 0) {
896 goto stream_error_wakeup_fd
;
899 obj
->u
.stream
.wakeup_fd
=
900 src
->u
.stream
.wakeup_fd
;
903 if (src
->u
.stream
.shm_fd
>= 0) {
904 obj
->u
.stream
.shm_fd
=
905 dup(src
->u
.stream
.shm_fd
);
906 if (obj
->u
.stream
.shm_fd
< 0) {
908 goto stream_error_shm_fd
;
911 obj
->u
.stream
.shm_fd
=
912 src
->u
.stream
.shm_fd
;
917 if (src
->u
.stream
.wakeup_fd
>= 0) {
920 closeret
= close(obj
->u
.stream
.wakeup_fd
);
925 stream_error_wakeup_fd
:
944 /* Buffer operations */
946 int ustctl_get_nr_stream_per_channel(void)
948 return num_possible_cpus();
951 struct ustctl_consumer_channel
*
952 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
,
953 const int *stream_fds
, int nr_stream_fds
)
955 struct ustctl_consumer_channel
*chan
;
956 const char *transport_name
;
957 struct lttng_transport
*transport
;
959 switch (attr
->type
) {
960 case LTTNG_UST_CHAN_PER_CPU
:
961 if (attr
->output
== LTTNG_UST_MMAP
) {
962 if (attr
->overwrite
) {
963 if (attr
->read_timer_interval
== 0) {
964 transport_name
= "relay-overwrite-mmap";
966 transport_name
= "relay-overwrite-rt-mmap";
969 if (attr
->read_timer_interval
== 0) {
970 transport_name
= "relay-discard-mmap";
972 transport_name
= "relay-discard-rt-mmap";
979 case LTTNG_UST_CHAN_METADATA
:
980 if (attr
->output
== LTTNG_UST_MMAP
)
981 transport_name
= "relay-metadata-mmap";
986 transport_name
= "<unknown>";
990 transport
= lttng_transport_find(transport_name
);
992 DBG("LTTng transport %s not found\n",
997 chan
= zmalloc(sizeof(*chan
));
1001 chan
->chan
= transport
->ops
.channel_create(transport_name
, NULL
,
1002 attr
->subbuf_size
, attr
->num_subbuf
,
1003 attr
->switch_timer_interval
,
1004 attr
->read_timer_interval
,
1005 attr
->uuid
, attr
->chan_id
,
1006 stream_fds
, nr_stream_fds
);
1010 chan
->chan
->ops
= &transport
->ops
;
1011 memcpy(&chan
->attr
, attr
, sizeof(chan
->attr
));
1012 chan
->wait_fd
= ustctl_channel_get_wait_fd(chan
);
1013 chan
->wakeup_fd
= ustctl_channel_get_wakeup_fd(chan
);
1021 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
)
1023 (void) ustctl_channel_close_wait_fd(chan
);
1024 (void) ustctl_channel_close_wakeup_fd(chan
);
1025 chan
->chan
->ops
->channel_destroy(chan
->chan
);
1029 int ustctl_send_channel_to_sessiond(int sock
,
1030 struct ustctl_consumer_channel
*channel
)
1032 struct shm_object_table
*table
;
1034 table
= channel
->chan
->handle
->table
;
1035 if (table
->size
<= 0)
1037 return ustctl_send_channel(sock
,
1039 table
->objects
[0].memory_map
,
1040 table
->objects
[0].memory_map_size
,
1045 int ustctl_send_stream_to_sessiond(int sock
,
1046 struct ustctl_consumer_stream
*stream
)
1049 return ustctl_send_stream(sock
, -1U, -1U, -1, -1, 0);
1051 return ustctl_send_stream(sock
,
1053 stream
->memory_map_size
,
1054 stream
->shm_fd
, stream
->wakeup_fd
,
1058 int ustctl_write_metadata_to_channel(
1059 struct ustctl_consumer_channel
*channel
,
1060 const char *metadata_str
, /* NOT null-terminated */
1061 size_t len
) /* metadata length */
1063 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1064 struct lttng_channel
*chan
= channel
->chan
;
1065 const char *str
= metadata_str
;
1066 int ret
= 0, waitret
;
1067 size_t reserve_len
, pos
;
1069 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
1070 reserve_len
= min_t(size_t,
1071 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1073 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1074 sizeof(char), -1, chan
->handle
);
1076 * We don't care about metadata buffer's records lost
1077 * count, because we always retry here. Report error if
1078 * we need to bail out after timeout or being
1081 waitret
= wait_cond_interruptible_timeout(
1083 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1084 ret
!= -ENOBUFS
|| !ret
;
1086 LTTNG_METADATA_TIMEOUT_MSEC
);
1087 if (waitret
== -ETIMEDOUT
|| waitret
== -EINTR
|| ret
) {
1088 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
1089 waitret
== -EINTR
? "interrupted" :
1090 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
1091 if (waitret
== -EINTR
)
1095 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
1096 chan
->ops
->event_commit(&ctx
);
1103 * Write at most one packet in the channel.
1104 * Returns the number of bytes written on success, < 0 on error.
1106 ssize_t
ustctl_write_one_packet_to_channel(
1107 struct ustctl_consumer_channel
*channel
,
1108 const char *metadata_str
, /* NOT null-terminated */
1109 size_t len
) /* metadata length */
1111 struct lttng_ust_lib_ring_buffer_ctx ctx
;
1112 struct lttng_channel
*chan
= channel
->chan
;
1113 const char *str
= metadata_str
;
1114 ssize_t reserve_len
;
1117 reserve_len
= min_t(ssize_t
,
1118 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
1120 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
1121 sizeof(char), -1, chan
->handle
);
1122 ret
= chan
->ops
->event_reserve(&ctx
, 0);
1124 DBG("LTTng: event reservation failed");
1129 chan
->ops
->event_write(&ctx
, str
, reserve_len
);
1130 chan
->ops
->event_commit(&ctx
);
1136 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
)
1138 struct channel
*chan
;
1141 chan
= consumer_chan
->chan
->chan
;
1142 ret
= ring_buffer_channel_close_wait_fd(&chan
->backend
.config
,
1143 chan
, chan
->handle
);
1145 consumer_chan
->wait_fd
= -1;
1149 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
)
1151 struct channel
*chan
;
1154 chan
= consumer_chan
->chan
->chan
;
1155 ret
= ring_buffer_channel_close_wakeup_fd(&chan
->backend
.config
,
1156 chan
, chan
->handle
);
1158 consumer_chan
->wakeup_fd
= -1;
1162 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
)
1164 struct channel
*chan
;
1166 chan
= stream
->chan
->chan
->chan
;
1167 return ring_buffer_stream_close_wait_fd(&chan
->backend
.config
,
1168 chan
, stream
->handle
, stream
->cpu
);
1171 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1173 struct channel
*chan
;
1175 chan
= stream
->chan
->chan
->chan
;
1176 return ring_buffer_stream_close_wakeup_fd(&chan
->backend
.config
,
1177 chan
, stream
->handle
, stream
->cpu
);
1180 struct ustctl_consumer_stream
*
1181 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
1184 struct ustctl_consumer_stream
*stream
;
1185 struct lttng_ust_shm_handle
*handle
;
1186 struct channel
*chan
;
1187 int shm_fd
, wait_fd
, wakeup_fd
;
1188 uint64_t memory_map_size
;
1189 struct lttng_ust_lib_ring_buffer
*buf
;
1194 handle
= channel
->chan
->handle
;
1198 chan
= channel
->chan
->chan
;
1199 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
1200 chan
, cpu
, handle
, &shm_fd
, &wait_fd
,
1201 &wakeup_fd
, &memory_map_size
);
1204 ret
= lib_ring_buffer_open_read(buf
, handle
);
1208 stream
= zmalloc(sizeof(*stream
));
1211 stream
->handle
= handle
;
1213 stream
->chan
= channel
;
1214 stream
->shm_fd
= shm_fd
;
1215 stream
->wait_fd
= wait_fd
;
1216 stream
->wakeup_fd
= wakeup_fd
;
1217 stream
->memory_map_size
= memory_map_size
;
1225 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
)
1227 struct lttng_ust_lib_ring_buffer
*buf
;
1228 struct ustctl_consumer_channel
*consumer_chan
;
1232 consumer_chan
= stream
->chan
;
1233 (void) ustctl_stream_close_wait_fd(stream
);
1234 (void) ustctl_stream_close_wakeup_fd(stream
);
1235 lib_ring_buffer_release_read(buf
, consumer_chan
->chan
->handle
);
1239 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*chan
)
1243 return shm_get_wait_fd(chan
->chan
->handle
,
1244 &chan
->chan
->handle
->chan
._ref
);
1247 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*chan
)
1251 return shm_get_wakeup_fd(chan
->chan
->handle
,
1252 &chan
->chan
->handle
->chan
._ref
);
1255 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
)
1257 struct lttng_ust_lib_ring_buffer
*buf
;
1258 struct ustctl_consumer_channel
*consumer_chan
;
1263 consumer_chan
= stream
->chan
;
1264 return shm_get_wait_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1267 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
)
1269 struct lttng_ust_lib_ring_buffer
*buf
;
1270 struct ustctl_consumer_channel
*consumer_chan
;
1275 consumer_chan
= stream
->chan
;
1276 return shm_get_wakeup_fd(consumer_chan
->chan
->handle
, &buf
->self
._ref
);
1279 /* For mmap mode, readable without "get" operation */
1281 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
)
1283 struct lttng_ust_lib_ring_buffer
*buf
;
1284 struct ustctl_consumer_channel
*consumer_chan
;
1289 consumer_chan
= stream
->chan
;
1290 return shmp(consumer_chan
->chan
->handle
, buf
->backend
.memory_map
);
1293 /* returns the length to mmap. */
1294 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
1297 struct ustctl_consumer_channel
*consumer_chan
;
1298 unsigned long mmap_buf_len
;
1299 struct channel
*chan
;
1303 consumer_chan
= stream
->chan
;
1304 chan
= consumer_chan
->chan
->chan
;
1305 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1307 mmap_buf_len
= chan
->backend
.buf_size
;
1308 if (chan
->backend
.extra_reader_sb
)
1309 mmap_buf_len
+= chan
->backend
.subbuf_size
;
1310 if (mmap_buf_len
> INT_MAX
)
1312 *len
= mmap_buf_len
;
1316 /* returns the maximum size for sub-buffers. */
1317 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
1320 struct ustctl_consumer_channel
*consumer_chan
;
1321 struct channel
*chan
;
1325 consumer_chan
= stream
->chan
;
1326 chan
= consumer_chan
->chan
->chan
;
1327 *len
= chan
->backend
.subbuf_size
;
1332 * For mmap mode, operate on the current packet (between get/put or
1333 * get_next/put_next).
1336 /* returns the offset of the subbuffer belonging to the mmap reader. */
1337 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
1340 struct channel
*chan
;
1341 unsigned long sb_bindex
;
1342 struct lttng_ust_lib_ring_buffer
*buf
;
1343 struct ustctl_consumer_channel
*consumer_chan
;
1348 consumer_chan
= stream
->chan
;
1349 chan
= consumer_chan
->chan
->chan
;
1350 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
1352 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
1353 buf
->backend
.buf_rsb
.id
);
1354 *off
= shmp(consumer_chan
->chan
->handle
,
1355 shmp_index(consumer_chan
->chan
->handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
1359 /* returns the size of the current sub-buffer, without padding (for mmap). */
1360 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
1363 struct ustctl_consumer_channel
*consumer_chan
;
1364 struct channel
*chan
;
1365 struct lttng_ust_lib_ring_buffer
*buf
;
1371 consumer_chan
= stream
->chan
;
1372 chan
= consumer_chan
->chan
->chan
;
1373 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1374 consumer_chan
->chan
->handle
);
1378 /* returns the size of the current sub-buffer, without padding (for mmap). */
1379 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
1382 struct ustctl_consumer_channel
*consumer_chan
;
1383 struct channel
*chan
;
1384 struct lttng_ust_lib_ring_buffer
*buf
;
1389 consumer_chan
= stream
->chan
;
1390 chan
= consumer_chan
->chan
->chan
;
1391 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
1392 consumer_chan
->chan
->handle
);
1393 *len
= PAGE_ALIGN(*len
);
1397 /* Get exclusive read access to the next sub-buffer that can be read. */
1398 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
)
1400 struct lttng_ust_lib_ring_buffer
*buf
;
1401 struct ustctl_consumer_channel
*consumer_chan
;
1406 consumer_chan
= stream
->chan
;
1407 return lib_ring_buffer_get_next_subbuf(buf
,
1408 consumer_chan
->chan
->handle
);
1412 /* Release exclusive sub-buffer access, move consumer forward. */
1413 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
)
1415 struct lttng_ust_lib_ring_buffer
*buf
;
1416 struct ustctl_consumer_channel
*consumer_chan
;
1421 consumer_chan
= stream
->chan
;
1422 lib_ring_buffer_put_next_subbuf(buf
, consumer_chan
->chan
->handle
);
1428 /* Get a snapshot of the current ring buffer producer and consumer positions */
1429 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
)
1431 struct lttng_ust_lib_ring_buffer
*buf
;
1432 struct ustctl_consumer_channel
*consumer_chan
;
1437 consumer_chan
= stream
->chan
;
1438 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
1439 &buf
->prod_snapshot
, consumer_chan
->chan
->handle
);
1442 /* Get the consumer position (iteration start) */
1443 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
1446 struct lttng_ust_lib_ring_buffer
*buf
;
1451 *pos
= buf
->cons_snapshot
;
1455 /* Get the producer position (iteration end) */
1456 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
1459 struct lttng_ust_lib_ring_buffer
*buf
;
1464 *pos
= buf
->prod_snapshot
;
1468 /* Get exclusive read access to the specified sub-buffer position */
1469 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
1472 struct lttng_ust_lib_ring_buffer
*buf
;
1473 struct ustctl_consumer_channel
*consumer_chan
;
1478 consumer_chan
= stream
->chan
;
1479 return lib_ring_buffer_get_subbuf(buf
, *pos
,
1480 consumer_chan
->chan
->handle
);
1483 /* Release exclusive sub-buffer access */
1484 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
)
1486 struct lttng_ust_lib_ring_buffer
*buf
;
1487 struct ustctl_consumer_channel
*consumer_chan
;
1492 consumer_chan
= stream
->chan
;
1493 lib_ring_buffer_put_subbuf(buf
, consumer_chan
->chan
->handle
);
1497 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
1498 int producer_active
)
1500 struct lttng_ust_lib_ring_buffer
*buf
;
1501 struct ustctl_consumer_channel
*consumer_chan
;
1505 consumer_chan
= stream
->chan
;
1506 lib_ring_buffer_switch_slow(buf
,
1507 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,
1508 consumer_chan
->chan
->handle
);
1512 struct lttng_ust_client_lib_ring_buffer_client_cb
*get_client_cb(
1513 struct lttng_ust_lib_ring_buffer
*buf
,
1514 struct lttng_ust_shm_handle
*handle
)
1516 struct channel
*chan
;
1517 const struct lttng_ust_lib_ring_buffer_config
*config
;
1518 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1520 chan
= shmp(handle
, buf
->backend
.chan
);
1521 config
= &chan
->backend
.config
;
1522 if (!config
->cb_ptr
)
1524 client_cb
= caa_container_of(config
->cb_ptr
,
1525 struct lttng_ust_client_lib_ring_buffer_client_cb
,
1530 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
1531 uint64_t *timestamp_begin
)
1533 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1534 struct lttng_ust_lib_ring_buffer
*buf
;
1535 struct lttng_ust_shm_handle
*handle
;
1537 if (!stream
|| !timestamp_begin
)
1540 handle
= stream
->chan
->chan
->handle
;
1541 client_cb
= get_client_cb(buf
, handle
);
1544 return client_cb
->timestamp_begin(buf
, handle
, timestamp_begin
);
1547 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
1548 uint64_t *timestamp_end
)
1550 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1551 struct lttng_ust_lib_ring_buffer
*buf
;
1552 struct lttng_ust_shm_handle
*handle
;
1554 if (!stream
|| !timestamp_end
)
1557 handle
= stream
->chan
->chan
->handle
;
1558 client_cb
= get_client_cb(buf
, handle
);
1561 return client_cb
->timestamp_end(buf
, handle
, timestamp_end
);
1564 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
1565 uint64_t *events_discarded
)
1567 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1568 struct lttng_ust_lib_ring_buffer
*buf
;
1569 struct lttng_ust_shm_handle
*handle
;
1571 if (!stream
|| !events_discarded
)
1574 handle
= stream
->chan
->chan
->handle
;
1575 client_cb
= get_client_cb(buf
, handle
);
1578 return client_cb
->events_discarded(buf
, handle
, events_discarded
);
1581 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
1582 uint64_t *content_size
)
1584 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1585 struct lttng_ust_lib_ring_buffer
*buf
;
1586 struct lttng_ust_shm_handle
*handle
;
1588 if (!stream
|| !content_size
)
1591 handle
= stream
->chan
->chan
->handle
;
1592 client_cb
= get_client_cb(buf
, handle
);
1595 return client_cb
->content_size(buf
, handle
, content_size
);
1598 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
1599 uint64_t *packet_size
)
1601 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1602 struct lttng_ust_lib_ring_buffer
*buf
;
1603 struct lttng_ust_shm_handle
*handle
;
1605 if (!stream
|| !packet_size
)
1608 handle
= stream
->chan
->chan
->handle
;
1609 client_cb
= get_client_cb(buf
, handle
);
1612 return client_cb
->packet_size(buf
, handle
, packet_size
);
1615 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
1616 uint64_t *stream_id
)
1618 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1619 struct lttng_ust_lib_ring_buffer
*buf
;
1620 struct lttng_ust_shm_handle
*handle
;
1622 if (!stream
|| !stream_id
)
1625 handle
= stream
->chan
->chan
->handle
;
1626 client_cb
= get_client_cb(buf
, handle
);
1629 return client_cb
->stream_id(buf
, handle
, stream_id
);
1632 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
1635 struct lttng_ust_client_lib_ring_buffer_client_cb
*client_cb
;
1636 struct lttng_ust_lib_ring_buffer
*buf
;
1637 struct lttng_ust_shm_handle
*handle
;
1642 handle
= stream
->chan
->chan
->handle
;
1643 client_cb
= get_client_cb(buf
, handle
);
1644 if (!client_cb
|| !client_cb
->current_timestamp
)
1646 return client_cb
->current_timestamp(buf
, handle
, ts
);
1649 #if defined(__x86_64__) || defined(__i386__)
1651 int ustctl_has_perf_counters(void)
1658 int ustctl_has_perf_counters(void)
1666 * Returns 0 on success, negative error value on error.
1668 int ustctl_recv_reg_msg(int sock
,
1669 enum ustctl_socket_type
*type
,
1676 uint32_t *bits_per_long
,
1677 uint32_t *uint8_t_alignment
,
1678 uint32_t *uint16_t_alignment
,
1679 uint32_t *uint32_t_alignment
,
1680 uint32_t *uint64_t_alignment
,
1681 uint32_t *long_alignment
,
1686 struct ustctl_reg_msg reg_msg
;
1688 len
= ustcomm_recv_unix_sock(sock
, ®_msg
, sizeof(reg_msg
));
1689 if (len
> 0 && len
!= sizeof(reg_msg
))
1696 if (reg_msg
.magic
== LTTNG_UST_COMM_MAGIC
) {
1697 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1698 BIG_ENDIAN
: LITTLE_ENDIAN
;
1699 } else if (reg_msg
.magic
== bswap_32(LTTNG_UST_COMM_MAGIC
)) {
1700 *byte_order
= BYTE_ORDER
== BIG_ENDIAN
?
1701 LITTLE_ENDIAN
: BIG_ENDIAN
;
1703 return -LTTNG_UST_ERR_INVAL_MAGIC
;
1705 switch (reg_msg
.socket_type
) {
1706 case 0: *type
= USTCTL_SOCKET_CMD
;
1708 case 1: *type
= USTCTL_SOCKET_NOTIFY
;
1711 return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE
;
1713 *major
= reg_msg
.major
;
1714 *minor
= reg_msg
.minor
;
1716 *ppid
= reg_msg
.ppid
;
1719 *bits_per_long
= reg_msg
.bits_per_long
;
1720 *uint8_t_alignment
= reg_msg
.uint8_t_alignment
;
1721 *uint16_t_alignment
= reg_msg
.uint16_t_alignment
;
1722 *uint32_t_alignment
= reg_msg
.uint32_t_alignment
;
1723 *uint64_t_alignment
= reg_msg
.uint64_t_alignment
;
1724 *long_alignment
= reg_msg
.long_alignment
;
1725 memcpy(name
, reg_msg
.name
, LTTNG_UST_ABI_PROCNAME_LEN
);
1726 if (reg_msg
.major
!= LTTNG_UST_ABI_MAJOR_VERSION
) {
1727 return -LTTNG_UST_ERR_UNSUP_MAJOR
;
1733 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
)
1735 struct ustcomm_notify_hdr header
;
1738 len
= ustcomm_recv_unix_sock(sock
, &header
, sizeof(header
));
1739 if (len
> 0 && len
!= sizeof(header
))
1745 switch (header
.notify_cmd
) {
1747 *notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1750 *notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1759 * Returns 0 on success, negative error value on error.
1761 int ustctl_recv_register_event(int sock
,
1768 struct ustctl_field
**fields
,
1769 char **model_emf_uri
)
1772 struct ustcomm_notify_event_msg msg
;
1773 size_t signature_len
, fields_len
, model_emf_uri_len
;
1774 char *a_sign
= NULL
, *a_model_emf_uri
= NULL
;
1775 struct ustctl_field
*a_fields
= NULL
;
1777 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1778 if (len
> 0 && len
!= sizeof(msg
))
1785 *session_objd
= msg
.session_objd
;
1786 *channel_objd
= msg
.channel_objd
;
1787 strncpy(event_name
, msg
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1788 event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
1789 *loglevel
= msg
.loglevel
;
1790 signature_len
= msg
.signature_len
;
1791 fields_len
= msg
.fields_len
;
1793 if (fields_len
% sizeof(*a_fields
) != 0) {
1797 model_emf_uri_len
= msg
.model_emf_uri_len
;
1799 /* recv signature. contains at least \0. */
1800 a_sign
= zmalloc(signature_len
);
1803 len
= ustcomm_recv_unix_sock(sock
, a_sign
, signature_len
);
1804 if (len
> 0 && len
!= signature_len
) {
1806 goto signature_error
;
1810 goto signature_error
;
1813 goto signature_error
;
1815 /* Enforce end of string */
1816 a_sign
[signature_len
- 1] = '\0';
1820 a_fields
= zmalloc(fields_len
);
1823 goto signature_error
;
1825 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1826 if (len
> 0 && len
!= fields_len
) {
1839 if (model_emf_uri_len
) {
1840 /* recv model_emf_uri_len */
1841 a_model_emf_uri
= zmalloc(model_emf_uri_len
);
1842 if (!a_model_emf_uri
) {
1846 len
= ustcomm_recv_unix_sock(sock
, a_model_emf_uri
,
1848 if (len
> 0 && len
!= model_emf_uri_len
) {
1859 /* Enforce end of string */
1860 a_model_emf_uri
[model_emf_uri_len
- 1] = '\0';
1863 *signature
= a_sign
;
1864 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1866 *model_emf_uri
= a_model_emf_uri
;
1871 free(a_model_emf_uri
);
1880 * Returns 0 on success, negative error value on error.
1882 int ustctl_reply_register_event(int sock
,
1888 struct ustcomm_notify_hdr header
;
1889 struct ustcomm_notify_event_reply r
;
1892 memset(&reply
, 0, sizeof(reply
));
1893 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_EVENT
;
1894 reply
.r
.ret_code
= ret_code
;
1895 reply
.r
.event_id
= id
;
1896 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1897 if (len
> 0 && len
!= sizeof(reply
))
1905 * Returns 0 on success, negative UST or system error value on error.
1907 int ustctl_recv_register_channel(int sock
,
1908 int *session_objd
, /* session descriptor (output) */
1909 int *channel_objd
, /* channel descriptor (output) */
1911 struct ustctl_field
**fields
)
1914 struct ustcomm_notify_channel_msg msg
;
1916 struct ustctl_field
*a_fields
;
1918 len
= ustcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
1919 if (len
> 0 && len
!= sizeof(msg
))
1926 *session_objd
= msg
.session_objd
;
1927 *channel_objd
= msg
.channel_objd
;
1928 fields_len
= msg
.ctx_fields_len
;
1930 if (fields_len
% sizeof(*a_fields
) != 0) {
1936 a_fields
= zmalloc(fields_len
);
1941 len
= ustcomm_recv_unix_sock(sock
, a_fields
, fields_len
);
1942 if (len
> 0 && len
!= fields_len
) {
1957 *nr_fields
= fields_len
/ sizeof(*a_fields
);
1967 * Returns 0 on success, negative error value on error.
1969 int ustctl_reply_register_channel(int sock
,
1971 enum ustctl_channel_header header_type
,
1976 struct ustcomm_notify_hdr header
;
1977 struct ustcomm_notify_channel_reply r
;
1980 memset(&reply
, 0, sizeof(reply
));
1981 reply
.header
.notify_cmd
= USTCTL_NOTIFY_CMD_CHANNEL
;
1982 reply
.r
.ret_code
= ret_code
;
1983 reply
.r
.chan_id
= chan_id
;
1984 switch (header_type
) {
1985 case USTCTL_CHANNEL_HEADER_COMPACT
:
1986 reply
.r
.header_type
= 1;
1988 case USTCTL_CHANNEL_HEADER_LARGE
:
1989 reply
.r
.header_type
= 2;
1992 reply
.r
.header_type
= 0;
1995 len
= ustcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1996 if (len
> 0 && len
!= sizeof(reply
))
2003 static __attribute__((constructor
))
2004 void ustctl_init(void)
2007 lttng_ust_clock_init();
2008 lttng_ring_buffer_metadata_client_init();
2009 lttng_ring_buffer_client_overwrite_init();
2010 lttng_ring_buffer_client_overwrite_rt_init();
2011 lttng_ring_buffer_client_discard_init();
2012 lttng_ring_buffer_client_discard_rt_init();
2013 lib_ringbuffer_signal_init();
2016 static __attribute__((destructor
))
2017 void ustctl_exit(void)
2019 lttng_ring_buffer_client_discard_rt_exit();
2020 lttng_ring_buffer_client_discard_exit();
2021 lttng_ring_buffer_client_overwrite_rt_exit();
2022 lttng_ring_buffer_client_overwrite_exit();
2023 lttng_ring_buffer_metadata_client_exit();