2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * 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>
26 #include <usterr-signal-safe.h>
29 #include "../libringbuffer/backend.h"
30 #include "../libringbuffer/frontend.h"
32 volatile enum ust_loglevel ust_loglevel
;
35 void init_object(struct lttng_ust_object_data
*data
)
40 data
->memory_map_size
= 0;
43 int ustctl_release_handle(int sock
, int handle
)
45 struct ustcomm_ust_msg lum
;
46 struct ustcomm_ust_reply lur
;
50 memset(&lum
, 0, sizeof(lum
));
52 lum
.cmd
= LTTNG_UST_RELEASE
;
53 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
60 * If sock is negative, it means we don't have to notify the other side
61 * (e.g. application has already vanished).
63 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
70 if (data
->shm_fd
>= 0) {
71 ret
= close(data
->shm_fd
);
77 if (data
->wait_fd
>= 0) {
78 ret
= close(data
->wait_fd
);
84 return ustctl_release_handle(sock
, data
->handle
);
88 * Send registration done packet to the application.
90 int ustctl_register_done(int sock
)
92 struct ustcomm_ust_msg lum
;
93 struct ustcomm_ust_reply lur
;
96 DBG("Sending register done command to %d", sock
);
97 memset(&lum
, 0, sizeof(lum
));
98 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
99 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
100 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
107 * returns session handle.
109 int ustctl_create_session(int sock
)
111 struct ustcomm_ust_msg lum
;
112 struct ustcomm_ust_reply lur
;
113 int ret
, session_handle
;
116 memset(&lum
, 0, sizeof(lum
));
117 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
118 lum
.cmd
= LTTNG_UST_SESSION
;
119 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
122 session_handle
= lur
.ret_val
;
123 DBG("received session handle %u", session_handle
);
124 return session_handle
;
127 /* open the metadata global channel */
128 int ustctl_open_metadata(int sock
, int session_handle
,
129 struct lttng_ust_channel_attr
*chops
,
130 struct lttng_ust_object_data
**_metadata_data
)
132 struct ustcomm_ust_msg lum
;
133 struct ustcomm_ust_reply lur
;
134 struct lttng_ust_object_data
*metadata_data
;
137 if (!chops
|| !_metadata_data
)
140 metadata_data
= malloc(sizeof(*metadata_data
));
143 init_object(metadata_data
);
144 /* Create metadata channel */
145 memset(&lum
, 0, sizeof(lum
));
146 lum
.handle
= session_handle
;
147 lum
.cmd
= LTTNG_UST_METADATA
;
148 lum
.u
.channel
.overwrite
= chops
->overwrite
;
149 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
150 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
151 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
152 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
153 lum
.u
.channel
.output
= chops
->output
;
154 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
159 metadata_data
->handle
= lur
.ret_val
;
160 DBG("received metadata handle %u", metadata_data
->handle
);
161 metadata_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
163 ret
= ustcomm_recv_fd(sock
);
167 metadata_data
->shm_fd
= ret
;
169 * We need to get the second FD even if the first fails, because
170 * libust expects us to read the two FDs.
173 ret
= ustcomm_recv_fd(sock
);
177 metadata_data
->wait_fd
= ret
;
180 *_metadata_data
= metadata_data
;
184 (void) ustctl_release_object(sock
, metadata_data
);
189 int ustctl_create_channel(int sock
, int session_handle
,
190 struct lttng_ust_channel_attr
*chops
,
191 struct lttng_ust_object_data
**_channel_data
)
193 struct ustcomm_ust_msg lum
;
194 struct ustcomm_ust_reply lur
;
195 struct lttng_ust_object_data
*channel_data
;
198 if (!chops
|| !_channel_data
)
201 channel_data
= malloc(sizeof(*channel_data
));
204 init_object(channel_data
);
205 /* Create metadata channel */
206 memset(&lum
, 0, sizeof(lum
));
207 lum
.handle
= session_handle
;
208 lum
.cmd
= LTTNG_UST_CHANNEL
;
209 lum
.u
.channel
.overwrite
= chops
->overwrite
;
210 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
211 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
212 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
213 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
214 lum
.u
.channel
.output
= chops
->output
;
215 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
220 channel_data
->handle
= lur
.ret_val
;
221 DBG("received channel handle %u", channel_data
->handle
);
222 channel_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
224 ret
= ustcomm_recv_fd(sock
);
228 channel_data
->shm_fd
= ret
;
230 * We need to get the second FD even if the first fails, because
231 * libust expects us to read the two FDs.
234 ret
= ustcomm_recv_fd(sock
);
238 channel_data
->wait_fd
= ret
;
241 *_channel_data
= channel_data
;
245 (void) ustctl_release_object(sock
, channel_data
);
251 * Return -ENOENT if no more stream is available for creation.
252 * Return 0 on success.
253 * Return negative error value on system error.
254 * Return positive error value on UST error.
256 int ustctl_create_stream(int sock
, struct lttng_ust_object_data
*channel_data
,
257 struct lttng_ust_object_data
**_stream_data
)
259 struct ustcomm_ust_msg lum
;
260 struct ustcomm_ust_reply lur
;
261 struct lttng_ust_object_data
*stream_data
;
262 int ret
, fd
, err
= 0;
264 if (!channel_data
|| !_stream_data
)
267 stream_data
= malloc(sizeof(*stream_data
));
270 init_object(stream_data
);
271 memset(&lum
, 0, sizeof(lum
));
272 lum
.handle
= channel_data
->handle
;
273 lum
.cmd
= LTTNG_UST_STREAM
;
274 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
279 stream_data
->handle
= lur
.ret_val
;
280 DBG("received stream handle %u", stream_data
->handle
);
281 stream_data
->memory_map_size
= lur
.u
.stream
.memory_map_size
;
283 fd
= ustcomm_recv_fd(sock
);
287 stream_data
->shm_fd
= fd
;
289 * We need to get the second FD even if the first fails, because
290 * libust expects us to read the two FDs.
293 fd
= ustcomm_recv_fd(sock
);
297 stream_data
->wait_fd
= fd
;
300 *_stream_data
= stream_data
;
304 (void) ustctl_release_object(sock
, stream_data
);
309 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
310 struct lttng_ust_object_data
*channel_data
,
311 struct lttng_ust_object_data
**_event_data
)
313 struct ustcomm_ust_msg lum
;
314 struct ustcomm_ust_reply lur
;
315 struct lttng_ust_object_data
*event_data
;
318 if (!channel_data
|| !_event_data
)
321 event_data
= malloc(sizeof(*event_data
));
324 init_object(event_data
);
325 memset(&lum
, 0, sizeof(lum
));
326 lum
.handle
= channel_data
->handle
;
327 lum
.cmd
= LTTNG_UST_EVENT
;
328 strncpy(lum
.u
.event
.name
, ev
->name
,
329 LTTNG_UST_SYM_NAME_LEN
);
330 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
331 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
332 lum
.u
.event
.loglevel
= ev
->loglevel
;
333 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
338 event_data
->handle
= lur
.ret_val
;
339 DBG("received event handle %u", event_data
->handle
);
340 *_event_data
= event_data
;
344 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
345 struct lttng_ust_object_data
*obj_data
,
346 struct lttng_ust_object_data
**_context_data
)
348 struct ustcomm_ust_msg lum
;
349 struct ustcomm_ust_reply lur
;
350 struct lttng_ust_object_data
*context_data
;
353 if (!obj_data
|| !_context_data
)
356 context_data
= malloc(sizeof(*context_data
));
359 init_object(context_data
);
360 memset(&lum
, 0, sizeof(lum
));
361 lum
.handle
= obj_data
->handle
;
362 lum
.cmd
= LTTNG_UST_CONTEXT
;
363 lum
.u
.context
.ctx
= ctx
->ctx
;
364 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
369 context_data
->handle
= lur
.ret_val
;
370 DBG("received context handle %u", context_data
->handle
);
371 *_context_data
= context_data
;
375 int ustctl_set_filter(int sock
, struct lttng_ust_filter_bytecode
*bytecode
,
376 struct lttng_ust_object_data
*obj_data
)
378 struct ustcomm_ust_msg lum
;
379 struct ustcomm_ust_reply lur
;
385 memset(&lum
, 0, sizeof(lum
));
386 lum
.handle
= obj_data
->handle
;
387 lum
.cmd
= LTTNG_UST_FILTER
;
388 lum
.u
.filter
.data_size
= bytecode
->len
;
389 lum
.u
.filter
.reloc_offset
= bytecode
->reloc_offset
;
390 lum
.u
.filter
.seqnum
= bytecode
->seqnum
;
392 ret
= ustcomm_send_app_msg(sock
, &lum
);
395 /* send var len bytecode */
396 ret
= ustcomm_send_unix_sock(sock
, bytecode
->data
,
399 if (ret
== -ECONNRESET
)
400 fprintf(stderr
, "remote end closed connection\n");
403 if (ret
!= bytecode
->len
)
405 return ustcomm_recv_app_reply(sock
, &lur
, lum
.handle
, lum
.cmd
);
408 /* Enable event, channel and session ioctl */
409 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
411 struct ustcomm_ust_msg lum
;
412 struct ustcomm_ust_reply lur
;
418 memset(&lum
, 0, sizeof(lum
));
419 lum
.handle
= object
->handle
;
420 lum
.cmd
= LTTNG_UST_ENABLE
;
421 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
424 DBG("enabled handle %u", object
->handle
);
428 /* Disable event, channel and session ioctl */
429 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
431 struct ustcomm_ust_msg lum
;
432 struct ustcomm_ust_reply lur
;
438 memset(&lum
, 0, sizeof(lum
));
439 lum
.handle
= object
->handle
;
440 lum
.cmd
= LTTNG_UST_DISABLE
;
441 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
444 DBG("disable handle %u", object
->handle
);
448 int ustctl_start_session(int sock
, int handle
)
450 struct lttng_ust_object_data obj
;
453 return ustctl_enable(sock
, &obj
);
456 int ustctl_stop_session(int sock
, int handle
)
458 struct lttng_ust_object_data obj
;
461 return ustctl_disable(sock
, &obj
);
464 int ustctl_tracepoint_list(int sock
)
466 struct ustcomm_ust_msg lum
;
467 struct ustcomm_ust_reply lur
;
468 int ret
, tp_list_handle
;
470 memset(&lum
, 0, sizeof(lum
));
471 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
472 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
473 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
476 tp_list_handle
= lur
.ret_val
;
477 DBG("received tracepoint list handle %u", tp_list_handle
);
478 return tp_list_handle
;
481 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
482 struct lttng_ust_tracepoint_iter
*iter
)
484 struct ustcomm_ust_msg lum
;
485 struct ustcomm_ust_reply lur
;
491 memset(&lum
, 0, sizeof(lum
));
492 lum
.handle
= tp_list_handle
;
493 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
494 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
497 DBG("received tracepoint list entry name %s loglevel %d",
498 lur
.u
.tracepoint
.name
,
499 lur
.u
.tracepoint
.loglevel
);
500 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
504 int ustctl_tracepoint_field_list(int sock
)
506 struct ustcomm_ust_msg lum
;
507 struct ustcomm_ust_reply lur
;
508 int ret
, tp_field_list_handle
;
510 memset(&lum
, 0, sizeof(lum
));
511 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
512 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST
;
513 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
516 tp_field_list_handle
= lur
.ret_val
;
517 DBG("received tracepoint field list handle %u", tp_field_list_handle
);
518 return tp_field_list_handle
;
521 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
522 struct lttng_ust_field_iter
*iter
)
524 struct ustcomm_ust_msg lum
;
525 struct ustcomm_ust_reply lur
;
532 memset(&lum
, 0, sizeof(lum
));
533 lum
.handle
= tp_field_list_handle
;
534 lum
.cmd
= LTTNG_UST_TRACEPOINT_FIELD_LIST_GET
;
535 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
538 len
= ustcomm_recv_unix_sock(sock
, iter
, sizeof(*iter
));
539 if (len
!= sizeof(*iter
)) {
542 DBG("received tracepoint field list entry event_name %s event_loglevel %d field_name %s field_type %d",
550 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
)
552 struct ustcomm_ust_msg lum
;
553 struct ustcomm_ust_reply lur
;
559 memset(&lum
, 0, sizeof(lum
));
560 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
561 lum
.cmd
= LTTNG_UST_TRACER_VERSION
;
562 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
565 memcpy(v
, &lur
.u
.version
, sizeof(*v
));
566 DBG("received tracer version");
570 int ustctl_wait_quiescent(int sock
)
572 struct ustcomm_ust_msg lum
;
573 struct ustcomm_ust_reply lur
;
576 memset(&lum
, 0, sizeof(lum
));
577 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
578 lum
.cmd
= LTTNG_UST_WAIT_QUIESCENT
;
579 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
582 DBG("waited for quiescent state");
586 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
)
594 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
)
596 struct ustcomm_ust_msg lum
;
597 struct ustcomm_ust_reply lur
;
603 memset(&lum
, 0, sizeof(lum
));
604 lum
.handle
= object
->handle
;
605 lum
.cmd
= LTTNG_UST_FLUSH_BUFFER
;
606 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
609 DBG("flushed buffer handle %u", object
->handle
);
613 /* Buffer operations */
615 /* Map channel shm into process memory */
616 struct lttng_ust_shm_handle
*ustctl_map_channel(struct lttng_ust_object_data
*chan_data
)
618 struct lttng_ust_shm_handle
*handle
;
619 struct channel
*chan
;
621 struct lttng_ust_lib_ring_buffer_config
*config
;
627 handle
= channel_handle_create(chan_data
->shm_fd
,
629 chan_data
->memory_map_size
);
631 ERR("create handle error");
635 * Set to -1, and then close the shm fd, and set the handle shm
636 * fd to -1 too. We don't need the shm fds after they have been
638 * The wait_fd is set to -1 in chan_data because it is now owned
641 chan_data
->shm_fd
= -1;
642 chan_data
->wait_fd
= -1;
644 /* chan is object 0. This is hardcoded. */
645 if (handle
->table
->objects
[0].shm_fd
>= 0) {
646 ret
= close(handle
->table
->objects
[0].shm_fd
);
648 perror("Error closing shm_fd");
650 handle
->table
->objects
[0].shm_fd
= -1;
654 * TODO: add consistency checks to be resilient if the
655 * application try to feed us with incoherent channel structure
658 chan
= shmp(handle
, handle
->chan
);
659 /* chan is object 0. This is hardcoded. */
660 chan_size
= handle
->table
->objects
[0].allocated_len
;
661 handle
->shadow_chan
= malloc(chan_size
);
662 if (!handle
->shadow_chan
) {
663 channel_destroy(chan
, handle
, 1);
666 memcpy(handle
->shadow_chan
, chan
, chan_size
);
668 * The callback pointers in the producer are invalid in the
669 * consumer. We need to look them up here.
671 config
= &handle
->shadow_chan
->backend
.config
;
672 switch (config
->client_type
) {
673 case LTTNG_CLIENT_METADATA
:
674 memcpy(&config
->cb
, lttng_client_callbacks_metadata
,
677 case LTTNG_CLIENT_DISCARD
:
678 memcpy(&config
->cb
, lttng_client_callbacks_discard
,
681 case LTTNG_CLIENT_OVERWRITE
:
682 memcpy(&config
->cb
, lttng_client_callbacks_overwrite
,
686 ERR("Unknown client type %d", config
->client_type
);
687 channel_destroy(chan
, handle
, 1);
688 free(handle
->shadow_chan
);
691 /* Replace the object table pointer. */
692 ret
= munmap(handle
->table
->objects
[0].memory_map
,
693 handle
->table
->objects
[0].memory_map_size
);
698 handle
->table
->objects
[0].memory_map
= (char *) handle
->shadow_chan
;
699 handle
->table
->objects
[0].is_shadow
= 1;
703 /* Add stream to channel shm and map its shm into process memory */
704 int ustctl_add_stream(struct lttng_ust_shm_handle
*handle
,
705 struct lttng_ust_object_data
*stream_data
)
709 if (!handle
|| !stream_data
)
712 if (!stream_data
->handle
)
715 ret
= channel_handle_add_stream(handle
,
717 stream_data
->wait_fd
,
718 stream_data
->memory_map_size
);
720 ERR("add stream error\n");
724 * Set to -1 because the lttng_ust_shm_handle destruction will take care
725 * of closing shm_fd and wait_fd.
727 stream_data
->shm_fd
= -1;
728 stream_data
->wait_fd
= -1;
732 void ustctl_unmap_channel(struct lttng_ust_shm_handle
*handle
)
734 struct channel
*chan
;
737 chan
= shmp(handle
, handle
->chan
);
738 channel_destroy(chan
, handle
, 1);
739 free(handle
->shadow_chan
);
743 * ustctl closes the shm_fd fds after mapping it.
745 struct lttng_ust_lib_ring_buffer
*ustctl_open_stream_read(struct lttng_ust_shm_handle
*handle
,
748 struct channel
*chan
;
749 int *shm_fd
, *wait_fd
;
750 uint64_t *memory_map_size
;
751 struct lttng_ust_lib_ring_buffer
*buf
;
757 chan
= handle
->shadow_chan
;
758 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
759 chan
, cpu
, handle
, &shm_fd
, &wait_fd
, &memory_map_size
);
762 ret
= lib_ring_buffer_open_read(buf
, handle
, 1);
766 * We can close shm_fd early, right after is has been mapped.
769 ret
= close(*shm_fd
);
771 perror("Error closing shm_fd");
778 void ustctl_close_stream_read(struct lttng_ust_shm_handle
*handle
,
779 struct lttng_ust_lib_ring_buffer
*buf
)
781 assert(handle
&& buf
);
782 lib_ring_buffer_release_read(buf
, handle
, 1);
785 /* For mmap mode, readable without "get" operation */
787 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle
*handle
,
788 struct lttng_ust_lib_ring_buffer
*buf
)
792 return shmp(handle
, buf
->backend
.memory_map
);
795 /* returns the length to mmap. */
796 int ustctl_get_mmap_len(struct lttng_ust_shm_handle
*handle
,
797 struct lttng_ust_lib_ring_buffer
*buf
,
800 unsigned long mmap_buf_len
;
801 struct channel
*chan
;
803 if (!handle
|| !buf
|| !len
)
806 chan
= handle
->shadow_chan
;
807 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
809 mmap_buf_len
= chan
->backend
.buf_size
;
810 if (chan
->backend
.extra_reader_sb
)
811 mmap_buf_len
+= chan
->backend
.subbuf_size
;
812 if (mmap_buf_len
> INT_MAX
)
818 /* returns the maximum size for sub-buffers. */
819 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle
*handle
,
820 struct lttng_ust_lib_ring_buffer
*buf
,
823 struct channel
*chan
;
825 if (!handle
|| !buf
|| !len
)
828 chan
= handle
->shadow_chan
;
829 *len
= chan
->backend
.subbuf_size
;
834 * For mmap mode, operate on the current packet (between get/put or
835 * get_next/put_next).
838 /* returns the offset of the subbuffer belonging to the mmap reader. */
839 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle
*handle
,
840 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *off
)
842 struct channel
*chan
;
843 unsigned long sb_bindex
;
845 if (!handle
|| !buf
|| !off
)
848 chan
= handle
->shadow_chan
;
849 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
851 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
852 buf
->backend
.buf_rsb
.id
);
853 *off
= shmp(handle
, shmp_index(handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
857 /* returns the size of the current sub-buffer, without padding (for mmap). */
858 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle
*handle
,
859 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
861 struct channel
*chan
;
863 if (!handle
|| !buf
|| !len
)
866 chan
= handle
->shadow_chan
;
867 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
872 /* returns the size of the current sub-buffer, without padding (for mmap). */
873 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle
*handle
,
874 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
876 struct channel
*chan
;
878 if (!handle
|| !buf
|| !len
)
881 chan
= handle
->shadow_chan
;
882 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
884 *len
= PAGE_ALIGN(*len
);
888 /* Get exclusive read access to the next sub-buffer that can be read. */
889 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle
*handle
,
890 struct lttng_ust_lib_ring_buffer
*buf
)
895 return lib_ring_buffer_get_next_subbuf(buf
, handle
);
899 /* Release exclusive sub-buffer access, move consumer forward. */
900 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle
*handle
,
901 struct lttng_ust_lib_ring_buffer
*buf
)
906 lib_ring_buffer_put_next_subbuf(buf
, handle
);
912 /* Get a snapshot of the current ring buffer producer and consumer positions */
913 int ustctl_snapshot(struct lttng_ust_shm_handle
*handle
,
914 struct lttng_ust_lib_ring_buffer
*buf
)
919 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
920 &buf
->prod_snapshot
, handle
);
923 /* Get the consumer position (iteration start) */
924 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle
*handle
,
925 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
927 if (!handle
|| !buf
|| !pos
)
930 *pos
= buf
->cons_snapshot
;
934 /* Get the producer position (iteration end) */
935 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle
*handle
,
936 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
938 if (!handle
|| !buf
|| !pos
)
941 *pos
= buf
->prod_snapshot
;
945 /* Get exclusive read access to the specified sub-buffer position */
946 int ustctl_get_subbuf(struct lttng_ust_shm_handle
*handle
,
947 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
949 if (!handle
|| !buf
|| !pos
)
952 return lib_ring_buffer_get_subbuf(buf
, *pos
, handle
);
955 /* Release exclusive sub-buffer access */
956 int ustctl_put_subbuf(struct lttng_ust_shm_handle
*handle
,
957 struct lttng_ust_lib_ring_buffer
*buf
)
962 lib_ring_buffer_put_subbuf(buf
, handle
);
966 void ustctl_flush_buffer(struct lttng_ust_shm_handle
*handle
,
967 struct lttng_ust_lib_ring_buffer
*buf
,
970 assert(handle
&& buf
);
971 lib_ring_buffer_switch_slow(buf
,
972 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,