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>
33 #include <bin/lttng-consumerd/health-consumerd.h>
34 #include <common/common.h>
35 #include <common/kernel-ctl/kernel-ctl.h>
36 #include <common/sessiond-comm/sessiond-comm.h>
37 #include <common/sessiond-comm/relayd.h>
38 #include <common/compat/fcntl.h>
39 #include <common/compat/endian.h>
40 #include <common/pipe.h>
41 #include <common/relayd/relayd.h>
42 #include <common/utils.h>
43 #include <common/consumer/consumer-stream.h>
44 #include <common/index/index.h>
45 #include <common/consumer/consumer-timer.h>
47 #include "kernel-consumer.h"
49 extern struct lttng_consumer_global_data consumer_data
;
50 extern int consumer_poll_timeout
;
53 * Take a snapshot for a specific fd
55 * Returns 0 on success, < 0 on error
57 int lttng_kconsumer_take_snapshot(struct lttng_consumer_stream
*stream
)
60 int infd
= stream
->wait_fd
;
62 ret
= kernctl_snapshot(infd
);
64 * -EAGAIN is not an error, it just means that there is no data to
67 if (ret
!= 0 && ret
!= -EAGAIN
) {
68 PERROR("Getting sub-buffer snapshot.");
75 * Sample consumed and produced positions for a specific fd.
77 * Returns 0 on success, < 0 on error.
79 int lttng_kconsumer_sample_snapshot_positions(
80 struct lttng_consumer_stream
*stream
)
84 return kernctl_snapshot_sample_positions(stream
->wait_fd
);
88 * Get the produced position
90 * Returns 0 on success, < 0 on error
92 int lttng_kconsumer_get_produced_snapshot(struct lttng_consumer_stream
*stream
,
96 int infd
= stream
->wait_fd
;
98 ret
= kernctl_snapshot_get_produced(infd
, pos
);
100 PERROR("kernctl_snapshot_get_produced");
107 * Get the consumerd position
109 * Returns 0 on success, < 0 on error
111 int lttng_kconsumer_get_consumed_snapshot(struct lttng_consumer_stream
*stream
,
115 int infd
= stream
->wait_fd
;
117 ret
= kernctl_snapshot_get_consumed(infd
, pos
);
119 PERROR("kernctl_snapshot_get_consumed");
126 * Take a snapshot of all the stream of a channel
127 * RCU read-side lock must be held across this function to ensure existence of
130 * Returns 0 on success, < 0 on error
132 static int lttng_kconsumer_snapshot_channel(
133 struct lttng_consumer_channel
*channel
,
134 uint64_t key
, char *path
, uint64_t relayd_id
,
135 uint64_t nb_packets_per_stream
,
136 struct lttng_consumer_local_data
*ctx
)
139 struct lttng_consumer_stream
*stream
;
141 DBG("Kernel consumer snapshot channel %" PRIu64
, key
);
145 /* Splice is not supported yet for channel snapshot. */
146 if (channel
->output
!= CONSUMER_CHANNEL_MMAP
) {
147 ERR("Unsupported output type for channel \"%s\": mmap output is required to record a snapshot",
153 cds_list_for_each_entry(stream
, &channel
->streams
.head
, send_node
) {
154 unsigned long consumed_pos
, produced_pos
;
156 health_code_update();
159 * Lock stream because we are about to change its state.
161 pthread_mutex_lock(&stream
->lock
);
164 * Assign the received relayd ID so we can use it for streaming. The streams
165 * are not visible to anyone so this is OK to change it.
167 stream
->net_seq_idx
= relayd_id
;
168 channel
->relayd_id
= relayd_id
;
169 if (relayd_id
!= (uint64_t) -1ULL) {
170 ret
= consumer_send_relayd_stream(stream
, path
);
172 ERR("sending stream to relayd");
176 ret
= utils_create_stream_file(path
, stream
->name
,
177 stream
->chan
->tracefile_size
,
178 stream
->tracefile_count_current
,
179 stream
->uid
, stream
->gid
, NULL
);
181 ERR("utils_create_stream_file");
185 stream
->out_fd
= ret
;
186 stream
->tracefile_size_current
= 0;
188 DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64
")",
189 path
, stream
->name
, stream
->key
);
192 ret
= kernctl_buffer_flush_empty(stream
->wait_fd
);
195 * Doing a buffer flush which does not take into
196 * account empty packets. This is not perfect
197 * for stream intersection, but required as a
198 * fall-back when "flush_empty" is not
199 * implemented by lttng-modules.
201 ret
= kernctl_buffer_flush(stream
->wait_fd
);
203 ERR("Failed to flush kernel stream");
209 ret
= lttng_kconsumer_take_snapshot(stream
);
211 ERR("Taking kernel snapshot");
215 ret
= lttng_kconsumer_get_produced_snapshot(stream
, &produced_pos
);
217 ERR("Produced kernel snapshot position");
221 ret
= lttng_kconsumer_get_consumed_snapshot(stream
, &consumed_pos
);
223 ERR("Consumerd kernel snapshot position");
227 if (stream
->max_sb_size
== 0) {
228 ret
= kernctl_get_max_subbuf_size(stream
->wait_fd
,
229 &stream
->max_sb_size
);
231 ERR("Getting kernel max_sb_size");
236 consumed_pos
= consumer_get_consume_start_pos(consumed_pos
,
237 produced_pos
, nb_packets_per_stream
,
238 stream
->max_sb_size
);
240 while ((long) (consumed_pos
- produced_pos
) < 0) {
242 unsigned long len
, padded_len
;
244 health_code_update();
246 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos
);
248 ret
= kernctl_get_subbuf(stream
->wait_fd
, &consumed_pos
);
250 if (ret
!= -EAGAIN
) {
251 PERROR("kernctl_get_subbuf snapshot");
254 DBG("Kernel consumer get subbuf failed. Skipping it.");
255 consumed_pos
+= stream
->max_sb_size
;
256 stream
->chan
->lost_packets
++;
260 ret
= kernctl_get_subbuf_size(stream
->wait_fd
, &len
);
262 ERR("Snapshot kernctl_get_subbuf_size");
263 goto error_put_subbuf
;
266 ret
= kernctl_get_padded_subbuf_size(stream
->wait_fd
, &padded_len
);
268 ERR("Snapshot kernctl_get_padded_subbuf_size");
269 goto error_put_subbuf
;
272 read_len
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, len
,
273 padded_len
- len
, NULL
);
275 * We write the padded len in local tracefiles but the data len
276 * when using a relay. Display the error but continue processing
277 * to try to release the subbuffer.
279 if (relayd_id
!= (uint64_t) -1ULL) {
280 if (read_len
!= len
) {
281 ERR("Error sending to the relay (ret: %zd != len: %lu)",
285 if (read_len
!= padded_len
) {
286 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
287 read_len
, padded_len
);
291 ret
= kernctl_put_subbuf(stream
->wait_fd
);
293 ERR("Snapshot kernctl_put_subbuf");
296 consumed_pos
+= stream
->max_sb_size
;
299 if (relayd_id
== (uint64_t) -1ULL) {
300 if (stream
->out_fd
>= 0) {
301 ret
= close(stream
->out_fd
);
303 PERROR("Kernel consumer snapshot close out_fd");
309 close_relayd_stream(stream
);
310 stream
->net_seq_idx
= (uint64_t) -1ULL;
312 pthread_mutex_unlock(&stream
->lock
);
320 ret
= kernctl_put_subbuf(stream
->wait_fd
);
322 ERR("Snapshot kernctl_put_subbuf error path");
325 pthread_mutex_unlock(&stream
->lock
);
332 * Read the whole metadata available for a snapshot.
333 * RCU read-side lock must be held across this function to ensure existence of
336 * Returns 0 on success, < 0 on error
338 static int lttng_kconsumer_snapshot_metadata(struct lttng_consumer_channel
*metadata_channel
,
339 uint64_t key
, char *path
, uint64_t relayd_id
,
340 struct lttng_consumer_local_data
*ctx
)
342 int ret
, use_relayd
= 0;
344 struct lttng_consumer_stream
*metadata_stream
;
348 DBG("Kernel consumer snapshot metadata with key %" PRIu64
" at path %s",
353 metadata_stream
= metadata_channel
->metadata_stream
;
354 assert(metadata_stream
);
355 pthread_mutex_lock(&metadata_stream
->lock
);
357 /* Flag once that we have a valid relayd for the stream. */
358 if (relayd_id
!= (uint64_t) -1ULL) {
363 ret
= consumer_send_relayd_stream(metadata_stream
, path
);
368 ret
= utils_create_stream_file(path
, metadata_stream
->name
,
369 metadata_stream
->chan
->tracefile_size
,
370 metadata_stream
->tracefile_count_current
,
371 metadata_stream
->uid
, metadata_stream
->gid
, NULL
);
375 metadata_stream
->out_fd
= ret
;
379 health_code_update();
381 ret_read
= lttng_kconsumer_read_subbuffer(metadata_stream
, ctx
, NULL
);
383 if (ret_read
!= -EAGAIN
) {
384 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
389 /* ret_read is negative at this point so we will exit the loop. */
392 } while (ret_read
>= 0);
395 close_relayd_stream(metadata_stream
);
396 metadata_stream
->net_seq_idx
= (uint64_t) -1ULL;
398 if (metadata_stream
->out_fd
>= 0) {
399 ret
= close(metadata_stream
->out_fd
);
401 PERROR("Kernel consumer snapshot metadata close out_fd");
403 * Don't go on error here since the snapshot was successful at this
404 * point but somehow the close failed.
407 metadata_stream
->out_fd
= -1;
413 pthread_mutex_unlock(&metadata_stream
->lock
);
414 cds_list_del(&metadata_stream
->send_node
);
415 consumer_stream_destroy(metadata_stream
, NULL
);
416 metadata_channel
->metadata_stream
= NULL
;
422 * Receive command from session daemon and process it.
424 * Return 1 on success else a negative value or 0.
426 int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data
*ctx
,
427 int sock
, struct pollfd
*consumer_sockpoll
)
430 enum lttcomm_return_code ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
431 struct lttcomm_consumer_msg msg
;
433 health_code_update();
435 ret
= lttcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
436 if (ret
!= sizeof(msg
)) {
438 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_CMD
);
444 health_code_update();
446 /* Deprecated command */
447 assert(msg
.cmd_type
!= LTTNG_CONSUMER_STOP
);
449 health_code_update();
451 /* relayd needs RCU read-side protection */
454 switch (msg
.cmd_type
) {
455 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET
:
457 /* Session daemon status message are handled in the following call. */
458 consumer_add_relayd_socket(msg
.u
.relayd_sock
.net_index
,
459 msg
.u
.relayd_sock
.type
, ctx
, sock
, consumer_sockpoll
,
460 &msg
.u
.relayd_sock
.sock
, msg
.u
.relayd_sock
.session_id
,
461 msg
.u
.relayd_sock
.relayd_session_id
);
464 case LTTNG_CONSUMER_ADD_CHANNEL
:
466 struct lttng_consumer_channel
*new_channel
;
469 health_code_update();
471 /* First send a status message before receiving the fds. */
472 ret
= consumer_send_status_msg(sock
, ret_code
);
474 /* Somehow, the session daemon is not responding anymore. */
478 health_code_update();
480 DBG("consumer_add_channel %" PRIu64
, msg
.u
.channel
.channel_key
);
481 new_channel
= consumer_allocate_channel(msg
.u
.channel
.channel_key
,
482 msg
.u
.channel
.session_id
, msg
.u
.channel
.pathname
,
483 msg
.u
.channel
.name
, msg
.u
.channel
.uid
, msg
.u
.channel
.gid
,
484 msg
.u
.channel
.relayd_id
, msg
.u
.channel
.output
,
485 msg
.u
.channel
.tracefile_size
,
486 msg
.u
.channel
.tracefile_count
, 0,
487 msg
.u
.channel
.monitor
,
488 msg
.u
.channel
.live_timer_interval
,
490 if (new_channel
== NULL
) {
491 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
494 new_channel
->nb_init_stream_left
= msg
.u
.channel
.nb_init_streams
;
495 switch (msg
.u
.channel
.output
) {
496 case LTTNG_EVENT_SPLICE
:
497 new_channel
->output
= CONSUMER_CHANNEL_SPLICE
;
499 case LTTNG_EVENT_MMAP
:
500 new_channel
->output
= CONSUMER_CHANNEL_MMAP
;
503 ERR("Channel output unknown %d", msg
.u
.channel
.output
);
507 /* Translate and save channel type. */
508 switch (msg
.u
.channel
.type
) {
509 case CONSUMER_CHANNEL_TYPE_DATA
:
510 case CONSUMER_CHANNEL_TYPE_METADATA
:
511 new_channel
->type
= msg
.u
.channel
.type
;
518 health_code_update();
520 if (ctx
->on_recv_channel
!= NULL
) {
521 ret_recv
= ctx
->on_recv_channel(new_channel
);
523 ret
= consumer_add_channel(new_channel
, ctx
);
524 } else if (ret_recv
< 0) {
528 ret
= consumer_add_channel(new_channel
, ctx
);
530 if (msg
.u
.channel
.type
== CONSUMER_CHANNEL_TYPE_DATA
&& !ret
) {
531 int monitor_start_ret
;
533 DBG("Consumer starting monitor timer");
534 consumer_timer_live_start(new_channel
,
535 msg
.u
.channel
.live_timer_interval
);
536 monitor_start_ret
= consumer_timer_monitor_start(
538 msg
.u
.channel
.monitor_timer_interval
);
539 if (monitor_start_ret
< 0) {
540 ERR("Starting channel monitoring timer failed");
546 health_code_update();
548 /* If we received an error in add_channel, we need to report it. */
550 ret
= consumer_send_status_msg(sock
, ret
);
559 case LTTNG_CONSUMER_ADD_STREAM
:
562 struct lttng_pipe
*stream_pipe
;
563 struct lttng_consumer_stream
*new_stream
;
564 struct lttng_consumer_channel
*channel
;
568 * Get stream's channel reference. Needed when adding the stream to the
571 channel
= consumer_find_channel(msg
.u
.stream
.channel_key
);
574 * We could not find the channel. Can happen if cpu hotplug
575 * happens while tearing down.
577 ERR("Unable to find channel key %" PRIu64
, msg
.u
.stream
.channel_key
);
578 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
581 health_code_update();
583 /* First send a status message before receiving the fds. */
584 ret
= consumer_send_status_msg(sock
, ret_code
);
586 /* Somehow, the session daemon is not responding anymore. */
590 health_code_update();
592 if (ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
593 /* Channel was not found. */
599 ret
= lttng_consumer_poll_socket(consumer_sockpoll
);
605 health_code_update();
607 /* Get stream file descriptor from socket */
608 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
609 if (ret
!= sizeof(fd
)) {
610 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_FD
);
615 health_code_update();
618 * Send status code to session daemon only if the recv works. If the
619 * above recv() failed, the session daemon is notified through the
620 * error socket and the teardown is eventually done.
622 ret
= consumer_send_status_msg(sock
, ret_code
);
624 /* Somehow, the session daemon is not responding anymore. */
628 health_code_update();
630 new_stream
= consumer_allocate_stream(channel
->key
,
632 LTTNG_CONSUMER_ACTIVE_STREAM
,
642 msg
.u
.stream
.trace_archive_id
);
643 if (new_stream
== NULL
) {
648 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
654 new_stream
->chan
= channel
;
655 new_stream
->wait_fd
= fd
;
656 consumer_stream_update_channel_attributes(new_stream
,
658 switch (channel
->output
) {
659 case CONSUMER_CHANNEL_SPLICE
:
660 new_stream
->output
= LTTNG_EVENT_SPLICE
;
661 ret
= utils_create_pipe(new_stream
->splice_pipe
);
666 case CONSUMER_CHANNEL_MMAP
:
667 new_stream
->output
= LTTNG_EVENT_MMAP
;
670 ERR("Stream output unknown %d", channel
->output
);
675 * We've just assigned the channel to the stream so increment the
676 * refcount right now. We don't need to increment the refcount for
677 * streams in no monitor because we handle manually the cleanup of
678 * those. It is very important to make sure there is NO prior
679 * consumer_del_stream() calls or else the refcount will be unbalanced.
681 if (channel
->monitor
) {
682 uatomic_inc(&new_stream
->chan
->refcount
);
686 * The buffer flush is done on the session daemon side for the kernel
687 * so no need for the stream "hangup_flush_done" variable to be
688 * tracked. This is important for a kernel stream since we don't rely
689 * on the flush state of the stream to read data. It's not the case for
690 * user space tracing.
692 new_stream
->hangup_flush_done
= 0;
694 health_code_update();
696 if (ctx
->on_recv_stream
) {
697 ret
= ctx
->on_recv_stream(new_stream
);
699 consumer_stream_free(new_stream
);
704 health_code_update();
706 if (new_stream
->metadata_flag
) {
707 channel
->metadata_stream
= new_stream
;
710 /* Do not monitor this stream. */
711 if (!channel
->monitor
) {
712 DBG("Kernel consumer add stream %s in no monitor mode with "
713 "relayd id %" PRIu64
, new_stream
->name
,
714 new_stream
->net_seq_idx
);
715 cds_list_add(&new_stream
->send_node
, &channel
->streams
.head
);
719 /* Send stream to relayd if the stream has an ID. */
720 if (new_stream
->net_seq_idx
!= (uint64_t) -1ULL) {
721 ret
= consumer_send_relayd_stream(new_stream
,
722 new_stream
->chan
->pathname
);
724 consumer_stream_free(new_stream
);
729 * If adding an extra stream to an already
730 * existing channel (e.g. cpu hotplug), we need
731 * to send the "streams_sent" command to relayd.
733 if (channel
->streams_sent_to_relayd
) {
734 ret
= consumer_send_relayd_streams_sent(
735 new_stream
->net_seq_idx
);
742 /* Get the right pipe where the stream will be sent. */
743 if (new_stream
->metadata_flag
) {
744 consumer_add_metadata_stream(new_stream
);
745 stream_pipe
= ctx
->consumer_metadata_pipe
;
747 consumer_add_data_stream(new_stream
);
748 stream_pipe
= ctx
->consumer_data_pipe
;
751 /* Visible to other threads */
752 new_stream
->globally_visible
= 1;
754 health_code_update();
756 ret
= lttng_pipe_write(stream_pipe
, &new_stream
, sizeof(new_stream
));
758 ERR("Consumer write %s stream to pipe %d",
759 new_stream
->metadata_flag
? "metadata" : "data",
760 lttng_pipe_get_writefd(stream_pipe
));
761 if (new_stream
->metadata_flag
) {
762 consumer_del_stream_for_metadata(new_stream
);
764 consumer_del_stream_for_data(new_stream
);
769 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64
,
770 new_stream
->name
, fd
, new_stream
->chan
->pathname
, new_stream
->relayd_stream_id
);
773 case LTTNG_CONSUMER_STREAMS_SENT
:
775 struct lttng_consumer_channel
*channel
;
778 * Get stream's channel reference. Needed when adding the stream to the
781 channel
= consumer_find_channel(msg
.u
.sent_streams
.channel_key
);
784 * We could not find the channel. Can happen if cpu hotplug
785 * happens while tearing down.
787 ERR("Unable to find channel key %" PRIu64
,
788 msg
.u
.sent_streams
.channel_key
);
789 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
792 health_code_update();
795 * Send status code to session daemon.
797 ret
= consumer_send_status_msg(sock
, ret_code
);
798 if (ret
< 0 || ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
799 /* Somehow, the session daemon is not responding anymore. */
803 health_code_update();
806 * We should not send this message if we don't monitor the
807 * streams in this channel.
809 if (!channel
->monitor
) {
813 health_code_update();
814 /* Send stream to relayd if the stream has an ID. */
815 if (msg
.u
.sent_streams
.net_seq_idx
!= (uint64_t) -1ULL) {
816 ret
= consumer_send_relayd_streams_sent(
817 msg
.u
.sent_streams
.net_seq_idx
);
821 channel
->streams_sent_to_relayd
= true;
825 case LTTNG_CONSUMER_UPDATE_STREAM
:
830 case LTTNG_CONSUMER_DESTROY_RELAYD
:
832 uint64_t index
= msg
.u
.destroy_relayd
.net_seq_idx
;
833 struct consumer_relayd_sock_pair
*relayd
;
835 DBG("Kernel consumer destroying relayd %" PRIu64
, index
);
837 /* Get relayd reference if exists. */
838 relayd
= consumer_find_relayd(index
);
839 if (relayd
== NULL
) {
840 DBG("Unable to find relayd %" PRIu64
, index
);
841 ret_code
= LTTCOMM_CONSUMERD_RELAYD_FAIL
;
845 * Each relayd socket pair has a refcount of stream attached to it
846 * which tells if the relayd is still active or not depending on the
849 * This will set the destroy flag of the relayd object and destroy it
850 * if the refcount reaches zero when called.
852 * The destroy can happen either here or when a stream fd hangs up.
855 consumer_flag_relayd_for_destroy(relayd
);
858 health_code_update();
860 ret
= consumer_send_status_msg(sock
, ret_code
);
862 /* Somehow, the session daemon is not responding anymore. */
868 case LTTNG_CONSUMER_DATA_PENDING
:
871 uint64_t id
= msg
.u
.data_pending
.session_id
;
873 DBG("Kernel consumer data pending command for id %" PRIu64
, id
);
875 ret
= consumer_data_pending(id
);
877 health_code_update();
879 /* Send back returned value to session daemon */
880 ret
= lttcomm_send_unix_sock(sock
, &ret
, sizeof(ret
));
882 PERROR("send data pending ret code");
887 * No need to send back a status message since the data pending
888 * returned value is the response.
892 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL
:
894 struct lttng_consumer_channel
*channel
;
895 uint64_t key
= msg
.u
.snapshot_channel
.key
;
897 channel
= consumer_find_channel(key
);
899 ERR("Channel %" PRIu64
" not found", key
);
900 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
902 if (msg
.u
.snapshot_channel
.metadata
== 1) {
903 ret
= lttng_kconsumer_snapshot_metadata(channel
, key
,
904 msg
.u
.snapshot_channel
.pathname
,
905 msg
.u
.snapshot_channel
.relayd_id
, ctx
);
907 ERR("Snapshot metadata failed");
908 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
911 ret
= lttng_kconsumer_snapshot_channel(channel
, key
,
912 msg
.u
.snapshot_channel
.pathname
,
913 msg
.u
.snapshot_channel
.relayd_id
,
914 msg
.u
.snapshot_channel
.nb_packets_per_stream
,
917 ERR("Snapshot channel failed");
918 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
922 health_code_update();
924 ret
= consumer_send_status_msg(sock
, ret_code
);
926 /* Somehow, the session daemon is not responding anymore. */
931 case LTTNG_CONSUMER_DESTROY_CHANNEL
:
933 uint64_t key
= msg
.u
.destroy_channel
.key
;
934 struct lttng_consumer_channel
*channel
;
936 channel
= consumer_find_channel(key
);
938 ERR("Kernel consumer destroy channel %" PRIu64
" not found", key
);
939 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
942 health_code_update();
944 ret
= consumer_send_status_msg(sock
, ret_code
);
946 /* Somehow, the session daemon is not responding anymore. */
950 health_code_update();
952 /* Stop right now if no channel was found. */
958 * This command should ONLY be issued for channel with streams set in
961 assert(!channel
->monitor
);
964 * The refcount should ALWAYS be 0 in the case of a channel in no
967 assert(!uatomic_sub_return(&channel
->refcount
, 1));
969 consumer_del_channel(channel
);
973 case LTTNG_CONSUMER_DISCARDED_EVENTS
:
977 struct lttng_consumer_channel
*channel
;
978 uint64_t id
= msg
.u
.discarded_events
.session_id
;
979 uint64_t key
= msg
.u
.discarded_events
.channel_key
;
981 DBG("Kernel consumer discarded events command for session id %"
982 PRIu64
", channel key %" PRIu64
, id
, key
);
984 channel
= consumer_find_channel(key
);
986 ERR("Kernel consumer discarded events channel %"
987 PRIu64
" not found", key
);
990 count
= channel
->discarded_events
;
993 health_code_update();
995 /* Send back returned value to session daemon */
996 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
998 PERROR("send discarded events");
1004 case LTTNG_CONSUMER_LOST_PACKETS
:
1008 struct lttng_consumer_channel
*channel
;
1009 uint64_t id
= msg
.u
.lost_packets
.session_id
;
1010 uint64_t key
= msg
.u
.lost_packets
.channel_key
;
1012 DBG("Kernel consumer lost packets command for session id %"
1013 PRIu64
", channel key %" PRIu64
, id
, key
);
1015 channel
= consumer_find_channel(key
);
1017 ERR("Kernel consumer lost packets channel %"
1018 PRIu64
" not found", key
);
1021 count
= channel
->lost_packets
;
1024 health_code_update();
1026 /* Send back returned value to session daemon */
1027 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1029 PERROR("send lost packets");
1035 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1037 int channel_monitor_pipe
;
1039 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1040 /* Successfully received the command's type. */
1041 ret
= consumer_send_status_msg(sock
, ret_code
);
1046 ret
= lttcomm_recv_fds_unix_sock(sock
, &channel_monitor_pipe
,
1048 if (ret
!= sizeof(channel_monitor_pipe
)) {
1049 ERR("Failed to receive channel monitor pipe");
1053 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe
);
1054 ret
= consumer_timer_thread_set_channel_monitor_pipe(
1055 channel_monitor_pipe
);
1059 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1060 /* Set the pipe as non-blocking. */
1061 ret
= fcntl(channel_monitor_pipe
, F_GETFL
, 0);
1063 PERROR("fcntl get flags of the channel monitoring pipe");
1068 ret
= fcntl(channel_monitor_pipe
, F_SETFL
,
1069 flags
| O_NONBLOCK
);
1071 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1074 DBG("Channel monitor pipe set as non-blocking");
1076 ret_code
= LTTCOMM_CONSUMERD_ALREADY_SET
;
1078 ret
= consumer_send_status_msg(sock
, ret_code
);
1084 case LTTNG_CONSUMER_ROTATE_CHANNEL
:
1086 struct lttng_consumer_channel
*channel
;
1087 uint64_t key
= msg
.u
.rotate_channel
.key
;
1089 DBG("Consumer rotate channel %" PRIu64
, key
);
1091 channel
= consumer_find_channel(key
);
1093 ERR("Channel %" PRIu64
" not found", key
);
1094 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1097 * Sample the rotate position of all the streams in this channel.
1099 ret
= lttng_consumer_rotate_channel(channel
, key
,
1100 msg
.u
.rotate_channel
.pathname
,
1101 msg
.u
.rotate_channel
.relayd_id
,
1102 msg
.u
.rotate_channel
.metadata
,
1103 msg
.u
.rotate_channel
.new_chunk_id
,
1106 ERR("Rotate channel failed");
1107 ret_code
= LTTCOMM_CONSUMERD_ROTATION_FAIL
;
1110 health_code_update();
1112 ret
= consumer_send_status_msg(sock
, ret_code
);
1114 /* Somehow, the session daemon is not responding anymore. */
1118 /* Rotate the streams that are ready right now. */
1119 ret
= lttng_consumer_rotate_ready_streams(
1122 ERR("Rotate ready streams failed");
1128 case LTTNG_CONSUMER_ROTATE_RENAME
:
1130 DBG("Consumer rename session %" PRIu64
" after rotation, old path = \"%s\", new path = \"%s\"",
1131 msg
.u
.rotate_rename
.session_id
,
1132 msg
.u
.rotate_rename
.old_path
,
1133 msg
.u
.rotate_rename
.new_path
);
1134 ret
= lttng_consumer_rotate_rename(msg
.u
.rotate_rename
.old_path
,
1135 msg
.u
.rotate_rename
.new_path
,
1136 msg
.u
.rotate_rename
.uid
,
1137 msg
.u
.rotate_rename
.gid
,
1138 msg
.u
.rotate_rename
.relayd_id
);
1140 ERR("Rotate rename failed");
1141 ret_code
= LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED
;
1144 health_code_update();
1146 ret
= consumer_send_status_msg(sock
, ret_code
);
1148 /* Somehow, the session daemon is not responding anymore. */
1153 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
:
1156 uint32_t pending_reply
;
1158 DBG("Perform local check of pending rotation for session id %" PRIu64
,
1159 msg
.u
.check_rotation_pending_local
.session_id
);
1160 pending
= lttng_consumer_check_rotation_pending_local(
1161 msg
.u
.check_rotation_pending_local
.session_id
,
1162 msg
.u
.check_rotation_pending_local
.chunk_id
);
1164 ERR("Local rotation pending check failed with code %i", pending
);
1165 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED
;
1167 pending_reply
= !!pending
;
1170 health_code_update();
1172 ret
= consumer_send_status_msg(sock
, ret_code
);
1174 /* Somehow, the session daemon is not responding anymore. */
1180 * An error occurred while running the command;
1181 * don't send the 'pending' flag as the sessiond
1187 /* Send back returned value to session daemon */
1188 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1189 sizeof(pending_reply
));
1191 PERROR("Failed to send rotation pending return code");
1196 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
:
1199 uint32_t pending_reply
;
1201 DBG("Perform relayd check of pending rotation for session id %" PRIu64
,
1202 msg
.u
.check_rotation_pending_relay
.session_id
);
1203 pending
= lttng_consumer_check_rotation_pending_relay(
1204 msg
.u
.check_rotation_pending_relay
.session_id
,
1205 msg
.u
.check_rotation_pending_relay
.relayd_id
,
1206 msg
.u
.check_rotation_pending_relay
.chunk_id
);
1208 ERR("Relayd rotation pending check failed with code %i", pending
);
1209 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED
;
1211 pending_reply
= !!pending
;
1214 health_code_update();
1216 ret
= consumer_send_status_msg(sock
, ret_code
);
1218 /* Somehow, the session daemon is not responding anymore. */
1224 * An error occurred while running the command;
1225 * don't send the 'pending' flag as the sessiond
1231 /* Send back returned value to session daemon */
1232 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1233 sizeof(pending_reply
));
1235 PERROR("Failed to send rotation pending return code");
1240 case LTTNG_CONSUMER_MKDIR
:
1242 DBG("Consumer mkdir %s in session %" PRIu64
,
1244 msg
.u
.mkdir
.session_id
);
1245 ret
= lttng_consumer_mkdir(msg
.u
.mkdir
.path
,
1248 msg
.u
.mkdir
.relayd_id
);
1250 ERR("consumer mkdir failed");
1251 ret_code
= LTTCOMM_CONSUMERD_MKDIR_FAILED
;
1254 health_code_update();
1256 ret
= consumer_send_status_msg(sock
, ret_code
);
1258 /* Somehow, the session daemon is not responding anymore. */
1271 * Return 1 to indicate success since the 0 value can be a socket
1272 * shutdown during the recv() or send() call.
1274 health_code_update();
1279 /* This will issue a consumer stop. */
1284 * Populate index values of a kernel stream. Values are set in big endian order.
1286 * Return 0 on success or else a negative value.
1288 static int get_index_values(struct ctf_packet_index
*index
, int infd
)
1292 ret
= kernctl_get_timestamp_begin(infd
, &index
->timestamp_begin
);
1294 PERROR("kernctl_get_timestamp_begin");
1297 index
->timestamp_begin
= htobe64(index
->timestamp_begin
);
1299 ret
= kernctl_get_timestamp_end(infd
, &index
->timestamp_end
);
1301 PERROR("kernctl_get_timestamp_end");
1304 index
->timestamp_end
= htobe64(index
->timestamp_end
);
1306 ret
= kernctl_get_events_discarded(infd
, &index
->events_discarded
);
1308 PERROR("kernctl_get_events_discarded");
1311 index
->events_discarded
= htobe64(index
->events_discarded
);
1313 ret
= kernctl_get_content_size(infd
, &index
->content_size
);
1315 PERROR("kernctl_get_content_size");
1318 index
->content_size
= htobe64(index
->content_size
);
1320 ret
= kernctl_get_packet_size(infd
, &index
->packet_size
);
1322 PERROR("kernctl_get_packet_size");
1325 index
->packet_size
= htobe64(index
->packet_size
);
1327 ret
= kernctl_get_stream_id(infd
, &index
->stream_id
);
1329 PERROR("kernctl_get_stream_id");
1332 index
->stream_id
= htobe64(index
->stream_id
);
1334 ret
= kernctl_get_instance_id(infd
, &index
->stream_instance_id
);
1336 if (ret
== -ENOTTY
) {
1337 /* Command not implemented by lttng-modules. */
1338 index
->stream_instance_id
= -1ULL;
1340 PERROR("kernctl_get_instance_id");
1344 index
->stream_instance_id
= htobe64(index
->stream_instance_id
);
1346 ret
= kernctl_get_sequence_number(infd
, &index
->packet_seq_num
);
1348 if (ret
== -ENOTTY
) {
1349 /* Command not implemented by lttng-modules. */
1350 index
->packet_seq_num
= -1ULL;
1353 PERROR("kernctl_get_sequence_number");
1357 index
->packet_seq_num
= htobe64(index
->packet_seq_num
);
1363 * Sync metadata meaning request them to the session daemon and snapshot to the
1364 * metadata thread can consumer them.
1366 * Metadata stream lock MUST be acquired.
1368 * Return 0 if new metadatda is available, EAGAIN if the metadata stream
1369 * is empty or a negative value on error.
1371 int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream
*metadata
)
1377 ret
= kernctl_buffer_flush(metadata
->wait_fd
);
1379 ERR("Failed to flush kernel stream");
1383 ret
= kernctl_snapshot(metadata
->wait_fd
);
1385 if (ret
!= -EAGAIN
) {
1386 ERR("Sync metadata, taking kernel snapshot failed.");
1389 DBG("Sync metadata, no new kernel metadata");
1390 /* No new metadata, exit. */
1400 int update_stream_stats(struct lttng_consumer_stream
*stream
)
1403 uint64_t seq
, discarded
;
1405 ret
= kernctl_get_sequence_number(stream
->wait_fd
, &seq
);
1407 if (ret
== -ENOTTY
) {
1408 /* Command not implemented by lttng-modules. */
1411 PERROR("kernctl_get_sequence_number");
1417 * Start the sequence when we extract the first packet in case we don't
1418 * start at 0 (for example if a consumer is not connected to the
1419 * session immediately after the beginning).
1421 if (stream
->last_sequence_number
== -1ULL) {
1422 stream
->last_sequence_number
= seq
;
1423 } else if (seq
> stream
->last_sequence_number
) {
1424 stream
->chan
->lost_packets
+= seq
-
1425 stream
->last_sequence_number
- 1;
1427 /* seq <= last_sequence_number */
1428 ERR("Sequence number inconsistent : prev = %" PRIu64
1429 ", current = %" PRIu64
,
1430 stream
->last_sequence_number
, seq
);
1434 stream
->last_sequence_number
= seq
;
1436 ret
= kernctl_get_events_discarded(stream
->wait_fd
, &discarded
);
1438 PERROR("kernctl_get_events_discarded");
1441 if (discarded
< stream
->last_discarded_events
) {
1443 * Overflow has occurred. We assume only one wrap-around
1446 stream
->chan
->discarded_events
+= (1ULL << (CAA_BITS_PER_LONG
- 1)) -
1447 stream
->last_discarded_events
+ discarded
;
1449 stream
->chan
->discarded_events
+= discarded
-
1450 stream
->last_discarded_events
;
1452 stream
->last_discarded_events
= discarded
;
1460 * Check if the local version of the metadata stream matches with the version
1461 * of the metadata stream in the kernel. If it was updated, set the reset flag
1465 int metadata_stream_check_version(int infd
, struct lttng_consumer_stream
*stream
)
1468 uint64_t cur_version
;
1470 ret
= kernctl_get_metadata_version(infd
, &cur_version
);
1472 if (ret
== -ENOTTY
) {
1474 * LTTng-modules does not implement this
1480 ERR("Failed to get the metadata version");
1484 if (stream
->metadata_version
== cur_version
) {
1489 DBG("New metadata version detected");
1490 stream
->metadata_version
= cur_version
;
1491 stream
->reset_metadata_flag
= 1;
1499 * Consume data on a file descriptor and write it on a trace file.
1501 ssize_t
lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream
*stream
,
1502 struct lttng_consumer_local_data
*ctx
, bool *rotated
)
1504 unsigned long len
, subbuf_size
, padding
;
1505 int err
, write_index
= 1, rotation_ret
;
1507 int infd
= stream
->wait_fd
;
1508 struct ctf_packet_index index
;
1510 DBG("In read_subbuffer (infd : %d)", infd
);
1513 * If the stream was flagged to be ready for rotation before we extract the
1514 * next packet, rotate it now.
1516 if (stream
->rotate_ready
) {
1517 DBG("Rotate stream before extracting data");
1518 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1519 if (rotation_ret
< 0) {
1520 ERR("Stream rotation error");
1526 /* Get the next subbuffer */
1527 err
= kernctl_get_next_subbuf(infd
);
1530 * This is a debug message even for single-threaded consumer,
1531 * because poll() have more relaxed criterions than get subbuf,
1532 * so get_subbuf may fail for short race windows where poll()
1533 * would issue wakeups.
1535 DBG("Reserving sub buffer failed (everything is normal, "
1536 "it is due to concurrency)");
1541 /* Get the full subbuffer size including padding */
1542 err
= kernctl_get_padded_subbuf_size(infd
, &len
);
1544 PERROR("Getting sub-buffer len failed.");
1545 err
= kernctl_put_subbuf(infd
);
1547 if (err
== -EFAULT
) {
1548 PERROR("Error in unreserving sub buffer\n");
1549 } else if (err
== -EIO
) {
1550 /* Should never happen with newer LTTng versions */
1551 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1560 if (!stream
->metadata_flag
) {
1561 ret
= get_index_values(&index
, infd
);
1563 err
= kernctl_put_subbuf(infd
);
1565 if (err
== -EFAULT
) {
1566 PERROR("Error in unreserving sub buffer\n");
1567 } else if (err
== -EIO
) {
1568 /* Should never happen with newer LTTng versions */
1569 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1576 ret
= update_stream_stats(stream
);
1578 err
= kernctl_put_subbuf(infd
);
1580 if (err
== -EFAULT
) {
1581 PERROR("Error in unreserving sub buffer\n");
1582 } else if (err
== -EIO
) {
1583 /* Should never happen with newer LTTng versions */
1584 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1593 ret
= metadata_stream_check_version(infd
, stream
);
1595 err
= kernctl_put_subbuf(infd
);
1597 if (err
== -EFAULT
) {
1598 PERROR("Error in unreserving sub buffer\n");
1599 } else if (err
== -EIO
) {
1600 /* Should never happen with newer LTTng versions */
1601 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1610 switch (stream
->chan
->output
) {
1611 case CONSUMER_CHANNEL_SPLICE
:
1613 * XXX: The lttng-modules splice "actor" does not handle copying
1614 * partial pages hence only using the subbuffer size without the
1615 * padding makes the splice fail.
1620 /* splice the subbuffer to the tracefile */
1621 ret
= lttng_consumer_on_read_subbuffer_splice(ctx
, stream
, subbuf_size
,
1624 * XXX: Splice does not support network streaming so the return value
1625 * is simply checked against subbuf_size and not like the mmap() op.
1627 if (ret
!= subbuf_size
) {
1629 * display the error but continue processing to try
1630 * to release the subbuffer
1632 ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
1637 case CONSUMER_CHANNEL_MMAP
:
1638 /* Get subbuffer size without padding */
1639 err
= kernctl_get_subbuf_size(infd
, &subbuf_size
);
1641 PERROR("Getting sub-buffer len failed.");
1642 err
= kernctl_put_subbuf(infd
);
1644 if (err
== -EFAULT
) {
1645 PERROR("Error in unreserving sub buffer\n");
1646 } else if (err
== -EIO
) {
1647 /* Should never happen with newer LTTng versions */
1648 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1657 /* Make sure the tracer is not gone mad on us! */
1658 assert(len
>= subbuf_size
);
1660 padding
= len
- subbuf_size
;
1662 /* write the subbuffer to the tracefile */
1663 ret
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, subbuf_size
,
1666 * The mmap operation should write subbuf_size amount of data when
1667 * network streaming or the full padding (len) size when we are _not_
1670 if ((ret
!= subbuf_size
&& stream
->net_seq_idx
!= (uint64_t) -1ULL) ||
1671 (ret
!= len
&& stream
->net_seq_idx
== (uint64_t) -1ULL)) {
1673 * Display the error but continue processing to try to release the
1674 * subbuffer. This is a DBG statement since this is possible to
1675 * happen without being a critical error.
1677 DBG("Error writing to tracefile "
1678 "(ret: %zd != len: %lu != subbuf_size: %lu)",
1679 ret
, len
, subbuf_size
);
1684 ERR("Unknown output method");
1688 err
= kernctl_put_next_subbuf(infd
);
1690 if (err
== -EFAULT
) {
1691 PERROR("Error in unreserving sub buffer\n");
1692 } else if (err
== -EIO
) {
1693 /* Should never happen with newer LTTng versions */
1694 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1700 /* Write index if needed. */
1705 if (stream
->chan
->live_timer_interval
&& !stream
->metadata_flag
) {
1707 * In live, block until all the metadata is sent.
1709 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1710 assert(!stream
->missed_metadata_flush
);
1711 stream
->waiting_on_metadata
= true;
1712 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1714 err
= consumer_stream_sync_metadata(ctx
, stream
->session_id
);
1716 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1717 stream
->waiting_on_metadata
= false;
1718 if (stream
->missed_metadata_flush
) {
1719 stream
->missed_metadata_flush
= false;
1720 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1721 (void) consumer_flush_kernel_index(stream
);
1723 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1730 err
= consumer_stream_write_index(stream
, &index
);
1737 * After extracting the packet, we check if the stream is now ready to be
1738 * rotated and perform the action immediately.
1740 rotation_ret
= lttng_consumer_stream_is_rotate_ready(stream
);
1741 if (rotation_ret
== 1) {
1742 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1743 if (rotation_ret
< 0) {
1744 ERR("Stream rotation error");
1748 } else if (rotation_ret
< 0) {
1749 ERR("Checking if stream is ready to rotate");
1758 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream
*stream
)
1765 * Don't create anything if this is set for streaming or should not be
1768 if (stream
->net_seq_idx
== (uint64_t) -1ULL && stream
->chan
->monitor
) {
1769 ret
= utils_create_stream_file(stream
->chan
->pathname
, stream
->name
,
1770 stream
->chan
->tracefile_size
, stream
->tracefile_count_current
,
1771 stream
->uid
, stream
->gid
, NULL
);
1775 stream
->out_fd
= ret
;
1776 stream
->tracefile_size_current
= 0;
1778 if (!stream
->metadata_flag
) {
1779 struct lttng_index_file
*index_file
;
1781 index_file
= lttng_index_file_create(stream
->chan
->pathname
,
1782 stream
->name
, stream
->uid
, stream
->gid
,
1783 stream
->chan
->tracefile_size
,
1784 stream
->tracefile_count_current
,
1785 CTF_INDEX_MAJOR
, CTF_INDEX_MINOR
);
1789 assert(!stream
->index_file
);
1790 stream
->index_file
= index_file
;
1794 if (stream
->output
== LTTNG_EVENT_MMAP
) {
1795 /* get the len of the mmap region */
1796 unsigned long mmap_len
;
1798 ret
= kernctl_get_mmap_len(stream
->wait_fd
, &mmap_len
);
1800 PERROR("kernctl_get_mmap_len");
1801 goto error_close_fd
;
1803 stream
->mmap_len
= (size_t) mmap_len
;
1805 stream
->mmap_base
= mmap(NULL
, stream
->mmap_len
, PROT_READ
,
1806 MAP_PRIVATE
, stream
->wait_fd
, 0);
1807 if (stream
->mmap_base
== MAP_FAILED
) {
1808 PERROR("Error mmaping");
1810 goto error_close_fd
;
1814 /* we return 0 to let the library handle the FD internally */
1818 if (stream
->out_fd
>= 0) {
1821 err
= close(stream
->out_fd
);
1823 stream
->out_fd
= -1;
1830 * Check if data is still being extracted from the buffers for a specific
1831 * stream. Consumer data lock MUST be acquired before calling this function
1832 * and the stream lock.
1834 * Return 1 if the traced data are still getting read else 0 meaning that the
1835 * data is available for trace viewer reading.
1837 int lttng_kconsumer_data_pending(struct lttng_consumer_stream
*stream
)
1843 if (stream
->endpoint_status
!= CONSUMER_ENDPOINT_ACTIVE
) {
1848 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1850 /* There is still data so let's put back this subbuffer. */
1851 ret
= kernctl_put_subbuf(stream
->wait_fd
);
1853 ret
= 1; /* Data is pending */
1857 /* Data is NOT pending and ready to be read. */