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
;
34 static int dummy_pipe
[2];
37 void __attribute__((constructor
)) setup_dummy_pipe(void)
40 /* Only dummy_pipe[0] is used */
42 /* FIXME: Handle pipe() failure */
46 inline int get_dummy_fd(void)
48 return dup(dummy_pipe
[0]);
52 void init_object(struct lttng_ust_object_data
*data
)
56 data
->shm_path
= NULL
;
58 data
->wait_pipe_path
= NULL
;
59 data
->memory_map_size
= 0;
62 int ustctl_release_handle(int sock
, int handle
)
64 struct ustcomm_ust_msg lum
;
65 struct ustcomm_ust_reply lur
;
69 memset(&lum
, 0, sizeof(lum
));
71 lum
.cmd
= LTTNG_UST_RELEASE
;
72 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
80 * If sock is negative, it means we don't have to notify the other side
81 * (e.g. application has already vanished).
83 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
)
90 if (data
->shm_fd
>= 0) {
91 ret
= close(data
->shm_fd
);
101 if (data
->wait_fd
>= 0) {
102 ret
= close(data
->wait_fd
);
108 if (data
->wait_pipe_path
) {
109 free(data
->wait_pipe_path
);
112 return ustctl_release_handle(sock
, data
->handle
);
116 * Send registration done packet to the application.
118 int ustctl_register_done(int sock
)
120 struct ustcomm_ust_msg lum
;
121 struct ustcomm_ust_reply lur
;
124 DBG("Sending register done command to %d", sock
);
125 memset(&lum
, 0, sizeof(lum
));
126 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
127 lum
.cmd
= LTTNG_UST_REGISTER_DONE
;
128 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
131 if (lur
.ret_code
!= USTCOMM_OK
) {
132 DBG("Return code: %s", ustcomm_get_readable_code(lur
.ret_code
));
142 * returns session handle.
144 int ustctl_create_session(int sock
)
146 struct ustcomm_ust_msg lum
;
147 struct ustcomm_ust_reply lur
;
148 int ret
, session_handle
;
151 memset(&lum
, 0, sizeof(lum
));
152 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
153 lum
.cmd
= LTTNG_UST_SESSION
;
154 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
157 session_handle
= lur
.ret_val
;
158 DBG("received session handle %u", session_handle
);
159 return session_handle
;
162 /* open the metadata global channel */
163 int ustctl_open_metadata(int sock
, int session_handle
,
164 struct lttng_ust_channel_attr
*chops
,
165 struct lttng_ust_object_data
**_metadata_data
)
167 struct ustcomm_ust_msg lum
;
168 struct ustcomm_ust_reply lur
;
169 struct lttng_ust_object_data
*metadata_data
;
171 char *shm_path
, *wait_pipe_path
;
173 if (!chops
|| !_metadata_data
)
176 metadata_data
= malloc(sizeof(*metadata_data
));
179 init_object(metadata_data
);
180 /* Create metadata channel */
181 memset(&lum
, 0, sizeof(lum
));
182 lum
.handle
= session_handle
;
183 lum
.cmd
= LTTNG_UST_METADATA
;
184 lum
.u
.channel
.overwrite
= chops
->overwrite
;
185 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
186 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
187 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
188 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
189 lum
.u
.channel
.output
= chops
->output
;
190 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
195 if (lur
.ret_code
!= USTCOMM_OK
) {
199 metadata_data
->handle
= lur
.ret_val
;
200 DBG("received metadata handle %u", metadata_data
->handle
);
201 metadata_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
203 shm_path
= ustcomm_recv_string(sock
);
207 DBG("Received shm path: %s\n", shm_path
);
208 metadata_data
->shm_fd
= get_dummy_fd();
209 metadata_data
->shm_path
= shm_path
;
213 * We need to get the second FD even if the first fails, because
214 * libust expects us to read the two FDs.
217 /* get wait pipe path */
218 wait_pipe_path
= ustcomm_recv_string(sock
);
219 if (!wait_pipe_path
) {
223 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
224 metadata_data
->wait_fd
= get_dummy_fd();
225 metadata_data
->wait_pipe_path
= wait_pipe_path
;
231 *_metadata_data
= metadata_data
;
235 (void) ustctl_release_object(sock
, metadata_data
);
240 int ustctl_create_channel(int sock
, int session_handle
,
241 struct lttng_ust_channel_attr
*chops
,
242 struct lttng_ust_object_data
**_channel_data
)
244 struct ustcomm_ust_msg lum
;
245 struct ustcomm_ust_reply lur
;
246 struct lttng_ust_object_data
*channel_data
;
248 char *shm_path
, *wait_pipe_path
;
250 if (!chops
|| !_channel_data
)
253 channel_data
= malloc(sizeof(*channel_data
));
256 init_object(channel_data
);
257 /* Create metadata channel */
258 memset(&lum
, 0, sizeof(lum
));
259 lum
.handle
= session_handle
;
260 lum
.cmd
= LTTNG_UST_CHANNEL
;
261 lum
.u
.channel
.overwrite
= chops
->overwrite
;
262 lum
.u
.channel
.subbuf_size
= chops
->subbuf_size
;
263 lum
.u
.channel
.num_subbuf
= chops
->num_subbuf
;
264 lum
.u
.channel
.switch_timer_interval
= chops
->switch_timer_interval
;
265 lum
.u
.channel
.read_timer_interval
= chops
->read_timer_interval
;
266 lum
.u
.channel
.output
= chops
->output
;
267 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
272 if (lur
.ret_code
!= USTCOMM_OK
) {
276 channel_data
->handle
= lur
.ret_val
;
277 DBG("received channel handle %u", channel_data
->handle
);
278 channel_data
->memory_map_size
= lur
.u
.channel
.memory_map_size
;
280 shm_path
= ustcomm_recv_string(sock
);
284 DBG("Received shm path: %s\n", shm_path
);
285 channel_data
->shm_fd
= get_dummy_fd();
286 channel_data
->shm_path
= shm_path
;
290 * We need to get the second FD even if the first fails, because
291 * libust expects us to read the two FDs.
293 /* get wait pipe path */
294 wait_pipe_path
= ustcomm_recv_string(sock
);
295 if (!wait_pipe_path
) {
299 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
300 channel_data
->wait_fd
= get_dummy_fd();
301 channel_data
->wait_pipe_path
= wait_pipe_path
;
306 *_channel_data
= channel_data
;
310 (void) ustctl_release_object(sock
, channel_data
);
316 * Return -ENOENT if no more stream is available for creation.
317 * Return 0 on success.
318 * Return negative error value on error.
320 int ustctl_create_stream(int sock
, struct lttng_ust_object_data
*channel_data
,
321 struct lttng_ust_object_data
**_stream_data
)
323 struct ustcomm_ust_msg lum
;
324 struct ustcomm_ust_reply lur
;
325 struct lttng_ust_object_data
*stream_data
;
327 char *shm_path
, *wait_pipe_path
;
329 if (!channel_data
|| !_stream_data
)
332 stream_data
= malloc(sizeof(*stream_data
));
335 init_object(stream_data
);
336 memset(&lum
, 0, sizeof(lum
));
337 lum
.handle
= channel_data
->handle
;
338 lum
.cmd
= LTTNG_UST_STREAM
;
339 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
344 if (lur
.ret_code
!= USTCOMM_OK
) {
349 stream_data
->handle
= lur
.ret_val
;
350 DBG("received stream handle %u", stream_data
->handle
);
351 stream_data
->memory_map_size
= lur
.u
.stream
.memory_map_size
;
353 shm_path
= ustcomm_recv_string(sock
);
357 DBG("Received shm path: %s\n", shm_path
);
358 stream_data
->shm_fd
= get_dummy_fd();
359 stream_data
->shm_path
= shm_path
;
363 * We need to get the second FD even if the first fails, because
364 * libust expects us to read the two FDs.
366 /* get wait pipe path */
367 wait_pipe_path
= ustcomm_recv_string(sock
);
368 if (!wait_pipe_path
) {
372 DBG("Received wait pipe path: %s\n", wait_pipe_path
);
373 stream_data
->wait_fd
= get_dummy_fd();
374 stream_data
->wait_pipe_path
= wait_pipe_path
;
379 *_stream_data
= stream_data
;
383 (void) ustctl_release_object(sock
, stream_data
);
388 int ustctl_create_event(int sock
, struct lttng_ust_event
*ev
,
389 struct lttng_ust_object_data
*channel_data
,
390 struct lttng_ust_object_data
**_event_data
)
392 struct ustcomm_ust_msg lum
;
393 struct ustcomm_ust_reply lur
;
394 struct lttng_ust_object_data
*event_data
;
397 if (!channel_data
|| !_event_data
)
400 event_data
= malloc(sizeof(*event_data
));
403 init_object(event_data
);
404 memset(&lum
, 0, sizeof(lum
));
405 lum
.handle
= channel_data
->handle
;
406 lum
.cmd
= LTTNG_UST_EVENT
;
407 strncpy(lum
.u
.event
.name
, ev
->name
,
408 LTTNG_UST_SYM_NAME_LEN
);
409 lum
.u
.event
.instrumentation
= ev
->instrumentation
;
410 lum
.u
.event
.loglevel_type
= ev
->loglevel_type
;
411 lum
.u
.event
.loglevel
= ev
->loglevel
;
412 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
417 event_data
->handle
= lur
.ret_val
;
418 DBG("received event handle %u", event_data
->handle
);
419 *_event_data
= event_data
;
423 int ustctl_add_context(int sock
, struct lttng_ust_context
*ctx
,
424 struct lttng_ust_object_data
*obj_data
,
425 struct lttng_ust_object_data
**_context_data
)
427 struct ustcomm_ust_msg lum
;
428 struct ustcomm_ust_reply lur
;
429 struct lttng_ust_object_data
*context_data
;
432 if (!obj_data
|| !_context_data
)
435 context_data
= malloc(sizeof(*context_data
));
438 init_object(context_data
);
439 memset(&lum
, 0, sizeof(lum
));
440 lum
.handle
= obj_data
->handle
;
441 lum
.cmd
= LTTNG_UST_CONTEXT
;
442 lum
.u
.context
.ctx
= ctx
->ctx
;
443 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
448 context_data
->handle
= lur
.ret_val
;
449 DBG("received context handle %u", context_data
->handle
);
450 *_context_data
= context_data
;
454 /* Enable event, channel and session ioctl */
455 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
)
457 struct ustcomm_ust_msg lum
;
458 struct ustcomm_ust_reply lur
;
464 memset(&lum
, 0, sizeof(lum
));
465 lum
.handle
= object
->handle
;
466 lum
.cmd
= LTTNG_UST_ENABLE
;
467 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
470 DBG("enabled handle %u", object
->handle
);
474 /* Disable event, channel and session ioctl */
475 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
)
477 struct ustcomm_ust_msg lum
;
478 struct ustcomm_ust_reply lur
;
484 memset(&lum
, 0, sizeof(lum
));
485 lum
.handle
= object
->handle
;
486 lum
.cmd
= LTTNG_UST_DISABLE
;
487 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
490 DBG("disable handle %u", object
->handle
);
494 int ustctl_start_session(int sock
, int handle
)
496 struct lttng_ust_object_data obj
;
499 return ustctl_enable(sock
, &obj
);
502 int ustctl_stop_session(int sock
, int handle
)
504 struct lttng_ust_object_data obj
;
507 return ustctl_disable(sock
, &obj
);
510 int ustctl_tracepoint_list(int sock
)
512 struct ustcomm_ust_msg lum
;
513 struct ustcomm_ust_reply lur
;
514 int ret
, tp_list_handle
;
516 memset(&lum
, 0, sizeof(lum
));
517 lum
.handle
= LTTNG_UST_ROOT_HANDLE
;
518 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST
;
519 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
522 tp_list_handle
= lur
.ret_val
;
523 DBG("received tracepoint list handle %u", tp_list_handle
);
524 return tp_list_handle
;
527 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
528 struct lttng_ust_tracepoint_iter
*iter
)
530 struct ustcomm_ust_msg lum
;
531 struct ustcomm_ust_reply lur
;
537 memset(&lum
, 0, sizeof(lum
));
538 lum
.handle
= tp_list_handle
;
539 lum
.cmd
= LTTNG_UST_TRACEPOINT_LIST_GET
;
540 ret
= ustcomm_send_app_cmd(sock
, &lum
, &lur
);
543 DBG("received tracepoint list entry name %s loglevel %d",
544 lur
.u
.tracepoint
.name
,
545 lur
.u
.tracepoint
.loglevel
);
546 memcpy(iter
, &lur
.u
.tracepoint
, sizeof(*iter
));
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);
690 /* Replace the object table pointer. */
691 ret
= munmap(handle
->table
->objects
[0].memory_map
,
692 handle
->table
->objects
[0].memory_map_size
);
697 handle
->table
->objects
[0].memory_map
= (char *) handle
->shadow_chan
;
698 handle
->table
->objects
[0].is_shadow
= 1;
702 /* Add stream to channel shm and map its shm into process memory */
703 int ustctl_add_stream(struct lttng_ust_shm_handle
*handle
,
704 struct lttng_ust_object_data
*stream_data
)
708 if (!handle
|| !stream_data
)
711 if (!stream_data
->handle
)
714 ret
= channel_handle_add_stream(handle
,
716 stream_data
->wait_fd
,
717 stream_data
->memory_map_size
);
719 ERR("add stream error\n");
723 * Set to -1 because the lttng_ust_shm_handle destruction will take care
724 * of closing shm_fd and wait_fd.
726 stream_data
->shm_fd
= -1;
727 stream_data
->wait_fd
= -1;
731 void ustctl_unmap_channel(struct lttng_ust_shm_handle
*handle
)
733 struct channel
*chan
;
736 chan
= shmp(handle
, handle
->chan
);
737 channel_destroy(chan
, handle
, 1);
741 * ustctl closes the shm_fd fds after mapping it.
743 struct lttng_ust_lib_ring_buffer
*ustctl_open_stream_read(struct lttng_ust_shm_handle
*handle
,
746 struct channel
*chan
;
747 int *shm_fd
, *wait_fd
;
748 char *shm_path
, *wait_pipe_path
;
749 uint64_t *memory_map_size
;
750 struct lttng_ust_lib_ring_buffer
*buf
;
756 chan
= handle
->shadow_chan
;
757 buf
= channel_get_ring_buffer(&chan
->backend
.config
,
760 &wait_fd
, &wait_pipe_path
,
764 ret
= lib_ring_buffer_open_read(buf
, handle
, 1);
768 * We can close shm_fd early, right after is has been mapped.
771 ret
= close(*shm_fd
);
773 perror("Error closing shm_fd");
780 void ustctl_close_stream_read(struct lttng_ust_shm_handle
*handle
,
781 struct lttng_ust_lib_ring_buffer
*buf
)
783 assert(handle
&& buf
);
784 lib_ring_buffer_release_read(buf
, handle
, 1);
787 /* For mmap mode, readable without "get" operation */
789 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle
*handle
,
790 struct lttng_ust_lib_ring_buffer
*buf
)
794 return shmp(handle
, buf
->backend
.memory_map
);
797 /* returns the length to mmap. */
798 int ustctl_get_mmap_len(struct lttng_ust_shm_handle
*handle
,
799 struct lttng_ust_lib_ring_buffer
*buf
,
802 unsigned long mmap_buf_len
;
803 struct channel
*chan
;
805 if (!handle
|| !buf
|| !len
)
808 chan
= handle
->shadow_chan
;
809 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
811 mmap_buf_len
= chan
->backend
.buf_size
;
812 if (chan
->backend
.extra_reader_sb
)
813 mmap_buf_len
+= chan
->backend
.subbuf_size
;
814 if (mmap_buf_len
> INT_MAX
)
820 /* returns the maximum size for sub-buffers. */
821 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle
*handle
,
822 struct lttng_ust_lib_ring_buffer
*buf
,
825 struct channel
*chan
;
827 if (!handle
|| !buf
|| !len
)
830 chan
= handle
->shadow_chan
;
831 *len
= chan
->backend
.subbuf_size
;
836 * For mmap mode, operate on the current packet (between get/put or
837 * get_next/put_next).
840 /* returns the offset of the subbuffer belonging to the mmap reader. */
841 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle
*handle
,
842 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *off
)
844 struct channel
*chan
;
845 unsigned long sb_bindex
;
847 if (!handle
|| !buf
|| !off
)
850 chan
= handle
->shadow_chan
;
851 if (chan
->backend
.config
.output
!= RING_BUFFER_MMAP
)
853 sb_bindex
= subbuffer_id_get_index(&chan
->backend
.config
,
854 buf
->backend
.buf_rsb
.id
);
855 *off
= shmp(handle
, shmp_index(handle
, buf
->backend
.array
, sb_bindex
)->shmp
)->mmap_offset
;
859 /* returns the size of the current sub-buffer, without padding (for mmap). */
860 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle
*handle
,
861 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
863 struct channel
*chan
;
865 if (!handle
|| !buf
|| !len
)
868 chan
= handle
->shadow_chan
;
869 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
874 /* returns the size of the current sub-buffer, without padding (for mmap). */
875 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle
*handle
,
876 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *len
)
878 struct channel
*chan
;
880 if (!handle
|| !buf
|| !len
)
883 chan
= handle
->shadow_chan
;
884 *len
= lib_ring_buffer_get_read_data_size(&chan
->backend
.config
, buf
,
886 *len
= PAGE_ALIGN(*len
);
890 /* Get exclusive read access to the next sub-buffer that can be read. */
891 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle
*handle
,
892 struct lttng_ust_lib_ring_buffer
*buf
)
897 return lib_ring_buffer_get_next_subbuf(buf
, handle
);
901 /* Release exclusive sub-buffer access, move consumer forward. */
902 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle
*handle
,
903 struct lttng_ust_lib_ring_buffer
*buf
)
908 lib_ring_buffer_put_next_subbuf(buf
, handle
);
914 /* Get a snapshot of the current ring buffer producer and consumer positions */
915 int ustctl_snapshot(struct lttng_ust_shm_handle
*handle
,
916 struct lttng_ust_lib_ring_buffer
*buf
)
921 return lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
922 &buf
->prod_snapshot
, handle
);
925 /* Get the consumer position (iteration start) */
926 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle
*handle
,
927 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
929 if (!handle
|| !buf
|| !pos
)
932 *pos
= buf
->cons_snapshot
;
936 /* Get the producer position (iteration end) */
937 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle
*handle
,
938 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
940 if (!handle
|| !buf
|| !pos
)
943 *pos
= buf
->prod_snapshot
;
947 /* Get exclusive read access to the specified sub-buffer position */
948 int ustctl_get_subbuf(struct lttng_ust_shm_handle
*handle
,
949 struct lttng_ust_lib_ring_buffer
*buf
, unsigned long *pos
)
951 if (!handle
|| !buf
|| !pos
)
954 return lib_ring_buffer_get_subbuf(buf
, *pos
, handle
);
957 /* Release exclusive sub-buffer access */
958 int ustctl_put_subbuf(struct lttng_ust_shm_handle
*handle
,
959 struct lttng_ust_lib_ring_buffer
*buf
)
964 lib_ring_buffer_put_subbuf(buf
, handle
);
968 void ustctl_flush_buffer(struct lttng_ust_shm_handle
*handle
,
969 struct lttng_ust_lib_ring_buffer
*buf
,
972 assert(handle
&& buf
);
973 lib_ring_buffer_switch_slow(buf
,
974 producer_active
? SWITCH_ACTIVE
: SWITCH_FLUSH
,