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 %d", channel
->output
);
152 cds_list_for_each_entry(stream
, &channel
->streams
.head
, send_node
) {
153 unsigned long consumed_pos
, produced_pos
;
155 health_code_update();
158 * Lock stream because we are about to change its state.
160 pthread_mutex_lock(&stream
->lock
);
163 * Assign the received relayd ID so we can use it for streaming. The streams
164 * are not visible to anyone so this is OK to change it.
166 stream
->net_seq_idx
= relayd_id
;
167 channel
->relayd_id
= relayd_id
;
168 if (relayd_id
!= (uint64_t) -1ULL) {
169 ret
= consumer_send_relayd_stream(stream
, path
);
171 ERR("sending stream to relayd");
175 ret
= utils_create_stream_file(path
, stream
->name
,
176 stream
->chan
->tracefile_size
,
177 stream
->tracefile_count_current
,
178 stream
->uid
, stream
->gid
, NULL
);
180 ERR("utils_create_stream_file");
184 stream
->out_fd
= ret
;
185 stream
->tracefile_size_current
= 0;
187 DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64
")",
188 path
, stream
->name
, stream
->key
);
191 ret
= kernctl_buffer_flush_empty(stream
->wait_fd
);
194 * Doing a buffer flush which does not take into
195 * account empty packets. This is not perfect
196 * for stream intersection, but required as a
197 * fall-back when "flush_empty" is not
198 * implemented by lttng-modules.
200 ret
= kernctl_buffer_flush(stream
->wait_fd
);
202 ERR("Failed to flush kernel stream");
208 ret
= lttng_kconsumer_take_snapshot(stream
);
210 ERR("Taking kernel snapshot");
214 ret
= lttng_kconsumer_get_produced_snapshot(stream
, &produced_pos
);
216 ERR("Produced kernel snapshot position");
220 ret
= lttng_kconsumer_get_consumed_snapshot(stream
, &consumed_pos
);
222 ERR("Consumerd kernel snapshot position");
226 if (stream
->max_sb_size
== 0) {
227 ret
= kernctl_get_max_subbuf_size(stream
->wait_fd
,
228 &stream
->max_sb_size
);
230 ERR("Getting kernel max_sb_size");
235 consumed_pos
= consumer_get_consume_start_pos(consumed_pos
,
236 produced_pos
, nb_packets_per_stream
,
237 stream
->max_sb_size
);
239 while (consumed_pos
< produced_pos
) {
241 unsigned long len
, padded_len
;
243 health_code_update();
245 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos
);
247 ret
= kernctl_get_subbuf(stream
->wait_fd
, &consumed_pos
);
249 if (ret
!= -EAGAIN
) {
250 PERROR("kernctl_get_subbuf snapshot");
253 DBG("Kernel consumer get subbuf failed. Skipping it.");
254 consumed_pos
+= stream
->max_sb_size
;
255 stream
->chan
->lost_packets
++;
259 ret
= kernctl_get_subbuf_size(stream
->wait_fd
, &len
);
261 ERR("Snapshot kernctl_get_subbuf_size");
262 goto error_put_subbuf
;
265 ret
= kernctl_get_padded_subbuf_size(stream
->wait_fd
, &padded_len
);
267 ERR("Snapshot kernctl_get_padded_subbuf_size");
268 goto error_put_subbuf
;
271 read_len
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, len
,
272 padded_len
- len
, NULL
);
274 * We write the padded len in local tracefiles but the data len
275 * when using a relay. Display the error but continue processing
276 * to try to release the subbuffer.
278 if (relayd_id
!= (uint64_t) -1ULL) {
279 if (read_len
!= len
) {
280 ERR("Error sending to the relay (ret: %zd != len: %lu)",
284 if (read_len
!= padded_len
) {
285 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
286 read_len
, padded_len
);
290 ret
= kernctl_put_subbuf(stream
->wait_fd
);
292 ERR("Snapshot kernctl_put_subbuf");
295 consumed_pos
+= stream
->max_sb_size
;
298 if (relayd_id
== (uint64_t) -1ULL) {
299 if (stream
->out_fd
>= 0) {
300 ret
= close(stream
->out_fd
);
302 PERROR("Kernel consumer snapshot close out_fd");
308 close_relayd_stream(stream
);
309 stream
->net_seq_idx
= (uint64_t) -1ULL;
311 pthread_mutex_unlock(&stream
->lock
);
319 ret
= kernctl_put_subbuf(stream
->wait_fd
);
321 ERR("Snapshot kernctl_put_subbuf error path");
324 pthread_mutex_unlock(&stream
->lock
);
331 * Read the whole metadata available for a snapshot.
332 * RCU read-side lock must be held across this function to ensure existence of
335 * Returns 0 on success, < 0 on error
337 static int lttng_kconsumer_snapshot_metadata(struct lttng_consumer_channel
*metadata_channel
,
338 uint64_t key
, char *path
, uint64_t relayd_id
,
339 struct lttng_consumer_local_data
*ctx
)
341 int ret
, use_relayd
= 0;
343 struct lttng_consumer_stream
*metadata_stream
;
347 DBG("Kernel consumer snapshot metadata with key %" PRIu64
" at path %s",
352 metadata_stream
= metadata_channel
->metadata_stream
;
353 assert(metadata_stream
);
354 pthread_mutex_lock(&metadata_stream
->lock
);
356 /* Flag once that we have a valid relayd for the stream. */
357 if (relayd_id
!= (uint64_t) -1ULL) {
362 ret
= consumer_send_relayd_stream(metadata_stream
, path
);
367 ret
= utils_create_stream_file(path
, metadata_stream
->name
,
368 metadata_stream
->chan
->tracefile_size
,
369 metadata_stream
->tracefile_count_current
,
370 metadata_stream
->uid
, metadata_stream
->gid
, NULL
);
374 metadata_stream
->out_fd
= ret
;
378 health_code_update();
380 ret_read
= lttng_kconsumer_read_subbuffer(metadata_stream
, ctx
, NULL
);
382 if (ret_read
!= -EAGAIN
) {
383 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
388 /* ret_read is negative at this point so we will exit the loop. */
391 } while (ret_read
>= 0);
394 close_relayd_stream(metadata_stream
);
395 metadata_stream
->net_seq_idx
= (uint64_t) -1ULL;
397 if (metadata_stream
->out_fd
>= 0) {
398 ret
= close(metadata_stream
->out_fd
);
400 PERROR("Kernel consumer snapshot metadata close out_fd");
402 * Don't go on error here since the snapshot was successful at this
403 * point but somehow the close failed.
406 metadata_stream
->out_fd
= -1;
412 pthread_mutex_unlock(&metadata_stream
->lock
);
413 cds_list_del(&metadata_stream
->send_node
);
414 consumer_stream_destroy(metadata_stream
, NULL
);
415 metadata_channel
->metadata_stream
= NULL
;
421 * Receive command from session daemon and process it.
423 * Return 1 on success else a negative value or 0.
425 int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data
*ctx
,
426 int sock
, struct pollfd
*consumer_sockpoll
)
429 enum lttcomm_return_code ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
430 struct lttcomm_consumer_msg msg
;
432 health_code_update();
434 ret
= lttcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
435 if (ret
!= sizeof(msg
)) {
437 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_CMD
);
443 health_code_update();
445 /* Deprecated command */
446 assert(msg
.cmd_type
!= LTTNG_CONSUMER_STOP
);
448 health_code_update();
450 /* relayd needs RCU read-side protection */
453 switch (msg
.cmd_type
) {
454 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET
:
456 /* Session daemon status message are handled in the following call. */
457 consumer_add_relayd_socket(msg
.u
.relayd_sock
.net_index
,
458 msg
.u
.relayd_sock
.type
, ctx
, sock
, consumer_sockpoll
,
459 &msg
.u
.relayd_sock
.sock
, msg
.u
.relayd_sock
.session_id
,
460 msg
.u
.relayd_sock
.relayd_session_id
);
463 case LTTNG_CONSUMER_ADD_CHANNEL
:
465 struct lttng_consumer_channel
*new_channel
;
468 health_code_update();
470 /* First send a status message before receiving the fds. */
471 ret
= consumer_send_status_msg(sock
, ret_code
);
473 /* Somehow, the session daemon is not responding anymore. */
477 health_code_update();
479 DBG("consumer_add_channel %" PRIu64
, msg
.u
.channel
.channel_key
);
480 new_channel
= consumer_allocate_channel(msg
.u
.channel
.channel_key
,
481 msg
.u
.channel
.session_id
, msg
.u
.channel
.pathname
,
482 msg
.u
.channel
.name
, msg
.u
.channel
.uid
, msg
.u
.channel
.gid
,
483 msg
.u
.channel
.relayd_id
, msg
.u
.channel
.output
,
484 msg
.u
.channel
.tracefile_size
,
485 msg
.u
.channel
.tracefile_count
, 0,
486 msg
.u
.channel
.monitor
,
487 msg
.u
.channel
.live_timer_interval
,
489 if (new_channel
== NULL
) {
490 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
493 new_channel
->nb_init_stream_left
= msg
.u
.channel
.nb_init_streams
;
494 switch (msg
.u
.channel
.output
) {
495 case LTTNG_EVENT_SPLICE
:
496 new_channel
->output
= CONSUMER_CHANNEL_SPLICE
;
498 case LTTNG_EVENT_MMAP
:
499 new_channel
->output
= CONSUMER_CHANNEL_MMAP
;
502 ERR("Channel output unknown %d", msg
.u
.channel
.output
);
506 /* Translate and save channel type. */
507 switch (msg
.u
.channel
.type
) {
508 case CONSUMER_CHANNEL_TYPE_DATA
:
509 case CONSUMER_CHANNEL_TYPE_METADATA
:
510 new_channel
->type
= msg
.u
.channel
.type
;
517 health_code_update();
519 if (ctx
->on_recv_channel
!= NULL
) {
520 ret_recv
= ctx
->on_recv_channel(new_channel
);
522 ret
= consumer_add_channel(new_channel
, ctx
);
523 } else if (ret_recv
< 0) {
527 ret
= consumer_add_channel(new_channel
, ctx
);
529 if (msg
.u
.channel
.type
== CONSUMER_CHANNEL_TYPE_DATA
&& !ret
) {
530 int monitor_start_ret
;
532 DBG("Consumer starting monitor timer");
533 consumer_timer_live_start(new_channel
,
534 msg
.u
.channel
.live_timer_interval
);
535 monitor_start_ret
= consumer_timer_monitor_start(
537 msg
.u
.channel
.monitor_timer_interval
);
538 if (monitor_start_ret
< 0) {
539 ERR("Starting channel monitoring timer failed");
545 health_code_update();
547 /* If we received an error in add_channel, we need to report it. */
549 ret
= consumer_send_status_msg(sock
, ret
);
558 case LTTNG_CONSUMER_ADD_STREAM
:
561 struct lttng_pipe
*stream_pipe
;
562 struct lttng_consumer_stream
*new_stream
;
563 struct lttng_consumer_channel
*channel
;
567 * Get stream's channel reference. Needed when adding the stream to the
570 channel
= consumer_find_channel(msg
.u
.stream
.channel_key
);
573 * We could not find the channel. Can happen if cpu hotplug
574 * happens while tearing down.
576 ERR("Unable to find channel key %" PRIu64
, msg
.u
.stream
.channel_key
);
577 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
580 health_code_update();
582 /* First send a status message before receiving the fds. */
583 ret
= consumer_send_status_msg(sock
, ret_code
);
585 /* Somehow, the session daemon is not responding anymore. */
589 health_code_update();
591 if (ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
592 /* Channel was not found. */
598 ret
= lttng_consumer_poll_socket(consumer_sockpoll
);
604 health_code_update();
606 /* Get stream file descriptor from socket */
607 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
608 if (ret
!= sizeof(fd
)) {
609 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_FD
);
614 health_code_update();
617 * Send status code to session daemon only if the recv works. If the
618 * above recv() failed, the session daemon is notified through the
619 * error socket and the teardown is eventually done.
621 ret
= consumer_send_status_msg(sock
, ret_code
);
623 /* Somehow, the session daemon is not responding anymore. */
627 health_code_update();
629 new_stream
= consumer_allocate_stream(channel
->key
,
631 LTTNG_CONSUMER_ACTIVE_STREAM
,
641 msg
.u
.stream
.trace_archive_id
);
642 if (new_stream
== NULL
) {
647 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
653 new_stream
->chan
= channel
;
654 new_stream
->wait_fd
= fd
;
655 consumer_stream_update_channel_attributes(new_stream
,
657 switch (channel
->output
) {
658 case CONSUMER_CHANNEL_SPLICE
:
659 new_stream
->output
= LTTNG_EVENT_SPLICE
;
660 ret
= utils_create_pipe(new_stream
->splice_pipe
);
665 case CONSUMER_CHANNEL_MMAP
:
666 new_stream
->output
= LTTNG_EVENT_MMAP
;
669 ERR("Stream output unknown %d", channel
->output
);
674 * We've just assigned the channel to the stream so increment the
675 * refcount right now. We don't need to increment the refcount for
676 * streams in no monitor because we handle manually the cleanup of
677 * those. It is very important to make sure there is NO prior
678 * consumer_del_stream() calls or else the refcount will be unbalanced.
680 if (channel
->monitor
) {
681 uatomic_inc(&new_stream
->chan
->refcount
);
685 * The buffer flush is done on the session daemon side for the kernel
686 * so no need for the stream "hangup_flush_done" variable to be
687 * tracked. This is important for a kernel stream since we don't rely
688 * on the flush state of the stream to read data. It's not the case for
689 * user space tracing.
691 new_stream
->hangup_flush_done
= 0;
693 health_code_update();
695 if (ctx
->on_recv_stream
) {
696 ret
= ctx
->on_recv_stream(new_stream
);
698 consumer_stream_free(new_stream
);
703 health_code_update();
705 if (new_stream
->metadata_flag
) {
706 channel
->metadata_stream
= new_stream
;
709 /* Do not monitor this stream. */
710 if (!channel
->monitor
) {
711 DBG("Kernel consumer add stream %s in no monitor mode with "
712 "relayd id %" PRIu64
, new_stream
->name
,
713 new_stream
->net_seq_idx
);
714 cds_list_add(&new_stream
->send_node
, &channel
->streams
.head
);
718 /* Send stream to relayd if the stream has an ID. */
719 if (new_stream
->net_seq_idx
!= (uint64_t) -1ULL) {
720 ret
= consumer_send_relayd_stream(new_stream
,
721 new_stream
->chan
->pathname
);
723 consumer_stream_free(new_stream
);
728 * If adding an extra stream to an already
729 * existing channel (e.g. cpu hotplug), we need
730 * to send the "streams_sent" command to relayd.
732 if (channel
->streams_sent_to_relayd
) {
733 ret
= consumer_send_relayd_streams_sent(
734 new_stream
->net_seq_idx
);
741 /* Get the right pipe where the stream will be sent. */
742 if (new_stream
->metadata_flag
) {
743 consumer_add_metadata_stream(new_stream
);
744 stream_pipe
= ctx
->consumer_metadata_pipe
;
746 consumer_add_data_stream(new_stream
);
747 stream_pipe
= ctx
->consumer_data_pipe
;
750 /* Visible to other threads */
751 new_stream
->globally_visible
= 1;
753 health_code_update();
755 ret
= lttng_pipe_write(stream_pipe
, &new_stream
, sizeof(new_stream
));
757 ERR("Consumer write %s stream to pipe %d",
758 new_stream
->metadata_flag
? "metadata" : "data",
759 lttng_pipe_get_writefd(stream_pipe
));
760 if (new_stream
->metadata_flag
) {
761 consumer_del_stream_for_metadata(new_stream
);
763 consumer_del_stream_for_data(new_stream
);
768 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64
,
769 new_stream
->name
, fd
, new_stream
->chan
->pathname
, new_stream
->relayd_stream_id
);
772 case LTTNG_CONSUMER_STREAMS_SENT
:
774 struct lttng_consumer_channel
*channel
;
777 * Get stream's channel reference. Needed when adding the stream to the
780 channel
= consumer_find_channel(msg
.u
.sent_streams
.channel_key
);
783 * We could not find the channel. Can happen if cpu hotplug
784 * happens while tearing down.
786 ERR("Unable to find channel key %" PRIu64
,
787 msg
.u
.sent_streams
.channel_key
);
788 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
791 health_code_update();
794 * Send status code to session daemon.
796 ret
= consumer_send_status_msg(sock
, ret_code
);
797 if (ret
< 0 || ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
798 /* Somehow, the session daemon is not responding anymore. */
802 health_code_update();
805 * We should not send this message if we don't monitor the
806 * streams in this channel.
808 if (!channel
->monitor
) {
812 health_code_update();
813 /* Send stream to relayd if the stream has an ID. */
814 if (msg
.u
.sent_streams
.net_seq_idx
!= (uint64_t) -1ULL) {
815 ret
= consumer_send_relayd_streams_sent(
816 msg
.u
.sent_streams
.net_seq_idx
);
820 channel
->streams_sent_to_relayd
= true;
824 case LTTNG_CONSUMER_UPDATE_STREAM
:
829 case LTTNG_CONSUMER_DESTROY_RELAYD
:
831 uint64_t index
= msg
.u
.destroy_relayd
.net_seq_idx
;
832 struct consumer_relayd_sock_pair
*relayd
;
834 DBG("Kernel consumer destroying relayd %" PRIu64
, index
);
836 /* Get relayd reference if exists. */
837 relayd
= consumer_find_relayd(index
);
838 if (relayd
== NULL
) {
839 DBG("Unable to find relayd %" PRIu64
, index
);
840 ret_code
= LTTCOMM_CONSUMERD_RELAYD_FAIL
;
844 * Each relayd socket pair has a refcount of stream attached to it
845 * which tells if the relayd is still active or not depending on the
848 * This will set the destroy flag of the relayd object and destroy it
849 * if the refcount reaches zero when called.
851 * The destroy can happen either here or when a stream fd hangs up.
854 consumer_flag_relayd_for_destroy(relayd
);
857 health_code_update();
859 ret
= consumer_send_status_msg(sock
, ret_code
);
861 /* Somehow, the session daemon is not responding anymore. */
867 case LTTNG_CONSUMER_DATA_PENDING
:
870 uint64_t id
= msg
.u
.data_pending
.session_id
;
872 DBG("Kernel consumer data pending command for id %" PRIu64
, id
);
874 ret
= consumer_data_pending(id
);
876 health_code_update();
878 /* Send back returned value to session daemon */
879 ret
= lttcomm_send_unix_sock(sock
, &ret
, sizeof(ret
));
881 PERROR("send data pending ret code");
886 * No need to send back a status message since the data pending
887 * returned value is the response.
891 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL
:
893 struct lttng_consumer_channel
*channel
;
894 uint64_t key
= msg
.u
.snapshot_channel
.key
;
896 channel
= consumer_find_channel(key
);
898 ERR("Channel %" PRIu64
" not found", key
);
899 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
901 if (msg
.u
.snapshot_channel
.metadata
== 1) {
902 ret
= lttng_kconsumer_snapshot_metadata(channel
, key
,
903 msg
.u
.snapshot_channel
.pathname
,
904 msg
.u
.snapshot_channel
.relayd_id
, ctx
);
906 ERR("Snapshot metadata failed");
907 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
910 ret
= lttng_kconsumer_snapshot_channel(channel
, key
,
911 msg
.u
.snapshot_channel
.pathname
,
912 msg
.u
.snapshot_channel
.relayd_id
,
913 msg
.u
.snapshot_channel
.nb_packets_per_stream
,
916 ERR("Snapshot channel failed");
917 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
921 health_code_update();
923 ret
= consumer_send_status_msg(sock
, ret_code
);
925 /* Somehow, the session daemon is not responding anymore. */
930 case LTTNG_CONSUMER_DESTROY_CHANNEL
:
932 uint64_t key
= msg
.u
.destroy_channel
.key
;
933 struct lttng_consumer_channel
*channel
;
935 channel
= consumer_find_channel(key
);
937 ERR("Kernel consumer destroy channel %" PRIu64
" not found", key
);
938 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
941 health_code_update();
943 ret
= consumer_send_status_msg(sock
, ret_code
);
945 /* Somehow, the session daemon is not responding anymore. */
949 health_code_update();
951 /* Stop right now if no channel was found. */
957 * This command should ONLY be issued for channel with streams set in
960 assert(!channel
->monitor
);
963 * The refcount should ALWAYS be 0 in the case of a channel in no
966 assert(!uatomic_sub_return(&channel
->refcount
, 1));
968 consumer_del_channel(channel
);
972 case LTTNG_CONSUMER_DISCARDED_EVENTS
:
976 struct lttng_consumer_channel
*channel
;
977 uint64_t id
= msg
.u
.discarded_events
.session_id
;
978 uint64_t key
= msg
.u
.discarded_events
.channel_key
;
980 DBG("Kernel consumer discarded events command for session id %"
981 PRIu64
", channel key %" PRIu64
, id
, key
);
983 channel
= consumer_find_channel(key
);
985 ERR("Kernel consumer discarded events channel %"
986 PRIu64
" not found", key
);
989 count
= channel
->discarded_events
;
992 health_code_update();
994 /* Send back returned value to session daemon */
995 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
997 PERROR("send discarded events");
1003 case LTTNG_CONSUMER_LOST_PACKETS
:
1007 struct lttng_consumer_channel
*channel
;
1008 uint64_t id
= msg
.u
.lost_packets
.session_id
;
1009 uint64_t key
= msg
.u
.lost_packets
.channel_key
;
1011 DBG("Kernel consumer lost packets command for session id %"
1012 PRIu64
", channel key %" PRIu64
, id
, key
);
1014 channel
= consumer_find_channel(key
);
1016 ERR("Kernel consumer lost packets channel %"
1017 PRIu64
" not found", key
);
1020 count
= channel
->lost_packets
;
1023 health_code_update();
1025 /* Send back returned value to session daemon */
1026 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1028 PERROR("send lost packets");
1034 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1036 int channel_monitor_pipe
;
1038 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1039 /* Successfully received the command's type. */
1040 ret
= consumer_send_status_msg(sock
, ret_code
);
1045 ret
= lttcomm_recv_fds_unix_sock(sock
, &channel_monitor_pipe
,
1047 if (ret
!= sizeof(channel_monitor_pipe
)) {
1048 ERR("Failed to receive channel monitor pipe");
1052 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe
);
1053 ret
= consumer_timer_thread_set_channel_monitor_pipe(
1054 channel_monitor_pipe
);
1058 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1059 /* Set the pipe as non-blocking. */
1060 ret
= fcntl(channel_monitor_pipe
, F_GETFL
, 0);
1062 PERROR("fcntl get flags of the channel monitoring pipe");
1067 ret
= fcntl(channel_monitor_pipe
, F_SETFL
,
1068 flags
| O_NONBLOCK
);
1070 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1073 DBG("Channel monitor pipe set as non-blocking");
1075 ret_code
= LTTCOMM_CONSUMERD_ALREADY_SET
;
1077 ret
= consumer_send_status_msg(sock
, ret_code
);
1083 case LTTNG_CONSUMER_ROTATE_CHANNEL
:
1085 struct lttng_consumer_channel
*channel
;
1086 uint64_t key
= msg
.u
.rotate_channel
.key
;
1088 DBG("Consumer rotate channel %" PRIu64
, key
);
1090 channel
= consumer_find_channel(key
);
1092 ERR("Channel %" PRIu64
" not found", key
);
1093 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1096 * Sample the rotate position of all the streams in this channel.
1098 ret
= lttng_consumer_rotate_channel(channel
, key
,
1099 msg
.u
.rotate_channel
.pathname
,
1100 msg
.u
.rotate_channel
.relayd_id
,
1101 msg
.u
.rotate_channel
.metadata
,
1102 msg
.u
.rotate_channel
.new_chunk_id
,
1105 ERR("Rotate channel failed");
1106 ret_code
= LTTCOMM_CONSUMERD_ROTATION_FAIL
;
1109 health_code_update();
1111 ret
= consumer_send_status_msg(sock
, ret_code
);
1113 /* Somehow, the session daemon is not responding anymore. */
1117 /* Rotate the streams that are ready right now. */
1118 ret
= lttng_consumer_rotate_ready_streams(
1121 ERR("Rotate ready streams failed");
1127 case LTTNG_CONSUMER_ROTATE_RENAME
:
1129 DBG("Consumer rename session %" PRIu64
" after rotation, old path = \"%s\", new path = \"%s\"",
1130 msg
.u
.rotate_rename
.session_id
,
1131 msg
.u
.rotate_rename
.old_path
,
1132 msg
.u
.rotate_rename
.new_path
);
1133 ret
= lttng_consumer_rotate_rename(msg
.u
.rotate_rename
.old_path
,
1134 msg
.u
.rotate_rename
.new_path
,
1135 msg
.u
.rotate_rename
.uid
,
1136 msg
.u
.rotate_rename
.gid
,
1137 msg
.u
.rotate_rename
.relayd_id
);
1139 ERR("Rotate rename failed");
1140 ret_code
= LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED
;
1143 health_code_update();
1145 ret
= consumer_send_status_msg(sock
, ret_code
);
1147 /* Somehow, the session daemon is not responding anymore. */
1152 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
:
1155 uint32_t pending_reply
;
1157 DBG("Perform local check of pending rotation for session id %" PRIu64
,
1158 msg
.u
.check_rotation_pending_local
.session_id
);
1159 pending
= lttng_consumer_check_rotation_pending_local(
1160 msg
.u
.check_rotation_pending_local
.session_id
,
1161 msg
.u
.check_rotation_pending_local
.chunk_id
);
1163 ERR("Local rotation pending check failed with code %i", pending
);
1164 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED
;
1166 pending_reply
= !!pending
;
1169 health_code_update();
1171 ret
= consumer_send_status_msg(sock
, ret_code
);
1173 /* Somehow, the session daemon is not responding anymore. */
1179 * An error occurred while running the command;
1180 * don't send the 'pending' flag as the sessiond
1186 /* Send back returned value to session daemon */
1187 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1188 sizeof(pending_reply
));
1190 PERROR("Failed to send rotation pending return code");
1195 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
:
1198 uint32_t pending_reply
;
1200 DBG("Perform relayd check of pending rotation for session id %" PRIu64
,
1201 msg
.u
.check_rotation_pending_relay
.session_id
);
1202 pending
= lttng_consumer_check_rotation_pending_relay(
1203 msg
.u
.check_rotation_pending_relay
.session_id
,
1204 msg
.u
.check_rotation_pending_relay
.relayd_id
,
1205 msg
.u
.check_rotation_pending_relay
.chunk_id
);
1207 ERR("Relayd rotation pending check failed with code %i", pending
);
1208 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED
;
1210 pending_reply
= !!pending
;
1213 health_code_update();
1215 ret
= consumer_send_status_msg(sock
, ret_code
);
1217 /* Somehow, the session daemon is not responding anymore. */
1223 * An error occurred while running the command;
1224 * don't send the 'pending' flag as the sessiond
1230 /* Send back returned value to session daemon */
1231 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1232 sizeof(pending_reply
));
1234 PERROR("Failed to send rotation pending return code");
1239 case LTTNG_CONSUMER_MKDIR
:
1241 DBG("Consumer mkdir %s in session %" PRIu64
,
1243 msg
.u
.mkdir
.session_id
);
1244 ret
= lttng_consumer_mkdir(msg
.u
.mkdir
.path
,
1247 msg
.u
.mkdir
.relayd_id
);
1249 ERR("consumer mkdir failed");
1250 ret_code
= LTTCOMM_CONSUMERD_MKDIR_FAILED
;
1253 health_code_update();
1255 ret
= consumer_send_status_msg(sock
, ret_code
);
1257 /* Somehow, the session daemon is not responding anymore. */
1270 * Return 1 to indicate success since the 0 value can be a socket
1271 * shutdown during the recv() or send() call.
1273 health_code_update();
1278 /* This will issue a consumer stop. */
1283 * Populate index values of a kernel stream. Values are set in big endian order.
1285 * Return 0 on success or else a negative value.
1287 static int get_index_values(struct ctf_packet_index
*index
, int infd
)
1291 ret
= kernctl_get_timestamp_begin(infd
, &index
->timestamp_begin
);
1293 PERROR("kernctl_get_timestamp_begin");
1296 index
->timestamp_begin
= htobe64(index
->timestamp_begin
);
1298 ret
= kernctl_get_timestamp_end(infd
, &index
->timestamp_end
);
1300 PERROR("kernctl_get_timestamp_end");
1303 index
->timestamp_end
= htobe64(index
->timestamp_end
);
1305 ret
= kernctl_get_events_discarded(infd
, &index
->events_discarded
);
1307 PERROR("kernctl_get_events_discarded");
1310 index
->events_discarded
= htobe64(index
->events_discarded
);
1312 ret
= kernctl_get_content_size(infd
, &index
->content_size
);
1314 PERROR("kernctl_get_content_size");
1317 index
->content_size
= htobe64(index
->content_size
);
1319 ret
= kernctl_get_packet_size(infd
, &index
->packet_size
);
1321 PERROR("kernctl_get_packet_size");
1324 index
->packet_size
= htobe64(index
->packet_size
);
1326 ret
= kernctl_get_stream_id(infd
, &index
->stream_id
);
1328 PERROR("kernctl_get_stream_id");
1331 index
->stream_id
= htobe64(index
->stream_id
);
1333 ret
= kernctl_get_instance_id(infd
, &index
->stream_instance_id
);
1335 if (ret
== -ENOTTY
) {
1336 /* Command not implemented by lttng-modules. */
1337 index
->stream_instance_id
= -1ULL;
1339 PERROR("kernctl_get_instance_id");
1343 index
->stream_instance_id
= htobe64(index
->stream_instance_id
);
1345 ret
= kernctl_get_sequence_number(infd
, &index
->packet_seq_num
);
1347 if (ret
== -ENOTTY
) {
1348 /* Command not implemented by lttng-modules. */
1349 index
->packet_seq_num
= -1ULL;
1352 PERROR("kernctl_get_sequence_number");
1356 index
->packet_seq_num
= htobe64(index
->packet_seq_num
);
1362 * Sync metadata meaning request them to the session daemon and snapshot to the
1363 * metadata thread can consumer them.
1365 * Metadata stream lock MUST be acquired.
1367 * Return 0 if new metadatda is available, EAGAIN if the metadata stream
1368 * is empty or a negative value on error.
1370 int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream
*metadata
)
1376 ret
= kernctl_buffer_flush(metadata
->wait_fd
);
1378 ERR("Failed to flush kernel stream");
1382 ret
= kernctl_snapshot(metadata
->wait_fd
);
1384 if (ret
!= -EAGAIN
) {
1385 ERR("Sync metadata, taking kernel snapshot failed.");
1388 DBG("Sync metadata, no new kernel metadata");
1389 /* No new metadata, exit. */
1399 int update_stream_stats(struct lttng_consumer_stream
*stream
)
1402 uint64_t seq
, discarded
;
1404 ret
= kernctl_get_sequence_number(stream
->wait_fd
, &seq
);
1406 if (ret
== -ENOTTY
) {
1407 /* Command not implemented by lttng-modules. */
1410 PERROR("kernctl_get_sequence_number");
1416 * Start the sequence when we extract the first packet in case we don't
1417 * start at 0 (for example if a consumer is not connected to the
1418 * session immediately after the beginning).
1420 if (stream
->last_sequence_number
== -1ULL) {
1421 stream
->last_sequence_number
= seq
;
1422 } else if (seq
> stream
->last_sequence_number
) {
1423 stream
->chan
->lost_packets
+= seq
-
1424 stream
->last_sequence_number
- 1;
1426 /* seq <= last_sequence_number */
1427 ERR("Sequence number inconsistent : prev = %" PRIu64
1428 ", current = %" PRIu64
,
1429 stream
->last_sequence_number
, seq
);
1433 stream
->last_sequence_number
= seq
;
1435 ret
= kernctl_get_events_discarded(stream
->wait_fd
, &discarded
);
1437 PERROR("kernctl_get_events_discarded");
1440 if (discarded
< stream
->last_discarded_events
) {
1442 * Overflow has occurred. We assume only one wrap-around
1445 stream
->chan
->discarded_events
+= (1ULL << (CAA_BITS_PER_LONG
- 1)) -
1446 stream
->last_discarded_events
+ discarded
;
1448 stream
->chan
->discarded_events
+= discarded
-
1449 stream
->last_discarded_events
;
1451 stream
->last_discarded_events
= discarded
;
1459 * Check if the local version of the metadata stream matches with the version
1460 * of the metadata stream in the kernel. If it was updated, set the reset flag
1464 int metadata_stream_check_version(int infd
, struct lttng_consumer_stream
*stream
)
1467 uint64_t cur_version
;
1469 ret
= kernctl_get_metadata_version(infd
, &cur_version
);
1471 if (ret
== -ENOTTY
) {
1473 * LTTng-modules does not implement this
1479 ERR("Failed to get the metadata version");
1483 if (stream
->metadata_version
== cur_version
) {
1488 DBG("New metadata version detected");
1489 stream
->metadata_version
= cur_version
;
1490 stream
->reset_metadata_flag
= 1;
1498 * Consume data on a file descriptor and write it on a trace file.
1500 ssize_t
lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream
*stream
,
1501 struct lttng_consumer_local_data
*ctx
, bool *rotated
)
1503 unsigned long len
, subbuf_size
, padding
;
1504 int err
, write_index
= 1, rotation_ret
;
1506 int infd
= stream
->wait_fd
;
1507 struct ctf_packet_index index
;
1509 DBG("In read_subbuffer (infd : %d)", infd
);
1512 * If the stream was flagged to be ready for rotation before we extract the
1513 * next packet, rotate it now.
1515 if (stream
->rotate_ready
) {
1516 DBG("Rotate stream before extracting data");
1517 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1518 if (rotation_ret
< 0) {
1519 ERR("Stream rotation error");
1525 /* Get the next subbuffer */
1526 err
= kernctl_get_next_subbuf(infd
);
1529 * This is a debug message even for single-threaded consumer,
1530 * because poll() have more relaxed criterions than get subbuf,
1531 * so get_subbuf may fail for short race windows where poll()
1532 * would issue wakeups.
1534 DBG("Reserving sub buffer failed (everything is normal, "
1535 "it is due to concurrency)");
1540 /* Get the full subbuffer size including padding */
1541 err
= kernctl_get_padded_subbuf_size(infd
, &len
);
1543 PERROR("Getting sub-buffer len failed.");
1544 err
= kernctl_put_subbuf(infd
);
1546 if (err
== -EFAULT
) {
1547 PERROR("Error in unreserving sub buffer\n");
1548 } else if (err
== -EIO
) {
1549 /* Should never happen with newer LTTng versions */
1550 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1559 if (!stream
->metadata_flag
) {
1560 ret
= get_index_values(&index
, infd
);
1562 err
= kernctl_put_subbuf(infd
);
1564 if (err
== -EFAULT
) {
1565 PERROR("Error in unreserving sub buffer\n");
1566 } else if (err
== -EIO
) {
1567 /* Should never happen with newer LTTng versions */
1568 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1575 ret
= update_stream_stats(stream
);
1577 err
= kernctl_put_subbuf(infd
);
1579 if (err
== -EFAULT
) {
1580 PERROR("Error in unreserving sub buffer\n");
1581 } else if (err
== -EIO
) {
1582 /* Should never happen with newer LTTng versions */
1583 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1592 ret
= metadata_stream_check_version(infd
, stream
);
1594 err
= kernctl_put_subbuf(infd
);
1596 if (err
== -EFAULT
) {
1597 PERROR("Error in unreserving sub buffer\n");
1598 } else if (err
== -EIO
) {
1599 /* Should never happen with newer LTTng versions */
1600 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1609 switch (stream
->chan
->output
) {
1610 case CONSUMER_CHANNEL_SPLICE
:
1612 * XXX: The lttng-modules splice "actor" does not handle copying
1613 * partial pages hence only using the subbuffer size without the
1614 * padding makes the splice fail.
1619 /* splice the subbuffer to the tracefile */
1620 ret
= lttng_consumer_on_read_subbuffer_splice(ctx
, stream
, subbuf_size
,
1623 * XXX: Splice does not support network streaming so the return value
1624 * is simply checked against subbuf_size and not like the mmap() op.
1626 if (ret
!= subbuf_size
) {
1628 * display the error but continue processing to try
1629 * to release the subbuffer
1631 ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
1636 case CONSUMER_CHANNEL_MMAP
:
1637 /* Get subbuffer size without padding */
1638 err
= kernctl_get_subbuf_size(infd
, &subbuf_size
);
1640 PERROR("Getting sub-buffer len failed.");
1641 err
= kernctl_put_subbuf(infd
);
1643 if (err
== -EFAULT
) {
1644 PERROR("Error in unreserving sub buffer\n");
1645 } else if (err
== -EIO
) {
1646 /* Should never happen with newer LTTng versions */
1647 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1656 /* Make sure the tracer is not gone mad on us! */
1657 assert(len
>= subbuf_size
);
1659 padding
= len
- subbuf_size
;
1661 /* write the subbuffer to the tracefile */
1662 ret
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, subbuf_size
,
1665 * The mmap operation should write subbuf_size amount of data when
1666 * network streaming or the full padding (len) size when we are _not_
1669 if ((ret
!= subbuf_size
&& stream
->net_seq_idx
!= (uint64_t) -1ULL) ||
1670 (ret
!= len
&& stream
->net_seq_idx
== (uint64_t) -1ULL)) {
1672 * Display the error but continue processing to try to release the
1673 * subbuffer. This is a DBG statement since this is possible to
1674 * happen without being a critical error.
1676 DBG("Error writing to tracefile "
1677 "(ret: %zd != len: %lu != subbuf_size: %lu)",
1678 ret
, len
, subbuf_size
);
1683 ERR("Unknown output method");
1687 err
= kernctl_put_next_subbuf(infd
);
1689 if (err
== -EFAULT
) {
1690 PERROR("Error in unreserving sub buffer\n");
1691 } else if (err
== -EIO
) {
1692 /* Should never happen with newer LTTng versions */
1693 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1699 /* Write index if needed. */
1704 if (stream
->chan
->live_timer_interval
&& !stream
->metadata_flag
) {
1706 * In live, block until all the metadata is sent.
1708 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1709 assert(!stream
->missed_metadata_flush
);
1710 stream
->waiting_on_metadata
= true;
1711 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1713 err
= consumer_stream_sync_metadata(ctx
, stream
->session_id
);
1715 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1716 stream
->waiting_on_metadata
= false;
1717 if (stream
->missed_metadata_flush
) {
1718 stream
->missed_metadata_flush
= false;
1719 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1720 (void) consumer_flush_kernel_index(stream
);
1722 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1729 err
= consumer_stream_write_index(stream
, &index
);
1736 * After extracting the packet, we check if the stream is now ready to be
1737 * rotated and perform the action immediately.
1739 rotation_ret
= lttng_consumer_stream_is_rotate_ready(stream
);
1740 if (rotation_ret
== 1) {
1741 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1742 if (rotation_ret
< 0) {
1743 ERR("Stream rotation error");
1747 } else if (rotation_ret
< 0) {
1748 ERR("Checking if stream is ready to rotate");
1757 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream
*stream
)
1764 * Don't create anything if this is set for streaming or should not be
1767 if (stream
->net_seq_idx
== (uint64_t) -1ULL && stream
->chan
->monitor
) {
1768 ret
= utils_create_stream_file(stream
->chan
->pathname
, stream
->name
,
1769 stream
->chan
->tracefile_size
, stream
->tracefile_count_current
,
1770 stream
->uid
, stream
->gid
, NULL
);
1774 stream
->out_fd
= ret
;
1775 stream
->tracefile_size_current
= 0;
1777 if (!stream
->metadata_flag
) {
1778 struct lttng_index_file
*index_file
;
1780 index_file
= lttng_index_file_create(stream
->chan
->pathname
,
1781 stream
->name
, stream
->uid
, stream
->gid
,
1782 stream
->chan
->tracefile_size
,
1783 stream
->tracefile_count_current
,
1784 CTF_INDEX_MAJOR
, CTF_INDEX_MINOR
);
1788 assert(!stream
->index_file
);
1789 stream
->index_file
= index_file
;
1793 if (stream
->output
== LTTNG_EVENT_MMAP
) {
1794 /* get the len of the mmap region */
1795 unsigned long mmap_len
;
1797 ret
= kernctl_get_mmap_len(stream
->wait_fd
, &mmap_len
);
1799 PERROR("kernctl_get_mmap_len");
1800 goto error_close_fd
;
1802 stream
->mmap_len
= (size_t) mmap_len
;
1804 stream
->mmap_base
= mmap(NULL
, stream
->mmap_len
, PROT_READ
,
1805 MAP_PRIVATE
, stream
->wait_fd
, 0);
1806 if (stream
->mmap_base
== MAP_FAILED
) {
1807 PERROR("Error mmaping");
1809 goto error_close_fd
;
1813 /* we return 0 to let the library handle the FD internally */
1817 if (stream
->out_fd
>= 0) {
1820 err
= close(stream
->out_fd
);
1822 stream
->out_fd
= -1;
1829 * Check if data is still being extracted from the buffers for a specific
1830 * stream. Consumer data lock MUST be acquired before calling this function
1831 * and the stream lock.
1833 * Return 1 if the traced data are still getting read else 0 meaning that the
1834 * data is available for trace viewer reading.
1836 int lttng_kconsumer_data_pending(struct lttng_consumer_stream
*stream
)
1842 if (stream
->endpoint_status
!= CONSUMER_ENDPOINT_ACTIVE
) {
1847 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1849 /* There is still data so let's put back this subbuffer. */
1850 ret
= kernctl_put_subbuf(stream
->wait_fd
);
1852 ret
= 1; /* Data is pending */
1856 /* Data is NOT pending and ready to be read. */