2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/socket.h>
28 #include <sys/types.h>
34 #include <bin/lttng-consumerd/health-consumerd.h>
35 #include <common/common.h>
36 #include <common/kernel-ctl/kernel-ctl.h>
37 #include <common/sessiond-comm/sessiond-comm.h>
38 #include <common/sessiond-comm/relayd.h>
39 #include <common/compat/fcntl.h>
40 #include <common/compat/endian.h>
41 #include <common/pipe.h>
42 #include <common/relayd/relayd.h>
43 #include <common/utils.h>
44 #include <common/consumer/consumer-stream.h>
45 #include <common/index/index.h>
46 #include <common/consumer/consumer-timer.h>
47 #include <common/optional.h>
48 #include <common/buffer-view.h>
49 #include <common/consumer/consumer.h>
50 #include <common/consumer/metadata-bucket.h>
52 #include "kernel-consumer.h"
54 extern struct lttng_consumer_global_data consumer_data
;
55 extern int consumer_poll_timeout
;
58 * Take a snapshot for a specific fd
60 * Returns 0 on success, < 0 on error
62 int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream
*stream
)
65 int infd
= stream
->wait_fd
;
67 ret
= kernctl_snapshot(infd
);
69 * -EAGAIN is not an error, it just means that there is no data to
72 if (ret
!= 0 && ret
!= -EAGAIN
) {
73 PERROR("Getting sub-buffer snapshot.");
80 * Sample consumed and produced positions for a specific fd.
82 * Returns 0 on success, < 0 on error.
84 int lttng_kconsumer_sample_snapshot_positions(
85 struct lttng_consumer_stream
*stream
)
89 return kernctl_snapshot_sample_positions(stream
->wait_fd
);
93 * Get the produced position
95 * Returns 0 on success, < 0 on error
97 int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream
*stream
,
101 int infd
= stream
->wait_fd
;
103 ret
= kernctl_snapshot_get_produced(infd
, pos
);
105 PERROR("kernctl_snapshot_get_produced");
112 * Get the consumerd position
114 * Returns 0 on success, < 0 on error
116 int lttng_kconsumer_get_consumed_snapshot(struct lttng_consumer_stream
*stream
,
120 int infd
= stream
->wait_fd
;
122 ret
= kernctl_snapshot_get_consumed(infd
, pos
);
124 PERROR("kernctl_snapshot_get_consumed");
131 int get_current_subbuf_addr(struct lttng_consumer_stream
*stream
,
135 unsigned long mmap_offset
;
136 const char *mmap_base
= stream
->mmap_base
;
138 ret
= kernctl_get_mmap_read_offset(stream
->wait_fd
, &mmap_offset
);
140 PERROR("Failed to get mmap read offset");
144 *addr
= mmap_base
+ mmap_offset
;
150 * Take a snapshot of all the stream of a channel
151 * RCU read-side lock must be held across this function to ensure existence of
152 * channel. The channel lock must be held by the caller.
154 * Returns 0 on success, < 0 on error
156 static int lttng_kconsumer_snapshot_channel(
157 struct lttng_consumer_channel
*channel
,
158 uint64_t key
, char *path
, uint64_t relayd_id
,
159 uint64_t nb_packets_per_stream
,
160 struct lttng_consumer_local_data
*ctx
)
163 struct lttng_consumer_stream
*stream
;
165 DBG("Kernel consumer snapshot channel %" PRIu64
, key
);
169 /* Splice is not supported yet for channel snapshot. */
170 if (channel
->output
!= CONSUMER_CHANNEL_MMAP
) {
171 ERR("Unsupported output type for channel \"%s\": mmap output is required to record a snapshot",
177 cds_list_for_each_entry(stream
, &channel
->streams
.head
, send_node
) {
178 unsigned long consumed_pos
, produced_pos
;
180 health_code_update();
183 * Lock stream because we are about to change its state.
185 pthread_mutex_lock(&stream
->lock
);
187 assert(channel
->trace_chunk
);
188 if (!lttng_trace_chunk_get(channel
->trace_chunk
)) {
190 * Can't happen barring an internal error as the channel
191 * holds a reference to the trace chunk.
193 ERR("Failed to acquire reference to channel's trace chunk");
197 assert(!stream
->trace_chunk
);
198 stream
->trace_chunk
= channel
->trace_chunk
;
201 * Assign the received relayd ID so we can use it for streaming. The streams
202 * are not visible to anyone so this is OK to change it.
204 stream
->net_seq_idx
= relayd_id
;
205 channel
->relayd_id
= relayd_id
;
206 if (relayd_id
!= (uint64_t) -1ULL) {
207 ret
= consumer_send_relayd_stream(stream
, path
);
209 ERR("sending stream to relayd");
213 ret
= consumer_stream_create_output_files(stream
,
218 DBG("Kernel consumer snapshot stream (%" PRIu64
")",
222 ret
= kernctl_buffer_flush_empty(stream
->wait_fd
);
225 * Doing a buffer flush which does not take into
226 * account empty packets. This is not perfect
227 * for stream intersection, but required as a
228 * fall-back when "flush_empty" is not
229 * implemented by lttng-modules.
231 ret
= kernctl_buffer_flush(stream
->wait_fd
);
233 ERR("Failed to flush kernel stream");
239 ret
= lttng_kconsumer_take_snapshot(stream
);
241 ERR("Taking kernel snapshot");
245 ret
= lttng_kconsumer_get_produced_snapshot(stream
, &produced_pos
);
247 ERR("Produced kernel snapshot position");
251 ret
= lttng_kconsumer_get_consumed_snapshot(stream
, &consumed_pos
);
253 ERR("Consumerd kernel snapshot position");
257 consumed_pos
= consumer_get_consume_start_pos(consumed_pos
,
258 produced_pos
, nb_packets_per_stream
,
259 stream
->max_sb_size
);
261 while ((long) (consumed_pos
- produced_pos
) < 0) {
263 unsigned long len
, padded_len
;
264 const char *subbuf_addr
;
265 struct lttng_buffer_view subbuf_view
;
267 health_code_update();
268 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos
);
270 ret
= kernctl_get_subbuf(stream
->wait_fd
, &consumed_pos
);
272 if (ret
!= -EAGAIN
) {
273 PERROR("kernctl_get_subbuf snapshot");
276 DBG("Kernel consumer get subbuf failed. Skipping it.");
277 consumed_pos
+= stream
->max_sb_size
;
278 stream
->chan
->lost_packets
++;
282 ret
= kernctl_get_subbuf_size(stream
->wait_fd
, &len
);
284 ERR("Snapshot kernctl_get_subbuf_size");
285 goto error_put_subbuf
;
288 ret
= kernctl_get_padded_subbuf_size(stream
->wait_fd
, &padded_len
);
290 ERR("Snapshot kernctl_get_padded_subbuf_size");
291 goto error_put_subbuf
;
294 ret
= get_current_subbuf_addr(stream
, &subbuf_addr
);
296 goto error_put_subbuf
;
299 subbuf_view
= lttng_buffer_view_init(
300 subbuf_addr
, 0, padded_len
);
301 read_len
= lttng_consumer_on_read_subbuffer_mmap(
302 stream
, &subbuf_view
,
305 * We write the padded len in local tracefiles but the data len
306 * when using a relay. Display the error but continue processing
307 * to try to release the subbuffer.
309 if (relayd_id
!= (uint64_t) -1ULL) {
310 if (read_len
!= len
) {
311 ERR("Error sending to the relay (ret: %zd != len: %lu)",
315 if (read_len
!= padded_len
) {
316 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
317 read_len
, padded_len
);
321 ret
= kernctl_put_subbuf(stream
->wait_fd
);
323 ERR("Snapshot kernctl_put_subbuf");
326 consumed_pos
+= stream
->max_sb_size
;
329 if (relayd_id
== (uint64_t) -1ULL) {
330 if (stream
->out_fd
>= 0) {
331 ret
= close(stream
->out_fd
);
333 PERROR("Kernel consumer snapshot close out_fd");
339 close_relayd_stream(stream
);
340 stream
->net_seq_idx
= (uint64_t) -1ULL;
342 lttng_trace_chunk_put(stream
->trace_chunk
);
343 stream
->trace_chunk
= NULL
;
344 pthread_mutex_unlock(&stream
->lock
);
352 ret
= kernctl_put_subbuf(stream
->wait_fd
);
354 ERR("Snapshot kernctl_put_subbuf error path");
357 pthread_mutex_unlock(&stream
->lock
);
364 * Read the whole metadata available for a snapshot.
365 * RCU read-side lock must be held across this function to ensure existence of
366 * metadata_channel. The channel lock must be held by the caller.
368 * Returns 0 on success, < 0 on error
370 static int lttng_kconsumer_snapshot_metadata(
371 struct lttng_consumer_channel
*metadata_channel
,
372 uint64_t key
, char *path
, uint64_t relayd_id
,
373 struct lttng_consumer_local_data
*ctx
)
375 int ret
, use_relayd
= 0;
377 struct lttng_consumer_stream
*metadata_stream
;
381 DBG("Kernel consumer snapshot metadata with key %" PRIu64
" at path %s",
386 metadata_stream
= metadata_channel
->metadata_stream
;
387 assert(metadata_stream
);
389 pthread_mutex_lock(&metadata_stream
->lock
);
390 assert(metadata_channel
->trace_chunk
);
391 assert(metadata_stream
->trace_chunk
);
393 /* Flag once that we have a valid relayd for the stream. */
394 if (relayd_id
!= (uint64_t) -1ULL) {
399 ret
= consumer_send_relayd_stream(metadata_stream
, path
);
404 ret
= consumer_stream_create_output_files(metadata_stream
,
412 health_code_update();
414 ret_read
= lttng_consumer_read_subbuffer(metadata_stream
, ctx
, true);
416 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
421 } while (ret_read
> 0);
424 close_relayd_stream(metadata_stream
);
425 metadata_stream
->net_seq_idx
= (uint64_t) -1ULL;
427 if (metadata_stream
->out_fd
>= 0) {
428 ret
= close(metadata_stream
->out_fd
);
430 PERROR("Kernel consumer snapshot metadata close out_fd");
432 * Don't go on error here since the snapshot was successful at this
433 * point but somehow the close failed.
436 metadata_stream
->out_fd
= -1;
437 lttng_trace_chunk_put(metadata_stream
->trace_chunk
);
438 metadata_stream
->trace_chunk
= NULL
;
444 pthread_mutex_unlock(&metadata_stream
->lock
);
445 cds_list_del(&metadata_stream
->send_node
);
446 consumer_stream_destroy(metadata_stream
, NULL
);
447 metadata_channel
->metadata_stream
= NULL
;
453 * Receive command from session daemon and process it.
455 * Return 1 on success else a negative value or 0.
457 int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data
*ctx
,
458 int sock
, struct pollfd
*consumer_sockpoll
)
461 enum lttcomm_return_code ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
462 struct lttcomm_consumer_msg msg
;
464 health_code_update();
466 ret
= lttcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
467 if (ret
!= sizeof(msg
)) {
469 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_CMD
);
475 health_code_update();
477 /* Deprecated command */
478 assert(msg
.cmd_type
!= LTTNG_CONSUMER_STOP
);
480 health_code_update();
482 /* relayd needs RCU read-side protection */
485 switch (msg
.cmd_type
) {
486 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET
:
488 /* Session daemon status message are handled in the following call. */
489 consumer_add_relayd_socket(msg
.u
.relayd_sock
.net_index
,
490 msg
.u
.relayd_sock
.type
, ctx
, sock
, consumer_sockpoll
,
491 &msg
.u
.relayd_sock
.sock
, msg
.u
.relayd_sock
.session_id
,
492 msg
.u
.relayd_sock
.relayd_session_id
);
495 case LTTNG_CONSUMER_ADD_CHANNEL
:
497 struct lttng_consumer_channel
*new_channel
;
499 const uint64_t chunk_id
= msg
.u
.channel
.chunk_id
.value
;
501 health_code_update();
503 /* First send a status message before receiving the fds. */
504 ret
= consumer_send_status_msg(sock
, ret_code
);
506 /* Somehow, the session daemon is not responding anymore. */
510 health_code_update();
512 DBG("consumer_add_channel %" PRIu64
, msg
.u
.channel
.channel_key
);
513 new_channel
= consumer_allocate_channel(msg
.u
.channel
.channel_key
,
514 msg
.u
.channel
.session_id
,
515 msg
.u
.channel
.chunk_id
.is_set
?
517 msg
.u
.channel
.pathname
,
519 msg
.u
.channel
.relayd_id
, msg
.u
.channel
.output
,
520 msg
.u
.channel
.tracefile_size
,
521 msg
.u
.channel
.tracefile_count
, 0,
522 msg
.u
.channel
.monitor
,
523 msg
.u
.channel
.live_timer_interval
,
524 msg
.u
.channel
.is_live
,
526 if (new_channel
== NULL
) {
527 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
530 new_channel
->nb_init_stream_left
= msg
.u
.channel
.nb_init_streams
;
531 switch (msg
.u
.channel
.output
) {
532 case LTTNG_EVENT_SPLICE
:
533 new_channel
->output
= CONSUMER_CHANNEL_SPLICE
;
535 case LTTNG_EVENT_MMAP
:
536 new_channel
->output
= CONSUMER_CHANNEL_MMAP
;
539 ERR("Channel output unknown %d", msg
.u
.channel
.output
);
543 /* Translate and save channel type. */
544 switch (msg
.u
.channel
.type
) {
545 case CONSUMER_CHANNEL_TYPE_DATA
:
546 case CONSUMER_CHANNEL_TYPE_METADATA
:
547 new_channel
->type
= msg
.u
.channel
.type
;
554 health_code_update();
556 if (ctx
->on_recv_channel
!= NULL
) {
557 ret_recv
= ctx
->on_recv_channel(new_channel
);
559 ret
= consumer_add_channel(new_channel
, ctx
);
560 } else if (ret_recv
< 0) {
564 ret
= consumer_add_channel(new_channel
, ctx
);
566 if (msg
.u
.channel
.type
== CONSUMER_CHANNEL_TYPE_DATA
&& !ret
) {
567 int monitor_start_ret
;
569 DBG("Consumer starting monitor timer");
570 consumer_timer_live_start(new_channel
,
571 msg
.u
.channel
.live_timer_interval
);
572 monitor_start_ret
= consumer_timer_monitor_start(
574 msg
.u
.channel
.monitor_timer_interval
);
575 if (monitor_start_ret
< 0) {
576 ERR("Starting channel monitoring timer failed");
582 health_code_update();
584 /* If we received an error in add_channel, we need to report it. */
586 ret
= consumer_send_status_msg(sock
, ret
);
595 case LTTNG_CONSUMER_ADD_STREAM
:
598 struct lttng_pipe
*stream_pipe
;
599 struct lttng_consumer_stream
*new_stream
;
600 struct lttng_consumer_channel
*channel
;
604 * Get stream's channel reference. Needed when adding the stream to the
607 channel
= consumer_find_channel(msg
.u
.stream
.channel_key
);
610 * We could not find the channel. Can happen if cpu hotplug
611 * happens while tearing down.
613 ERR("Unable to find channel key %" PRIu64
, msg
.u
.stream
.channel_key
);
614 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
617 health_code_update();
619 /* First send a status message before receiving the fds. */
620 ret
= consumer_send_status_msg(sock
, ret_code
);
622 /* Somehow, the session daemon is not responding anymore. */
623 goto error_add_stream_fatal
;
626 health_code_update();
628 if (ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
629 /* Channel was not found. */
630 goto error_add_stream_nosignal
;
635 ret
= lttng_consumer_poll_socket(consumer_sockpoll
);
638 goto error_add_stream_fatal
;
641 health_code_update();
643 /* Get stream file descriptor from socket */
644 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
645 if (ret
!= sizeof(fd
)) {
646 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_FD
);
650 health_code_update();
653 * Send status code to session daemon only if the recv works. If the
654 * above recv() failed, the session daemon is notified through the
655 * error socket and the teardown is eventually done.
657 ret
= consumer_send_status_msg(sock
, ret_code
);
659 /* Somehow, the session daemon is not responding anymore. */
660 goto error_add_stream_nosignal
;
663 health_code_update();
665 pthread_mutex_lock(&channel
->lock
);
666 new_stream
= consumer_stream_create(
673 channel
->trace_chunk
,
678 if (new_stream
== NULL
) {
683 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
686 pthread_mutex_unlock(&channel
->lock
);
687 goto error_add_stream_nosignal
;
690 new_stream
->wait_fd
= fd
;
691 ret
= kernctl_get_max_subbuf_size(new_stream
->wait_fd
,
692 &new_stream
->max_sb_size
);
694 pthread_mutex_unlock(&channel
->lock
);
695 ERR("Failed to get kernel maximal subbuffer size");
696 goto error_add_stream_nosignal
;
699 consumer_stream_update_channel_attributes(new_stream
,
703 * We've just assigned the channel to the stream so increment the
704 * refcount right now. We don't need to increment the refcount for
705 * streams in no monitor because we handle manually the cleanup of
706 * those. It is very important to make sure there is NO prior
707 * consumer_del_stream() calls or else the refcount will be unbalanced.
709 if (channel
->monitor
) {
710 uatomic_inc(&new_stream
->chan
->refcount
);
714 * The buffer flush is done on the session daemon side for the kernel
715 * so no need for the stream "hangup_flush_done" variable to be
716 * tracked. This is important for a kernel stream since we don't rely
717 * on the flush state of the stream to read data. It's not the case for
718 * user space tracing.
720 new_stream
->hangup_flush_done
= 0;
722 health_code_update();
724 pthread_mutex_lock(&new_stream
->lock
);
725 if (ctx
->on_recv_stream
) {
726 ret
= ctx
->on_recv_stream(new_stream
);
728 pthread_mutex_unlock(&new_stream
->lock
);
729 pthread_mutex_unlock(&channel
->lock
);
730 consumer_stream_free(new_stream
);
731 goto error_add_stream_nosignal
;
734 health_code_update();
736 if (new_stream
->metadata_flag
) {
737 channel
->metadata_stream
= new_stream
;
740 /* Do not monitor this stream. */
741 if (!channel
->monitor
) {
742 DBG("Kernel consumer add stream %s in no monitor mode with "
743 "relayd id %" PRIu64
, new_stream
->name
,
744 new_stream
->net_seq_idx
);
745 cds_list_add(&new_stream
->send_node
, &channel
->streams
.head
);
746 pthread_mutex_unlock(&new_stream
->lock
);
747 pthread_mutex_unlock(&channel
->lock
);
751 /* Send stream to relayd if the stream has an ID. */
752 if (new_stream
->net_seq_idx
!= (uint64_t) -1ULL) {
753 ret
= consumer_send_relayd_stream(new_stream
,
754 new_stream
->chan
->pathname
);
756 pthread_mutex_unlock(&new_stream
->lock
);
757 pthread_mutex_unlock(&channel
->lock
);
758 consumer_stream_free(new_stream
);
759 goto error_add_stream_nosignal
;
763 * If adding an extra stream to an already
764 * existing channel (e.g. cpu hotplug), we need
765 * to send the "streams_sent" command to relayd.
767 if (channel
->streams_sent_to_relayd
) {
768 ret
= consumer_send_relayd_streams_sent(
769 new_stream
->net_seq_idx
);
771 pthread_mutex_unlock(&new_stream
->lock
);
772 pthread_mutex_unlock(&channel
->lock
);
773 goto error_add_stream_nosignal
;
777 pthread_mutex_unlock(&new_stream
->lock
);
778 pthread_mutex_unlock(&channel
->lock
);
780 /* Get the right pipe where the stream will be sent. */
781 if (new_stream
->metadata_flag
) {
782 consumer_add_metadata_stream(new_stream
);
783 stream_pipe
= ctx
->consumer_metadata_pipe
;
785 consumer_add_data_stream(new_stream
);
786 stream_pipe
= ctx
->consumer_data_pipe
;
789 /* Visible to other threads */
790 new_stream
->globally_visible
= 1;
792 health_code_update();
794 ret
= lttng_pipe_write(stream_pipe
, &new_stream
, sizeof(new_stream
));
796 ERR("Consumer write %s stream to pipe %d",
797 new_stream
->metadata_flag
? "metadata" : "data",
798 lttng_pipe_get_writefd(stream_pipe
));
799 if (new_stream
->metadata_flag
) {
800 consumer_del_stream_for_metadata(new_stream
);
802 consumer_del_stream_for_data(new_stream
);
804 goto error_add_stream_nosignal
;
807 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64
,
808 new_stream
->name
, fd
, new_stream
->chan
->pathname
, new_stream
->relayd_stream_id
);
811 error_add_stream_nosignal
:
813 error_add_stream_fatal
:
816 case LTTNG_CONSUMER_STREAMS_SENT
:
818 struct lttng_consumer_channel
*channel
;
821 * Get stream's channel reference. Needed when adding the stream to the
824 channel
= consumer_find_channel(msg
.u
.sent_streams
.channel_key
);
827 * We could not find the channel. Can happen if cpu hotplug
828 * happens while tearing down.
830 ERR("Unable to find channel key %" PRIu64
,
831 msg
.u
.sent_streams
.channel_key
);
832 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
835 health_code_update();
838 * Send status code to session daemon.
840 ret
= consumer_send_status_msg(sock
, ret_code
);
841 if (ret
< 0 || ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
842 /* Somehow, the session daemon is not responding anymore. */
843 goto error_streams_sent_nosignal
;
846 health_code_update();
849 * We should not send this message if we don't monitor the
850 * streams in this channel.
852 if (!channel
->monitor
) {
853 goto end_error_streams_sent
;
856 health_code_update();
857 /* Send stream to relayd if the stream has an ID. */
858 if (msg
.u
.sent_streams
.net_seq_idx
!= (uint64_t) -1ULL) {
859 ret
= consumer_send_relayd_streams_sent(
860 msg
.u
.sent_streams
.net_seq_idx
);
862 goto error_streams_sent_nosignal
;
864 channel
->streams_sent_to_relayd
= true;
866 end_error_streams_sent
:
868 error_streams_sent_nosignal
:
871 case LTTNG_CONSUMER_UPDATE_STREAM
:
876 case LTTNG_CONSUMER_DESTROY_RELAYD
:
878 uint64_t index
= msg
.u
.destroy_relayd
.net_seq_idx
;
879 struct consumer_relayd_sock_pair
*relayd
;
881 DBG("Kernel consumer destroying relayd %" PRIu64
, index
);
883 /* Get relayd reference if exists. */
884 relayd
= consumer_find_relayd(index
);
885 if (relayd
== NULL
) {
886 DBG("Unable to find relayd %" PRIu64
, index
);
887 ret_code
= LTTCOMM_CONSUMERD_RELAYD_FAIL
;
891 * Each relayd socket pair has a refcount of stream attached to it
892 * which tells if the relayd is still active or not depending on the
895 * This will set the destroy flag of the relayd object and destroy it
896 * if the refcount reaches zero when called.
898 * The destroy can happen either here or when a stream fd hangs up.
901 consumer_flag_relayd_for_destroy(relayd
);
904 health_code_update();
906 ret
= consumer_send_status_msg(sock
, ret_code
);
908 /* Somehow, the session daemon is not responding anymore. */
914 case LTTNG_CONSUMER_DATA_PENDING
:
917 uint64_t id
= msg
.u
.data_pending
.session_id
;
919 DBG("Kernel consumer data pending command for id %" PRIu64
, id
);
921 ret
= consumer_data_pending(id
);
923 health_code_update();
925 /* Send back returned value to session daemon */
926 ret
= lttcomm_send_unix_sock(sock
, &ret
, sizeof(ret
));
928 PERROR("send data pending ret code");
933 * No need to send back a status message since the data pending
934 * returned value is the response.
938 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL
:
940 struct lttng_consumer_channel
*channel
;
941 uint64_t key
= msg
.u
.snapshot_channel
.key
;
943 channel
= consumer_find_channel(key
);
945 ERR("Channel %" PRIu64
" not found", key
);
946 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
948 pthread_mutex_lock(&channel
->lock
);
949 if (msg
.u
.snapshot_channel
.metadata
== 1) {
950 ret
= lttng_kconsumer_snapshot_metadata(channel
, key
,
951 msg
.u
.snapshot_channel
.pathname
,
952 msg
.u
.snapshot_channel
.relayd_id
, ctx
);
954 ERR("Snapshot metadata failed");
955 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
958 ret
= lttng_kconsumer_snapshot_channel(channel
, key
,
959 msg
.u
.snapshot_channel
.pathname
,
960 msg
.u
.snapshot_channel
.relayd_id
,
961 msg
.u
.snapshot_channel
.nb_packets_per_stream
,
964 ERR("Snapshot channel failed");
965 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
968 pthread_mutex_unlock(&channel
->lock
);
970 health_code_update();
972 ret
= consumer_send_status_msg(sock
, ret_code
);
974 /* Somehow, the session daemon is not responding anymore. */
979 case LTTNG_CONSUMER_DESTROY_CHANNEL
:
981 uint64_t key
= msg
.u
.destroy_channel
.key
;
982 struct lttng_consumer_channel
*channel
;
984 channel
= consumer_find_channel(key
);
986 ERR("Kernel consumer destroy channel %" PRIu64
" not found", key
);
987 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
990 health_code_update();
992 ret
= consumer_send_status_msg(sock
, ret_code
);
994 /* Somehow, the session daemon is not responding anymore. */
995 goto end_destroy_channel
;
998 health_code_update();
1000 /* Stop right now if no channel was found. */
1002 goto end_destroy_channel
;
1006 * This command should ONLY be issued for channel with streams set in
1009 assert(!channel
->monitor
);
1012 * The refcount should ALWAYS be 0 in the case of a channel in no
1015 assert(!uatomic_sub_return(&channel
->refcount
, 1));
1017 consumer_del_channel(channel
);
1018 end_destroy_channel
:
1021 case LTTNG_CONSUMER_DISCARDED_EVENTS
:
1025 struct lttng_consumer_channel
*channel
;
1026 uint64_t id
= msg
.u
.discarded_events
.session_id
;
1027 uint64_t key
= msg
.u
.discarded_events
.channel_key
;
1029 DBG("Kernel consumer discarded events command for session id %"
1030 PRIu64
", channel key %" PRIu64
, id
, key
);
1032 channel
= consumer_find_channel(key
);
1034 ERR("Kernel consumer discarded events channel %"
1035 PRIu64
" not found", key
);
1038 count
= channel
->discarded_events
;
1041 health_code_update();
1043 /* Send back returned value to session daemon */
1044 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1046 PERROR("send discarded events");
1052 case LTTNG_CONSUMER_LOST_PACKETS
:
1056 struct lttng_consumer_channel
*channel
;
1057 uint64_t id
= msg
.u
.lost_packets
.session_id
;
1058 uint64_t key
= msg
.u
.lost_packets
.channel_key
;
1060 DBG("Kernel consumer lost packets command for session id %"
1061 PRIu64
", channel key %" PRIu64
, id
, key
);
1063 channel
= consumer_find_channel(key
);
1065 ERR("Kernel consumer lost packets channel %"
1066 PRIu64
" not found", key
);
1069 count
= channel
->lost_packets
;
1072 health_code_update();
1074 /* Send back returned value to session daemon */
1075 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1077 PERROR("send lost packets");
1083 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1085 int channel_monitor_pipe
;
1087 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1088 /* Successfully received the command's type. */
1089 ret
= consumer_send_status_msg(sock
, ret_code
);
1094 ret
= lttcomm_recv_fds_unix_sock(sock
, &channel_monitor_pipe
,
1096 if (ret
!= sizeof(channel_monitor_pipe
)) {
1097 ERR("Failed to receive channel monitor pipe");
1101 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe
);
1102 ret
= consumer_timer_thread_set_channel_monitor_pipe(
1103 channel_monitor_pipe
);
1107 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1108 /* Set the pipe as non-blocking. */
1109 ret
= fcntl(channel_monitor_pipe
, F_GETFL
, 0);
1111 PERROR("fcntl get flags of the channel monitoring pipe");
1116 ret
= fcntl(channel_monitor_pipe
, F_SETFL
,
1117 flags
| O_NONBLOCK
);
1119 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1122 DBG("Channel monitor pipe set as non-blocking");
1124 ret_code
= LTTCOMM_CONSUMERD_ALREADY_SET
;
1126 ret
= consumer_send_status_msg(sock
, ret_code
);
1132 case LTTNG_CONSUMER_ROTATE_CHANNEL
:
1134 struct lttng_consumer_channel
*channel
;
1135 uint64_t key
= msg
.u
.rotate_channel
.key
;
1137 DBG("Consumer rotate channel %" PRIu64
, key
);
1139 channel
= consumer_find_channel(key
);
1141 ERR("Channel %" PRIu64
" not found", key
);
1142 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1145 * Sample the rotate position of all the streams in this channel.
1147 ret
= lttng_consumer_rotate_channel(channel
, key
,
1148 msg
.u
.rotate_channel
.relayd_id
,
1149 msg
.u
.rotate_channel
.metadata
,
1152 ERR("Rotate channel failed");
1153 ret_code
= LTTCOMM_CONSUMERD_ROTATION_FAIL
;
1156 health_code_update();
1158 ret
= consumer_send_status_msg(sock
, ret_code
);
1160 /* Somehow, the session daemon is not responding anymore. */
1161 goto error_rotate_channel
;
1164 /* Rotate the streams that are ready right now. */
1165 ret
= lttng_consumer_rotate_ready_streams(
1168 ERR("Rotate ready streams failed");
1172 error_rotate_channel
:
1175 case LTTNG_CONSUMER_INIT
:
1177 ret_code
= lttng_consumer_init_command(ctx
,
1178 msg
.u
.init
.sessiond_uuid
);
1179 health_code_update();
1180 ret
= consumer_send_status_msg(sock
, ret_code
);
1182 /* Somehow, the session daemon is not responding anymore. */
1187 case LTTNG_CONSUMER_CREATE_TRACE_CHUNK
:
1189 const struct lttng_credentials credentials
= {
1190 .uid
= msg
.u
.create_trace_chunk
.credentials
.value
.uid
,
1191 .gid
= msg
.u
.create_trace_chunk
.credentials
.value
.gid
,
1193 const bool is_local_trace
=
1194 !msg
.u
.create_trace_chunk
.relayd_id
.is_set
;
1195 const uint64_t relayd_id
=
1196 msg
.u
.create_trace_chunk
.relayd_id
.value
;
1197 const char *chunk_override_name
=
1198 *msg
.u
.create_trace_chunk
.override_name
?
1199 msg
.u
.create_trace_chunk
.override_name
:
1201 LTTNG_OPTIONAL(struct lttng_directory_handle
) chunk_directory_handle
=
1202 LTTNG_OPTIONAL_INIT
;
1205 * The session daemon will only provide a chunk directory file
1206 * descriptor for local traces.
1208 if (is_local_trace
) {
1211 /* Acnowledge the reception of the command. */
1212 ret
= consumer_send_status_msg(sock
,
1213 LTTCOMM_CONSUMERD_SUCCESS
);
1215 /* Somehow, the session daemon is not responding anymore. */
1219 ret
= lttcomm_recv_fds_unix_sock(sock
, &chunk_dirfd
, 1);
1220 if (ret
!= sizeof(chunk_dirfd
)) {
1221 ERR("Failed to receive trace chunk directory file descriptor");
1225 DBG("Received trace chunk directory fd (%d)",
1227 ret
= lttng_directory_handle_init_from_dirfd(
1228 &chunk_directory_handle
.value
,
1231 ERR("Failed to initialize chunk directory handle from directory file descriptor");
1232 if (close(chunk_dirfd
)) {
1233 PERROR("Failed to close chunk directory file descriptor");
1237 chunk_directory_handle
.is_set
= true;
1240 ret_code
= lttng_consumer_create_trace_chunk(
1241 !is_local_trace
? &relayd_id
: NULL
,
1242 msg
.u
.create_trace_chunk
.session_id
,
1243 msg
.u
.create_trace_chunk
.chunk_id
,
1244 (time_t) msg
.u
.create_trace_chunk
1245 .creation_timestamp
,
1246 chunk_override_name
,
1247 msg
.u
.create_trace_chunk
.credentials
.is_set
?
1250 chunk_directory_handle
.is_set
?
1251 &chunk_directory_handle
.value
:
1254 if (chunk_directory_handle
.is_set
) {
1255 lttng_directory_handle_fini(
1256 &chunk_directory_handle
.value
);
1258 goto end_msg_sessiond
;
1260 case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK
:
1262 enum lttng_trace_chunk_command_type close_command
=
1263 msg
.u
.close_trace_chunk
.close_command
.value
;
1264 const uint64_t relayd_id
=
1265 msg
.u
.close_trace_chunk
.relayd_id
.value
;
1266 struct lttcomm_consumer_close_trace_chunk_reply reply
;
1267 char path
[LTTNG_PATH_MAX
];
1269 ret_code
= lttng_consumer_close_trace_chunk(
1270 msg
.u
.close_trace_chunk
.relayd_id
.is_set
?
1273 msg
.u
.close_trace_chunk
.session_id
,
1274 msg
.u
.close_trace_chunk
.chunk_id
,
1275 (time_t) msg
.u
.close_trace_chunk
.close_timestamp
,
1276 msg
.u
.close_trace_chunk
.close_command
.is_set
?
1279 reply
.ret_code
= ret_code
;
1280 reply
.path_length
= strlen(path
) + 1;
1281 ret
= lttcomm_send_unix_sock(sock
, &reply
, sizeof(reply
));
1282 if (ret
!= sizeof(reply
)) {
1285 ret
= lttcomm_send_unix_sock(sock
, path
, reply
.path_length
);
1286 if (ret
!= reply
.path_length
) {
1291 case LTTNG_CONSUMER_TRACE_CHUNK_EXISTS
:
1293 const uint64_t relayd_id
=
1294 msg
.u
.trace_chunk_exists
.relayd_id
.value
;
1296 ret_code
= lttng_consumer_trace_chunk_exists(
1297 msg
.u
.trace_chunk_exists
.relayd_id
.is_set
?
1299 msg
.u
.trace_chunk_exists
.session_id
,
1300 msg
.u
.trace_chunk_exists
.chunk_id
);
1301 goto end_msg_sessiond
;
1309 * Return 1 to indicate success since the 0 value can be a socket
1310 * shutdown during the recv() or send() call.
1315 /* This will issue a consumer stop. */
1320 * The returned value here is not useful since either way we'll return 1 to
1321 * the caller because the session daemon socket management is done
1322 * elsewhere. Returning a negative code or 0 will shutdown the consumer.
1324 ret
= consumer_send_status_msg(sock
, ret_code
);
1330 health_code_update();
1336 * Sync metadata meaning request them to the session daemon and snapshot to the
1337 * metadata thread can consumer them.
1339 * Metadata stream lock MUST be acquired.
1341 enum sync_metadata_status
lttng_kconsumer_sync_metadata(
1342 struct lttng_consumer_stream
*metadata
)
1345 enum sync_metadata_status status
;
1349 ret
= kernctl_buffer_flush(metadata
->wait_fd
);
1351 ERR("Failed to flush kernel stream");
1352 status
= SYNC_METADATA_STATUS_ERROR
;
1356 ret
= kernctl_snapshot(metadata
->wait_fd
);
1358 if (errno
== EAGAIN
) {
1359 /* No new metadata, exit. */
1360 DBG("Sync metadata, no new kernel metadata");
1361 status
= SYNC_METADATA_STATUS_NO_DATA
;
1363 ERR("Sync metadata, taking kernel snapshot failed.");
1364 status
= SYNC_METADATA_STATUS_ERROR
;
1367 status
= SYNC_METADATA_STATUS_NEW_DATA
;
1375 int extract_common_subbuffer_info(struct lttng_consumer_stream
*stream
,
1376 struct stream_subbuffer
*subbuf
)
1380 ret
= kernctl_get_subbuf_size(
1381 stream
->wait_fd
, &subbuf
->info
.data
.subbuf_size
);
1386 ret
= kernctl_get_padded_subbuf_size(
1387 stream
->wait_fd
, &subbuf
->info
.data
.padded_subbuf_size
);
1397 int extract_metadata_subbuffer_info(struct lttng_consumer_stream
*stream
,
1398 struct stream_subbuffer
*subbuf
)
1402 ret
= extract_common_subbuffer_info(stream
, subbuf
);
1407 ret
= kernctl_get_metadata_version(
1408 stream
->wait_fd
, &subbuf
->info
.metadata
.version
);
1418 int extract_data_subbuffer_info(struct lttng_consumer_stream
*stream
,
1419 struct stream_subbuffer
*subbuf
)
1423 ret
= extract_common_subbuffer_info(stream
, subbuf
);
1428 ret
= kernctl_get_packet_size(
1429 stream
->wait_fd
, &subbuf
->info
.data
.packet_size
);
1431 PERROR("Failed to get sub-buffer packet size");
1435 ret
= kernctl_get_content_size(
1436 stream
->wait_fd
, &subbuf
->info
.data
.content_size
);
1438 PERROR("Failed to get sub-buffer content size");
1442 ret
= kernctl_get_timestamp_begin(
1443 stream
->wait_fd
, &subbuf
->info
.data
.timestamp_begin
);
1445 PERROR("Failed to get sub-buffer begin timestamp");
1449 ret
= kernctl_get_timestamp_end(
1450 stream
->wait_fd
, &subbuf
->info
.data
.timestamp_end
);
1452 PERROR("Failed to get sub-buffer end timestamp");
1456 ret
= kernctl_get_events_discarded(
1457 stream
->wait_fd
, &subbuf
->info
.data
.events_discarded
);
1459 PERROR("Failed to get sub-buffer events discarded count");
1463 ret
= kernctl_get_sequence_number(stream
->wait_fd
,
1464 &subbuf
->info
.data
.sequence_number
.value
);
1466 /* May not be supported by older LTTng-modules. */
1467 if (ret
!= -ENOTTY
) {
1468 PERROR("Failed to get sub-buffer sequence number");
1472 subbuf
->info
.data
.sequence_number
.is_set
= true;
1475 ret
= kernctl_get_stream_id(
1476 stream
->wait_fd
, &subbuf
->info
.data
.stream_id
);
1478 PERROR("Failed to get stream id");
1482 ret
= kernctl_get_instance_id(stream
->wait_fd
,
1483 &subbuf
->info
.data
.stream_instance_id
.value
);
1485 /* May not be supported by older LTTng-modules. */
1486 if (ret
!= -ENOTTY
) {
1487 PERROR("Failed to get stream instance id");
1491 subbuf
->info
.data
.stream_instance_id
.is_set
= true;
1498 int get_subbuffer_common(struct lttng_consumer_stream
*stream
,
1499 struct stream_subbuffer
*subbuffer
)
1503 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1506 * The caller only expects -ENODATA when there is no data to
1507 * read, but the kernel tracer returns -EAGAIN when there is
1508 * currently no data for a non-finalized stream, and -ENODATA
1509 * when there is no data for a finalized stream. Those can be
1510 * combined into a -ENODATA return value.
1512 if (ret
== -EAGAIN
) {
1519 ret
= stream
->read_subbuffer_ops
.extract_subbuffer_info(
1526 int get_next_subbuffer_splice(struct lttng_consumer_stream
*stream
,
1527 struct stream_subbuffer
*subbuffer
)
1531 ret
= get_subbuffer_common(stream
, subbuffer
);
1536 subbuffer
->buffer
.fd
= stream
->wait_fd
;
1542 int get_next_subbuffer_mmap(struct lttng_consumer_stream
*stream
,
1543 struct stream_subbuffer
*subbuffer
)
1548 ret
= get_subbuffer_common(stream
, subbuffer
);
1553 ret
= get_current_subbuf_addr(stream
, &addr
);
1558 subbuffer
->buffer
.buffer
= lttng_buffer_view_init(
1559 addr
, 0, subbuffer
->info
.data
.padded_subbuf_size
);
1565 int get_next_subbuffer_metadata_check(struct lttng_consumer_stream
*stream
,
1566 struct stream_subbuffer
*subbuffer
)
1572 ret
= kernctl_get_next_subbuf_metadata_check(stream
->wait_fd
,
1578 ret
= stream
->read_subbuffer_ops
.extract_subbuffer_info(
1584 LTTNG_OPTIONAL_SET(&subbuffer
->info
.metadata
.coherent
, coherent
);
1586 ret
= get_current_subbuf_addr(stream
, &addr
);
1591 subbuffer
->buffer
.buffer
= lttng_buffer_view_init(
1592 addr
, 0, subbuffer
->info
.data
.padded_subbuf_size
);
1593 DBG("Got metadata packet with padded_subbuf_size = %lu, coherent = %s",
1594 subbuffer
->info
.metadata
.padded_subbuf_size
,
1595 coherent
? "true" : "false");
1598 * The caller only expects -ENODATA when there is no data to read, but
1599 * the kernel tracer returns -EAGAIN when there is currently no data
1600 * for a non-finalized stream, and -ENODATA when there is no data for a
1601 * finalized stream. Those can be combined into a -ENODATA return value.
1603 if (ret
== -EAGAIN
) {
1611 int put_next_subbuffer(struct lttng_consumer_stream
*stream
,
1612 struct stream_subbuffer
*subbuffer
)
1614 const int ret
= kernctl_put_next_subbuf(stream
->wait_fd
);
1617 if (ret
== -EFAULT
) {
1618 PERROR("Error in unreserving sub buffer");
1619 } else if (ret
== -EIO
) {
1620 /* Should never happen with newer LTTng versions */
1621 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted");
1629 bool is_get_next_check_metadata_available(int tracer_fd
)
1631 const int ret
= kernctl_get_next_subbuf_metadata_check(tracer_fd
, NULL
);
1632 const bool available
= ret
!= -ENOTTY
;
1635 /* get succeeded, make sure to put the subbuffer. */
1636 kernctl_put_subbuf(tracer_fd
);
1643 int signal_metadata(struct lttng_consumer_stream
*stream
,
1644 struct lttng_consumer_local_data
*ctx
)
1646 ASSERT_LOCKED(stream
->metadata_rdv_lock
);
1647 return pthread_cond_broadcast(&stream
->metadata_rdv
) ? -errno
: 0;
1651 int lttng_kconsumer_set_stream_ops(
1652 struct lttng_consumer_stream
*stream
)
1656 if (stream
->metadata_flag
&& stream
->chan
->is_live
) {
1657 DBG("Attempting to enable metadata bucketization for live consumers");
1658 if (is_get_next_check_metadata_available(stream
->wait_fd
)) {
1659 DBG("Kernel tracer supports get_next_subbuffer_metadata_check, metadata will be accumulated until a coherent state is reached");
1660 stream
->read_subbuffer_ops
.get_next_subbuffer
=
1661 get_next_subbuffer_metadata_check
;
1662 ret
= consumer_stream_enable_metadata_bucketization(
1669 * The kernel tracer version is too old to indicate
1670 * when the metadata stream has reached a "coherent"
1671 * (parseable) point.
1673 * This means that a live viewer may see an incoherent
1674 * sequence of metadata and fail to parse it.
1676 WARN("Kernel tracer does not support get_next_subbuffer_metadata_check which may cause live clients to fail to parse the metadata stream");
1677 metadata_bucket_destroy(stream
->metadata_bucket
);
1678 stream
->metadata_bucket
= NULL
;
1681 stream
->read_subbuffer_ops
.on_sleep
= signal_metadata
;
1684 if (!stream
->read_subbuffer_ops
.get_next_subbuffer
) {
1685 if (stream
->chan
->output
== CONSUMER_CHANNEL_MMAP
) {
1686 stream
->read_subbuffer_ops
.get_next_subbuffer
=
1687 get_next_subbuffer_mmap
;
1689 stream
->read_subbuffer_ops
.get_next_subbuffer
=
1690 get_next_subbuffer_splice
;
1694 if (stream
->metadata_flag
) {
1695 stream
->read_subbuffer_ops
.extract_subbuffer_info
=
1696 extract_metadata_subbuffer_info
;
1698 stream
->read_subbuffer_ops
.extract_subbuffer_info
=
1699 extract_data_subbuffer_info
;
1700 if (stream
->chan
->is_live
) {
1701 stream
->read_subbuffer_ops
.send_live_beacon
=
1702 consumer_flush_kernel_index
;
1706 stream
->read_subbuffer_ops
.put_next_subbuffer
= put_next_subbuffer
;
1711 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream
*stream
)
1718 * Don't create anything if this is set for streaming or if there is
1719 * no current trace chunk on the parent channel.
1721 if (stream
->net_seq_idx
== (uint64_t) -1ULL && stream
->chan
->monitor
&&
1722 stream
->chan
->trace_chunk
) {
1723 ret
= consumer_stream_create_output_files(stream
, true);
1729 if (stream
->output
== LTTNG_EVENT_MMAP
) {
1730 /* get the len of the mmap region */
1731 unsigned long mmap_len
;
1733 ret
= kernctl_get_mmap_len(stream
->wait_fd
, &mmap_len
);
1735 PERROR("kernctl_get_mmap_len");
1736 goto error_close_fd
;
1738 stream
->mmap_len
= (size_t) mmap_len
;
1740 stream
->mmap_base
= mmap(NULL
, stream
->mmap_len
, PROT_READ
,
1741 MAP_PRIVATE
, stream
->wait_fd
, 0);
1742 if (stream
->mmap_base
== MAP_FAILED
) {
1743 PERROR("Error mmaping");
1745 goto error_close_fd
;
1749 ret
= lttng_kconsumer_set_stream_ops(stream
);
1751 goto error_close_fd
;
1754 /* we return 0 to let the library handle the FD internally */
1758 if (stream
->out_fd
>= 0) {
1761 err
= close(stream
->out_fd
);
1763 stream
->out_fd
= -1;
1770 * Check if data is still being extracted from the buffers for a specific
1771 * stream. Consumer data lock MUST be acquired before calling this function
1772 * and the stream lock.
1774 * Return 1 if the traced data are still getting read else 0 meaning that the
1775 * data is available for trace viewer reading.
1777 int lttng_kconsumer_data_pending(struct lttng_consumer_stream
*stream
)
1783 if (stream
->endpoint_status
!= CONSUMER_ENDPOINT_ACTIVE
) {
1788 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1790 /* There is still data so let's put back this subbuffer. */
1791 ret
= kernctl_put_subbuf(stream
->wait_fd
);
1793 ret
= 1; /* Data is pending */
1797 /* Data is NOT pending and ready to be read. */