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
128 * Returns 0 on success, < 0 on error
130 int lttng_kconsumer_snapshot_channel(uint64_t key
, char *path
,
131 uint64_t relayd_id
, uint64_t nb_packets_per_stream
,
132 struct lttng_consumer_local_data
*ctx
)
135 struct lttng_consumer_channel
*channel
;
136 struct lttng_consumer_stream
*stream
;
138 DBG("Kernel consumer snapshot channel %" PRIu64
, key
);
142 channel
= consumer_find_channel(key
);
144 ERR("No channel found for key %" PRIu64
, key
);
149 /* Splice is not supported yet for channel snapshot. */
150 if (channel
->output
!= CONSUMER_CHANNEL_MMAP
) {
151 ERR("Unsupported output %d", channel
->output
);
156 cds_list_for_each_entry(stream
, &channel
->streams
.head
, send_node
) {
157 unsigned long consumed_pos
, produced_pos
;
159 health_code_update();
162 * Lock stream because we are about to change its state.
164 pthread_mutex_lock(&stream
->lock
);
167 * Assign the received relayd ID so we can use it for streaming. The streams
168 * are not visible to anyone so this is OK to change it.
170 stream
->net_seq_idx
= relayd_id
;
171 channel
->relayd_id
= relayd_id
;
172 if (relayd_id
!= (uint64_t) -1ULL) {
173 ret
= consumer_send_relayd_stream(stream
, path
);
175 ERR("sending stream to relayd");
179 ret
= utils_create_stream_file(path
, stream
->name
,
180 stream
->chan
->tracefile_size
,
181 stream
->tracefile_count_current
,
182 stream
->uid
, stream
->gid
, NULL
);
184 ERR("utils_create_stream_file");
188 stream
->out_fd
= ret
;
189 stream
->tracefile_size_current
= 0;
191 DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64
")",
192 path
, stream
->name
, stream
->key
);
195 ret
= kernctl_buffer_flush_empty(stream
->wait_fd
);
198 * Doing a buffer flush which does not take into
199 * account empty packets. This is not perfect
200 * for stream intersection, but required as a
201 * fall-back when "flush_empty" is not
202 * implemented by lttng-modules.
204 ret
= kernctl_buffer_flush(stream
->wait_fd
);
206 ERR("Failed to flush kernel stream");
212 ret
= lttng_kconsumer_take_snapshot(stream
);
214 ERR("Taking kernel snapshot");
218 ret
= lttng_kconsumer_get_produced_snapshot(stream
, &produced_pos
);
220 ERR("Produced kernel snapshot position");
224 ret
= lttng_kconsumer_get_consumed_snapshot(stream
, &consumed_pos
);
226 ERR("Consumerd kernel snapshot position");
230 if (stream
->max_sb_size
== 0) {
231 ret
= kernctl_get_max_subbuf_size(stream
->wait_fd
,
232 &stream
->max_sb_size
);
234 ERR("Getting kernel max_sb_size");
239 consumed_pos
= consumer_get_consume_start_pos(consumed_pos
,
240 produced_pos
, nb_packets_per_stream
,
241 stream
->max_sb_size
);
243 while (consumed_pos
< produced_pos
) {
245 unsigned long len
, padded_len
;
247 health_code_update();
249 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos
);
251 ret
= kernctl_get_subbuf(stream
->wait_fd
, &consumed_pos
);
253 if (ret
!= -EAGAIN
) {
254 PERROR("kernctl_get_subbuf snapshot");
257 DBG("Kernel consumer get subbuf failed. Skipping it.");
258 consumed_pos
+= stream
->max_sb_size
;
259 stream
->chan
->lost_packets
++;
263 ret
= kernctl_get_subbuf_size(stream
->wait_fd
, &len
);
265 ERR("Snapshot kernctl_get_subbuf_size");
266 goto error_put_subbuf
;
269 ret
= kernctl_get_padded_subbuf_size(stream
->wait_fd
, &padded_len
);
271 ERR("Snapshot kernctl_get_padded_subbuf_size");
272 goto error_put_subbuf
;
275 read_len
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, len
,
276 padded_len
- len
, NULL
);
278 * We write the padded len in local tracefiles but the data len
279 * when using a relay. Display the error but continue processing
280 * to try to release the subbuffer.
282 if (relayd_id
!= (uint64_t) -1ULL) {
283 if (read_len
!= len
) {
284 ERR("Error sending to the relay (ret: %zd != len: %lu)",
288 if (read_len
!= padded_len
) {
289 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
290 read_len
, padded_len
);
294 ret
= kernctl_put_subbuf(stream
->wait_fd
);
296 ERR("Snapshot kernctl_put_subbuf");
299 consumed_pos
+= stream
->max_sb_size
;
302 if (relayd_id
== (uint64_t) -1ULL) {
303 if (stream
->out_fd
>= 0) {
304 ret
= close(stream
->out_fd
);
306 PERROR("Kernel consumer snapshot close out_fd");
312 close_relayd_stream(stream
);
313 stream
->net_seq_idx
= (uint64_t) -1ULL;
315 pthread_mutex_unlock(&stream
->lock
);
323 ret
= kernctl_put_subbuf(stream
->wait_fd
);
325 ERR("Snapshot kernctl_put_subbuf error path");
328 pthread_mutex_unlock(&stream
->lock
);
335 * Read the whole metadata available for a snapshot.
337 * Returns 0 on success, < 0 on error
339 static int lttng_kconsumer_snapshot_metadata(uint64_t key
, char *path
,
340 uint64_t relayd_id
, struct lttng_consumer_local_data
*ctx
)
342 int ret
, use_relayd
= 0;
344 struct lttng_consumer_channel
*metadata_channel
;
345 struct lttng_consumer_stream
*metadata_stream
;
349 DBG("Kernel consumer snapshot metadata with key %" PRIu64
" at path %s",
354 metadata_channel
= consumer_find_channel(key
);
355 if (!metadata_channel
) {
356 ERR("Kernel snapshot metadata not found for key %" PRIu64
, key
);
358 goto error_no_channel
;
361 metadata_stream
= metadata_channel
->metadata_stream
;
362 assert(metadata_stream
);
363 pthread_mutex_lock(&metadata_stream
->lock
);
365 /* Flag once that we have a valid relayd for the stream. */
366 if (relayd_id
!= (uint64_t) -1ULL) {
371 ret
= consumer_send_relayd_stream(metadata_stream
, path
);
376 ret
= utils_create_stream_file(path
, metadata_stream
->name
,
377 metadata_stream
->chan
->tracefile_size
,
378 metadata_stream
->tracefile_count_current
,
379 metadata_stream
->uid
, metadata_stream
->gid
, NULL
);
383 metadata_stream
->out_fd
= ret
;
387 health_code_update();
389 ret_read
= lttng_kconsumer_read_subbuffer(metadata_stream
, ctx
, NULL
);
391 if (ret_read
!= -EAGAIN
) {
392 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
397 /* ret_read is negative at this point so we will exit the loop. */
400 } while (ret_read
>= 0);
403 close_relayd_stream(metadata_stream
);
404 metadata_stream
->net_seq_idx
= (uint64_t) -1ULL;
406 if (metadata_stream
->out_fd
>= 0) {
407 ret
= close(metadata_stream
->out_fd
);
409 PERROR("Kernel consumer snapshot metadata close out_fd");
411 * Don't go on error here since the snapshot was successful at this
412 * point but somehow the close failed.
415 metadata_stream
->out_fd
= -1;
421 pthread_mutex_unlock(&metadata_stream
->lock
);
422 cds_list_del(&metadata_stream
->send_node
);
423 consumer_stream_destroy(metadata_stream
, NULL
);
424 metadata_channel
->metadata_stream
= NULL
;
431 * Receive command from session daemon and process it.
433 * Return 1 on success else a negative value or 0.
435 int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data
*ctx
,
436 int sock
, struct pollfd
*consumer_sockpoll
)
439 enum lttcomm_return_code ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
440 struct lttcomm_consumer_msg msg
;
442 health_code_update();
444 ret
= lttcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
445 if (ret
!= sizeof(msg
)) {
447 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_CMD
);
453 health_code_update();
455 /* Deprecated command */
456 assert(msg
.cmd_type
!= LTTNG_CONSUMER_STOP
);
458 health_code_update();
460 /* relayd needs RCU read-side protection */
463 switch (msg
.cmd_type
) {
464 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET
:
466 /* Session daemon status message are handled in the following call. */
467 consumer_add_relayd_socket(msg
.u
.relayd_sock
.net_index
,
468 msg
.u
.relayd_sock
.type
, ctx
, sock
, consumer_sockpoll
,
469 &msg
.u
.relayd_sock
.sock
, msg
.u
.relayd_sock
.session_id
,
470 msg
.u
.relayd_sock
.relayd_session_id
);
473 case LTTNG_CONSUMER_ADD_CHANNEL
:
475 struct lttng_consumer_channel
*new_channel
;
478 health_code_update();
480 /* First send a status message before receiving the fds. */
481 ret
= consumer_send_status_msg(sock
, ret_code
);
483 /* Somehow, the session daemon is not responding anymore. */
487 health_code_update();
489 DBG("consumer_add_channel %" PRIu64
, msg
.u
.channel
.channel_key
);
490 new_channel
= consumer_allocate_channel(msg
.u
.channel
.channel_key
,
491 msg
.u
.channel
.session_id
, msg
.u
.channel
.pathname
,
492 msg
.u
.channel
.name
, msg
.u
.channel
.uid
, msg
.u
.channel
.gid
,
493 msg
.u
.channel
.relayd_id
, msg
.u
.channel
.output
,
494 msg
.u
.channel
.tracefile_size
,
495 msg
.u
.channel
.tracefile_count
, 0,
496 msg
.u
.channel
.monitor
,
497 msg
.u
.channel
.live_timer_interval
,
499 if (new_channel
== NULL
) {
500 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
503 new_channel
->nb_init_stream_left
= msg
.u
.channel
.nb_init_streams
;
504 switch (msg
.u
.channel
.output
) {
505 case LTTNG_EVENT_SPLICE
:
506 new_channel
->output
= CONSUMER_CHANNEL_SPLICE
;
508 case LTTNG_EVENT_MMAP
:
509 new_channel
->output
= CONSUMER_CHANNEL_MMAP
;
512 ERR("Channel output unknown %d", msg
.u
.channel
.output
);
516 /* Translate and save channel type. */
517 switch (msg
.u
.channel
.type
) {
518 case CONSUMER_CHANNEL_TYPE_DATA
:
519 case CONSUMER_CHANNEL_TYPE_METADATA
:
520 new_channel
->type
= msg
.u
.channel
.type
;
527 health_code_update();
529 if (ctx
->on_recv_channel
!= NULL
) {
530 ret_recv
= ctx
->on_recv_channel(new_channel
);
532 ret
= consumer_add_channel(new_channel
, ctx
);
533 } else if (ret_recv
< 0) {
537 ret
= consumer_add_channel(new_channel
, ctx
);
539 if (msg
.u
.channel
.type
== CONSUMER_CHANNEL_TYPE_DATA
&& !ret
) {
540 int monitor_start_ret
;
542 DBG("Consumer starting monitor timer");
543 consumer_timer_live_start(new_channel
,
544 msg
.u
.channel
.live_timer_interval
);
545 monitor_start_ret
= consumer_timer_monitor_start(
547 msg
.u
.channel
.monitor_timer_interval
);
548 if (monitor_start_ret
< 0) {
549 ERR("Starting channel monitoring timer failed");
555 health_code_update();
557 /* If we received an error in add_channel, we need to report it. */
559 ret
= consumer_send_status_msg(sock
, ret
);
568 case LTTNG_CONSUMER_ADD_STREAM
:
571 struct lttng_pipe
*stream_pipe
;
572 struct lttng_consumer_stream
*new_stream
;
573 struct lttng_consumer_channel
*channel
;
577 * Get stream's channel reference. Needed when adding the stream to the
580 channel
= consumer_find_channel(msg
.u
.stream
.channel_key
);
583 * We could not find the channel. Can happen if cpu hotplug
584 * happens while tearing down.
586 ERR("Unable to find channel key %" PRIu64
, msg
.u
.stream
.channel_key
);
587 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
590 health_code_update();
592 /* First send a status message before receiving the fds. */
593 ret
= consumer_send_status_msg(sock
, ret_code
);
595 /* Somehow, the session daemon is not responding anymore. */
599 health_code_update();
601 if (ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
602 /* Channel was not found. */
608 ret
= lttng_consumer_poll_socket(consumer_sockpoll
);
614 health_code_update();
616 /* Get stream file descriptor from socket */
617 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
618 if (ret
!= sizeof(fd
)) {
619 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_FD
);
624 health_code_update();
627 * Send status code to session daemon only if the recv works. If the
628 * above recv() failed, the session daemon is notified through the
629 * error socket and the teardown is eventually done.
631 ret
= consumer_send_status_msg(sock
, ret_code
);
633 /* Somehow, the session daemon is not responding anymore. */
637 health_code_update();
639 new_stream
= consumer_allocate_stream(channel
->key
,
641 LTTNG_CONSUMER_ACTIVE_STREAM
,
651 msg
.u
.stream
.trace_archive_id
);
652 if (new_stream
== NULL
) {
657 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
663 new_stream
->chan
= channel
;
664 new_stream
->wait_fd
= fd
;
665 consumer_stream_update_channel_attributes(new_stream
,
667 switch (channel
->output
) {
668 case CONSUMER_CHANNEL_SPLICE
:
669 new_stream
->output
= LTTNG_EVENT_SPLICE
;
670 ret
= utils_create_pipe(new_stream
->splice_pipe
);
675 case CONSUMER_CHANNEL_MMAP
:
676 new_stream
->output
= LTTNG_EVENT_MMAP
;
679 ERR("Stream output unknown %d", channel
->output
);
684 * We've just assigned the channel to the stream so increment the
685 * refcount right now. We don't need to increment the refcount for
686 * streams in no monitor because we handle manually the cleanup of
687 * those. It is very important to make sure there is NO prior
688 * consumer_del_stream() calls or else the refcount will be unbalanced.
690 if (channel
->monitor
) {
691 uatomic_inc(&new_stream
->chan
->refcount
);
695 * The buffer flush is done on the session daemon side for the kernel
696 * so no need for the stream "hangup_flush_done" variable to be
697 * tracked. This is important for a kernel stream since we don't rely
698 * on the flush state of the stream to read data. It's not the case for
699 * user space tracing.
701 new_stream
->hangup_flush_done
= 0;
703 health_code_update();
705 if (ctx
->on_recv_stream
) {
706 ret
= ctx
->on_recv_stream(new_stream
);
708 consumer_stream_free(new_stream
);
713 health_code_update();
715 if (new_stream
->metadata_flag
) {
716 channel
->metadata_stream
= new_stream
;
719 /* Do not monitor this stream. */
720 if (!channel
->monitor
) {
721 DBG("Kernel consumer add stream %s in no monitor mode with "
722 "relayd id %" PRIu64
, new_stream
->name
,
723 new_stream
->net_seq_idx
);
724 cds_list_add(&new_stream
->send_node
, &channel
->streams
.head
);
728 /* Send stream to relayd if the stream has an ID. */
729 if (new_stream
->net_seq_idx
!= (uint64_t) -1ULL) {
730 ret
= consumer_send_relayd_stream(new_stream
,
731 new_stream
->chan
->pathname
);
733 consumer_stream_free(new_stream
);
738 * If adding an extra stream to an already
739 * existing channel (e.g. cpu hotplug), we need
740 * to send the "streams_sent" command to relayd.
742 if (channel
->streams_sent_to_relayd
) {
743 ret
= consumer_send_relayd_streams_sent(
744 new_stream
->net_seq_idx
);
751 /* Get the right pipe where the stream will be sent. */
752 if (new_stream
->metadata_flag
) {
753 consumer_add_metadata_stream(new_stream
);
754 stream_pipe
= ctx
->consumer_metadata_pipe
;
756 consumer_add_data_stream(new_stream
);
757 stream_pipe
= ctx
->consumer_data_pipe
;
760 /* Visible to other threads */
761 new_stream
->globally_visible
= 1;
763 health_code_update();
765 ret
= lttng_pipe_write(stream_pipe
, &new_stream
, sizeof(new_stream
));
767 ERR("Consumer write %s stream to pipe %d",
768 new_stream
->metadata_flag
? "metadata" : "data",
769 lttng_pipe_get_writefd(stream_pipe
));
770 if (new_stream
->metadata_flag
) {
771 consumer_del_stream_for_metadata(new_stream
);
773 consumer_del_stream_for_data(new_stream
);
778 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64
,
779 new_stream
->name
, fd
, new_stream
->chan
->pathname
, new_stream
->relayd_stream_id
);
782 case LTTNG_CONSUMER_STREAMS_SENT
:
784 struct lttng_consumer_channel
*channel
;
787 * Get stream's channel reference. Needed when adding the stream to the
790 channel
= consumer_find_channel(msg
.u
.sent_streams
.channel_key
);
793 * We could not find the channel. Can happen if cpu hotplug
794 * happens while tearing down.
796 ERR("Unable to find channel key %" PRIu64
,
797 msg
.u
.sent_streams
.channel_key
);
798 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
801 health_code_update();
804 * Send status code to session daemon.
806 ret
= consumer_send_status_msg(sock
, ret_code
);
807 if (ret
< 0 || ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
808 /* Somehow, the session daemon is not responding anymore. */
812 health_code_update();
815 * We should not send this message if we don't monitor the
816 * streams in this channel.
818 if (!channel
->monitor
) {
822 health_code_update();
823 /* Send stream to relayd if the stream has an ID. */
824 if (msg
.u
.sent_streams
.net_seq_idx
!= (uint64_t) -1ULL) {
825 ret
= consumer_send_relayd_streams_sent(
826 msg
.u
.sent_streams
.net_seq_idx
);
830 channel
->streams_sent_to_relayd
= true;
834 case LTTNG_CONSUMER_UPDATE_STREAM
:
839 case LTTNG_CONSUMER_DESTROY_RELAYD
:
841 uint64_t index
= msg
.u
.destroy_relayd
.net_seq_idx
;
842 struct consumer_relayd_sock_pair
*relayd
;
844 DBG("Kernel consumer destroying relayd %" PRIu64
, index
);
846 /* Get relayd reference if exists. */
847 relayd
= consumer_find_relayd(index
);
848 if (relayd
== NULL
) {
849 DBG("Unable to find relayd %" PRIu64
, index
);
850 ret_code
= LTTCOMM_CONSUMERD_RELAYD_FAIL
;
854 * Each relayd socket pair has a refcount of stream attached to it
855 * which tells if the relayd is still active or not depending on the
858 * This will set the destroy flag of the relayd object and destroy it
859 * if the refcount reaches zero when called.
861 * The destroy can happen either here or when a stream fd hangs up.
864 consumer_flag_relayd_for_destroy(relayd
);
867 health_code_update();
869 ret
= consumer_send_status_msg(sock
, ret_code
);
871 /* Somehow, the session daemon is not responding anymore. */
877 case LTTNG_CONSUMER_DATA_PENDING
:
880 uint64_t id
= msg
.u
.data_pending
.session_id
;
882 DBG("Kernel consumer data pending command for id %" PRIu64
, id
);
884 ret
= consumer_data_pending(id
);
886 health_code_update();
888 /* Send back returned value to session daemon */
889 ret
= lttcomm_send_unix_sock(sock
, &ret
, sizeof(ret
));
891 PERROR("send data pending ret code");
896 * No need to send back a status message since the data pending
897 * returned value is the response.
901 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL
:
903 if (msg
.u
.snapshot_channel
.metadata
== 1) {
904 ret
= lttng_kconsumer_snapshot_metadata(msg
.u
.snapshot_channel
.key
,
905 msg
.u
.snapshot_channel
.pathname
,
906 msg
.u
.snapshot_channel
.relayd_id
, ctx
);
908 ERR("Snapshot metadata failed");
909 ret_code
= LTTCOMM_CONSUMERD_ERROR_METADATA
;
912 ret
= lttng_kconsumer_snapshot_channel(msg
.u
.snapshot_channel
.key
,
913 msg
.u
.snapshot_channel
.pathname
,
914 msg
.u
.snapshot_channel
.relayd_id
,
915 msg
.u
.snapshot_channel
.nb_packets_per_stream
,
918 ERR("Snapshot channel failed");
919 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
923 health_code_update();
925 ret
= consumer_send_status_msg(sock
, ret_code
);
927 /* Somehow, the session daemon is not responding anymore. */
932 case LTTNG_CONSUMER_DESTROY_CHANNEL
:
934 uint64_t key
= msg
.u
.destroy_channel
.key
;
935 struct lttng_consumer_channel
*channel
;
937 channel
= consumer_find_channel(key
);
939 ERR("Kernel consumer destroy channel %" PRIu64
" not found", key
);
940 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
943 health_code_update();
945 ret
= consumer_send_status_msg(sock
, ret_code
);
947 /* Somehow, the session daemon is not responding anymore. */
951 health_code_update();
953 /* Stop right now if no channel was found. */
959 * This command should ONLY be issued for channel with streams set in
962 assert(!channel
->monitor
);
965 * The refcount should ALWAYS be 0 in the case of a channel in no
968 assert(!uatomic_sub_return(&channel
->refcount
, 1));
970 consumer_del_channel(channel
);
974 case LTTNG_CONSUMER_DISCARDED_EVENTS
:
978 struct lttng_consumer_channel
*channel
;
979 uint64_t id
= msg
.u
.discarded_events
.session_id
;
980 uint64_t key
= msg
.u
.discarded_events
.channel_key
;
982 DBG("Kernel consumer discarded events command for session id %"
983 PRIu64
", channel key %" PRIu64
, id
, key
);
985 channel
= consumer_find_channel(key
);
987 ERR("Kernel consumer discarded events channel %"
988 PRIu64
" not found", key
);
991 count
= channel
->discarded_events
;
994 health_code_update();
996 /* Send back returned value to session daemon */
997 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
999 PERROR("send discarded events");
1005 case LTTNG_CONSUMER_LOST_PACKETS
:
1009 struct lttng_consumer_channel
*channel
;
1010 uint64_t id
= msg
.u
.lost_packets
.session_id
;
1011 uint64_t key
= msg
.u
.lost_packets
.channel_key
;
1013 DBG("Kernel consumer lost packets command for session id %"
1014 PRIu64
", channel key %" PRIu64
, id
, key
);
1016 channel
= consumer_find_channel(key
);
1018 ERR("Kernel consumer lost packets channel %"
1019 PRIu64
" not found", key
);
1022 count
= channel
->lost_packets
;
1025 health_code_update();
1027 /* Send back returned value to session daemon */
1028 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1030 PERROR("send lost packets");
1036 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1038 int channel_monitor_pipe
;
1040 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1041 /* Successfully received the command's type. */
1042 ret
= consumer_send_status_msg(sock
, ret_code
);
1047 ret
= lttcomm_recv_fds_unix_sock(sock
, &channel_monitor_pipe
,
1049 if (ret
!= sizeof(channel_monitor_pipe
)) {
1050 ERR("Failed to receive channel monitor pipe");
1054 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe
);
1055 ret
= consumer_timer_thread_set_channel_monitor_pipe(
1056 channel_monitor_pipe
);
1060 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1061 /* Set the pipe as non-blocking. */
1062 ret
= fcntl(channel_monitor_pipe
, F_GETFL
, 0);
1064 PERROR("fcntl get flags of the channel monitoring pipe");
1069 ret
= fcntl(channel_monitor_pipe
, F_SETFL
,
1070 flags
| O_NONBLOCK
);
1072 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1075 DBG("Channel monitor pipe set as non-blocking");
1077 ret_code
= LTTCOMM_CONSUMERD_ALREADY_SET
;
1079 ret
= consumer_send_status_msg(sock
, ret_code
);
1085 case LTTNG_CONSUMER_ROTATE_CHANNEL
:
1087 struct lttng_consumer_channel
*channel
;
1088 uint64_t key
= msg
.u
.rotate_channel
.key
;
1090 DBG("Consumer rotate channel %" PRIu64
, key
);
1092 channel
= consumer_find_channel(key
);
1094 ERR("Channel %" PRIu64
" not found", key
);
1095 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1098 * Sample the rotate position of all the streams in this channel.
1100 ret
= lttng_consumer_rotate_channel(channel
, key
,
1101 msg
.u
.rotate_channel
.pathname
,
1102 msg
.u
.rotate_channel
.relayd_id
,
1103 msg
.u
.rotate_channel
.metadata
,
1104 msg
.u
.rotate_channel
.new_chunk_id
,
1107 ERR("Rotate channel failed");
1108 ret_code
= LTTCOMM_CONSUMERD_ROTATION_FAIL
;
1111 health_code_update();
1113 ret
= consumer_send_status_msg(sock
, ret_code
);
1115 /* Somehow, the session daemon is not responding anymore. */
1119 /* Rotate the streams that are ready right now. */
1120 ret
= lttng_consumer_rotate_ready_streams(
1123 ERR("Rotate ready streams failed");
1129 case LTTNG_CONSUMER_ROTATE_RENAME
:
1131 DBG("Consumer rename session %" PRIu64
" after rotation, old path = \"%s\", new path = \"%s\"",
1132 msg
.u
.rotate_rename
.session_id
,
1133 msg
.u
.rotate_rename
.old_path
,
1134 msg
.u
.rotate_rename
.new_path
);
1135 ret
= lttng_consumer_rotate_rename(msg
.u
.rotate_rename
.old_path
,
1136 msg
.u
.rotate_rename
.new_path
,
1137 msg
.u
.rotate_rename
.uid
,
1138 msg
.u
.rotate_rename
.gid
,
1139 msg
.u
.rotate_rename
.relayd_id
);
1141 ERR("Rotate rename failed");
1142 ret_code
= LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED
;
1145 health_code_update();
1147 ret
= consumer_send_status_msg(sock
, ret_code
);
1149 /* Somehow, the session daemon is not responding anymore. */
1154 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
:
1157 uint32_t pending_reply
;
1159 DBG("Perform local check of pending rotation for session id %" PRIu64
,
1160 msg
.u
.check_rotation_pending_local
.session_id
);
1161 pending
= lttng_consumer_check_rotation_pending_local(
1162 msg
.u
.check_rotation_pending_local
.session_id
,
1163 msg
.u
.check_rotation_pending_local
.chunk_id
);
1165 ERR("Local rotation pending check failed with code %i", pending
);
1166 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED
;
1168 pending_reply
= !!pending
;
1171 health_code_update();
1173 ret
= consumer_send_status_msg(sock
, ret_code
);
1175 /* Somehow, the session daemon is not responding anymore. */
1181 * An error occured while running the command;
1182 * don't send the 'pending' flag as the sessiond
1188 /* Send back returned value to session daemon */
1189 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1190 sizeof(pending_reply
));
1192 PERROR("Failed to send rotation pending return code");
1197 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
:
1200 uint32_t pending_reply
;
1202 DBG("Perform relayd check of pending rotation for session id %" PRIu64
,
1203 msg
.u
.check_rotation_pending_relay
.session_id
);
1204 pending
= lttng_consumer_check_rotation_pending_relay(
1205 msg
.u
.check_rotation_pending_relay
.session_id
,
1206 msg
.u
.check_rotation_pending_relay
.relayd_id
,
1207 msg
.u
.check_rotation_pending_relay
.chunk_id
);
1209 ERR("Relayd rotation pending check failed with code %i", pending
);
1210 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED
;
1212 pending_reply
= !!pending
;
1215 health_code_update();
1217 ret
= consumer_send_status_msg(sock
, ret_code
);
1219 /* Somehow, the session daemon is not responding anymore. */
1225 * An error occured while running the command;
1226 * don't send the 'pending' flag as the sessiond
1232 /* Send back returned value to session daemon */
1233 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1234 sizeof(pending_reply
));
1236 PERROR("Failed to send rotation pending return code");
1241 case LTTNG_CONSUMER_MKDIR
:
1243 DBG("Consumer mkdir %s in session %" PRIu64
,
1245 msg
.u
.mkdir
.session_id
);
1246 ret
= lttng_consumer_mkdir(msg
.u
.mkdir
.path
,
1249 msg
.u
.mkdir
.relayd_id
);
1251 ERR("consumer mkdir failed");
1252 ret_code
= LTTCOMM_CONSUMERD_MKDIR_FAILED
;
1255 health_code_update();
1257 ret
= consumer_send_status_msg(sock
, ret_code
);
1259 /* Somehow, the session daemon is not responding anymore. */
1272 * Return 1 to indicate success since the 0 value can be a socket
1273 * shutdown during the recv() or send() call.
1275 health_code_update();
1280 /* This will issue a consumer stop. */
1285 * Populate index values of a kernel stream. Values are set in big endian order.
1287 * Return 0 on success or else a negative value.
1289 static int get_index_values(struct ctf_packet_index
*index
, int infd
)
1293 ret
= kernctl_get_timestamp_begin(infd
, &index
->timestamp_begin
);
1295 PERROR("kernctl_get_timestamp_begin");
1298 index
->timestamp_begin
= htobe64(index
->timestamp_begin
);
1300 ret
= kernctl_get_timestamp_end(infd
, &index
->timestamp_end
);
1302 PERROR("kernctl_get_timestamp_end");
1305 index
->timestamp_end
= htobe64(index
->timestamp_end
);
1307 ret
= kernctl_get_events_discarded(infd
, &index
->events_discarded
);
1309 PERROR("kernctl_get_events_discarded");
1312 index
->events_discarded
= htobe64(index
->events_discarded
);
1314 ret
= kernctl_get_content_size(infd
, &index
->content_size
);
1316 PERROR("kernctl_get_content_size");
1319 index
->content_size
= htobe64(index
->content_size
);
1321 ret
= kernctl_get_packet_size(infd
, &index
->packet_size
);
1323 PERROR("kernctl_get_packet_size");
1326 index
->packet_size
= htobe64(index
->packet_size
);
1328 ret
= kernctl_get_stream_id(infd
, &index
->stream_id
);
1330 PERROR("kernctl_get_stream_id");
1333 index
->stream_id
= htobe64(index
->stream_id
);
1335 ret
= kernctl_get_instance_id(infd
, &index
->stream_instance_id
);
1337 if (ret
== -ENOTTY
) {
1338 /* Command not implemented by lttng-modules. */
1339 index
->stream_instance_id
= -1ULL;
1341 PERROR("kernctl_get_instance_id");
1345 index
->stream_instance_id
= htobe64(index
->stream_instance_id
);
1347 ret
= kernctl_get_sequence_number(infd
, &index
->packet_seq_num
);
1349 if (ret
== -ENOTTY
) {
1350 /* Command not implemented by lttng-modules. */
1351 index
->packet_seq_num
= -1ULL;
1354 PERROR("kernctl_get_sequence_number");
1358 index
->packet_seq_num
= htobe64(index
->packet_seq_num
);
1364 * Sync metadata meaning request them to the session daemon and snapshot to the
1365 * metadata thread can consumer them.
1367 * Metadata stream lock MUST be acquired.
1369 * Return 0 if new metadatda is available, EAGAIN if the metadata stream
1370 * is empty or a negative value on error.
1372 int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream
*metadata
)
1378 ret
= kernctl_buffer_flush(metadata
->wait_fd
);
1380 ERR("Failed to flush kernel stream");
1384 ret
= kernctl_snapshot(metadata
->wait_fd
);
1386 if (ret
!= -EAGAIN
) {
1387 ERR("Sync metadata, taking kernel snapshot failed.");
1390 DBG("Sync metadata, no new kernel metadata");
1391 /* No new metadata, exit. */
1401 int update_stream_stats(struct lttng_consumer_stream
*stream
)
1404 uint64_t seq
, discarded
;
1406 ret
= kernctl_get_sequence_number(stream
->wait_fd
, &seq
);
1408 if (ret
== -ENOTTY
) {
1409 /* Command not implemented by lttng-modules. */
1412 PERROR("kernctl_get_sequence_number");
1418 * Start the sequence when we extract the first packet in case we don't
1419 * start at 0 (for example if a consumer is not connected to the
1420 * session immediately after the beginning).
1422 if (stream
->last_sequence_number
== -1ULL) {
1423 stream
->last_sequence_number
= seq
;
1424 } else if (seq
> stream
->last_sequence_number
) {
1425 stream
->chan
->lost_packets
+= seq
-
1426 stream
->last_sequence_number
- 1;
1428 /* seq <= last_sequence_number */
1429 ERR("Sequence number inconsistent : prev = %" PRIu64
1430 ", current = %" PRIu64
,
1431 stream
->last_sequence_number
, seq
);
1435 stream
->last_sequence_number
= seq
;
1437 ret
= kernctl_get_events_discarded(stream
->wait_fd
, &discarded
);
1439 PERROR("kernctl_get_events_discarded");
1442 if (discarded
< stream
->last_discarded_events
) {
1444 * Overflow has occurred. We assume only one wrap-around
1447 stream
->chan
->discarded_events
+= (1ULL << (CAA_BITS_PER_LONG
- 1)) -
1448 stream
->last_discarded_events
+ discarded
;
1450 stream
->chan
->discarded_events
+= discarded
-
1451 stream
->last_discarded_events
;
1453 stream
->last_discarded_events
= discarded
;
1461 * Check if the local version of the metadata stream matches with the version
1462 * of the metadata stream in the kernel. If it was updated, set the reset flag
1466 int metadata_stream_check_version(int infd
, struct lttng_consumer_stream
*stream
)
1469 uint64_t cur_version
;
1471 ret
= kernctl_get_metadata_version(infd
, &cur_version
);
1473 if (ret
== -ENOTTY
) {
1475 * LTTng-modules does not implement this
1481 ERR("Failed to get the metadata version");
1485 if (stream
->metadata_version
== cur_version
) {
1490 DBG("New metadata version detected");
1491 stream
->metadata_version
= cur_version
;
1492 stream
->reset_metadata_flag
= 1;
1500 * Consume data on a file descriptor and write it on a trace file.
1502 ssize_t
lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream
*stream
,
1503 struct lttng_consumer_local_data
*ctx
, bool *rotated
)
1505 unsigned long len
, subbuf_size
, padding
;
1506 int err
, write_index
= 1, rotation_ret
;
1508 int infd
= stream
->wait_fd
;
1509 struct ctf_packet_index index
;
1511 DBG("In read_subbuffer (infd : %d)", infd
);
1514 * If the stream was flagged to be ready for rotation before we extract the
1515 * next packet, rotate it now.
1517 if (stream
->rotate_ready
) {
1518 DBG("Rotate stream before extracting data");
1519 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1520 if (rotation_ret
< 0) {
1521 ERR("Stream rotation error");
1527 /* Get the next subbuffer */
1528 err
= kernctl_get_next_subbuf(infd
);
1531 * This is a debug message even for single-threaded consumer,
1532 * because poll() have more relaxed criterions than get subbuf,
1533 * so get_subbuf may fail for short race windows where poll()
1534 * would issue wakeups.
1536 DBG("Reserving sub buffer failed (everything is normal, "
1537 "it is due to concurrency)");
1542 /* Get the full subbuffer size including padding */
1543 err
= kernctl_get_padded_subbuf_size(infd
, &len
);
1545 PERROR("Getting sub-buffer len failed.");
1546 err
= kernctl_put_subbuf(infd
);
1548 if (err
== -EFAULT
) {
1549 PERROR("Error in unreserving sub buffer\n");
1550 } else if (err
== -EIO
) {
1551 /* Should never happen with newer LTTng versions */
1552 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1561 if (!stream
->metadata_flag
) {
1562 ret
= get_index_values(&index
, infd
);
1564 err
= kernctl_put_subbuf(infd
);
1566 if (err
== -EFAULT
) {
1567 PERROR("Error in unreserving sub buffer\n");
1568 } else if (err
== -EIO
) {
1569 /* Should never happen with newer LTTng versions */
1570 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1577 ret
= update_stream_stats(stream
);
1579 err
= kernctl_put_subbuf(infd
);
1581 if (err
== -EFAULT
) {
1582 PERROR("Error in unreserving sub buffer\n");
1583 } else if (err
== -EIO
) {
1584 /* Should never happen with newer LTTng versions */
1585 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1594 ret
= metadata_stream_check_version(infd
, stream
);
1596 err
= kernctl_put_subbuf(infd
);
1598 if (err
== -EFAULT
) {
1599 PERROR("Error in unreserving sub buffer\n");
1600 } else if (err
== -EIO
) {
1601 /* Should never happen with newer LTTng versions */
1602 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1611 switch (stream
->chan
->output
) {
1612 case CONSUMER_CHANNEL_SPLICE
:
1614 * XXX: The lttng-modules splice "actor" does not handle copying
1615 * partial pages hence only using the subbuffer size without the
1616 * padding makes the splice fail.
1621 /* splice the subbuffer to the tracefile */
1622 ret
= lttng_consumer_on_read_subbuffer_splice(ctx
, stream
, subbuf_size
,
1625 * XXX: Splice does not support network streaming so the return value
1626 * is simply checked against subbuf_size and not like the mmap() op.
1628 if (ret
!= subbuf_size
) {
1630 * display the error but continue processing to try
1631 * to release the subbuffer
1633 ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
1638 case CONSUMER_CHANNEL_MMAP
:
1639 /* Get subbuffer size without padding */
1640 err
= kernctl_get_subbuf_size(infd
, &subbuf_size
);
1642 PERROR("Getting sub-buffer len failed.");
1643 err
= kernctl_put_subbuf(infd
);
1645 if (err
== -EFAULT
) {
1646 PERROR("Error in unreserving sub buffer\n");
1647 } else if (err
== -EIO
) {
1648 /* Should never happen with newer LTTng versions */
1649 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1658 /* Make sure the tracer is not gone mad on us! */
1659 assert(len
>= subbuf_size
);
1661 padding
= len
- subbuf_size
;
1663 /* write the subbuffer to the tracefile */
1664 ret
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, subbuf_size
,
1667 * The mmap operation should write subbuf_size amount of data when
1668 * network streaming or the full padding (len) size when we are _not_
1671 if ((ret
!= subbuf_size
&& stream
->net_seq_idx
!= (uint64_t) -1ULL) ||
1672 (ret
!= len
&& stream
->net_seq_idx
== (uint64_t) -1ULL)) {
1674 * Display the error but continue processing to try to release the
1675 * subbuffer. This is a DBG statement since this is possible to
1676 * happen without being a critical error.
1678 DBG("Error writing to tracefile "
1679 "(ret: %zd != len: %lu != subbuf_size: %lu)",
1680 ret
, len
, subbuf_size
);
1685 ERR("Unknown output method");
1689 err
= kernctl_put_next_subbuf(infd
);
1691 if (err
== -EFAULT
) {
1692 PERROR("Error in unreserving sub buffer\n");
1693 } else if (err
== -EIO
) {
1694 /* Should never happen with newer LTTng versions */
1695 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1701 /* Write index if needed. */
1706 if (stream
->chan
->live_timer_interval
&& !stream
->metadata_flag
) {
1708 * In live, block until all the metadata is sent.
1710 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1711 assert(!stream
->missed_metadata_flush
);
1712 stream
->waiting_on_metadata
= true;
1713 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1715 err
= consumer_stream_sync_metadata(ctx
, stream
->session_id
);
1717 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1718 stream
->waiting_on_metadata
= false;
1719 if (stream
->missed_metadata_flush
) {
1720 stream
->missed_metadata_flush
= false;
1721 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1722 (void) consumer_flush_kernel_index(stream
);
1724 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1731 err
= consumer_stream_write_index(stream
, &index
);
1738 * After extracting the packet, we check if the stream is now ready to be
1739 * rotated and perform the action immediately.
1741 rotation_ret
= lttng_consumer_stream_is_rotate_ready(stream
);
1742 if (rotation_ret
== 1) {
1743 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1744 if (rotation_ret
< 0) {
1745 ERR("Stream rotation error");
1749 } else if (rotation_ret
< 0) {
1750 ERR("Checking if stream is ready to rotate");
1759 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream
*stream
)
1766 * Don't create anything if this is set for streaming or should not be
1769 if (stream
->net_seq_idx
== (uint64_t) -1ULL && stream
->chan
->monitor
) {
1770 ret
= utils_create_stream_file(stream
->chan
->pathname
, stream
->name
,
1771 stream
->chan
->tracefile_size
, stream
->tracefile_count_current
,
1772 stream
->uid
, stream
->gid
, NULL
);
1776 stream
->out_fd
= ret
;
1777 stream
->tracefile_size_current
= 0;
1779 if (!stream
->metadata_flag
) {
1780 struct lttng_index_file
*index_file
;
1782 index_file
= lttng_index_file_create(stream
->chan
->pathname
,
1783 stream
->name
, stream
->uid
, stream
->gid
,
1784 stream
->chan
->tracefile_size
,
1785 stream
->tracefile_count_current
,
1786 CTF_INDEX_MAJOR
, CTF_INDEX_MINOR
);
1790 assert(!stream
->index_file
);
1791 stream
->index_file
= index_file
;
1795 if (stream
->output
== LTTNG_EVENT_MMAP
) {
1796 /* get the len of the mmap region */
1797 unsigned long mmap_len
;
1799 ret
= kernctl_get_mmap_len(stream
->wait_fd
, &mmap_len
);
1801 PERROR("kernctl_get_mmap_len");
1802 goto error_close_fd
;
1804 stream
->mmap_len
= (size_t) mmap_len
;
1806 stream
->mmap_base
= mmap(NULL
, stream
->mmap_len
, PROT_READ
,
1807 MAP_PRIVATE
, stream
->wait_fd
, 0);
1808 if (stream
->mmap_base
== MAP_FAILED
) {
1809 PERROR("Error mmaping");
1811 goto error_close_fd
;
1815 /* we return 0 to let the library handle the FD internally */
1819 if (stream
->out_fd
>= 0) {
1822 err
= close(stream
->out_fd
);
1824 stream
->out_fd
= -1;
1831 * Check if data is still being extracted from the buffers for a specific
1832 * stream. Consumer data lock MUST be acquired before calling this function
1833 * and the stream lock.
1835 * Return 1 if the traced data are still getting read else 0 meaning that the
1836 * data is available for trace viewer reading.
1838 int lttng_kconsumer_data_pending(struct lttng_consumer_stream
*stream
)
1844 if (stream
->endpoint_status
!= CONSUMER_ENDPOINT_ACTIVE
) {
1849 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1851 /* There is still data so let's put back this subbuffer. */
1852 ret
= kernctl_put_subbuf(stream
->wait_fd
);
1854 ret
= 1; /* Data is pending */
1858 /* Data is NOT pending and ready to be read. */