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 int lttng_kconsumer_snapshot_channel(struct lttng_consumer_channel
*channel
,
133 uint64_t key
, char *path
, uint64_t relayd_id
, uint64_t nb_packets_per_stream
,
134 struct lttng_consumer_local_data
*ctx
)
137 struct lttng_consumer_stream
*stream
;
139 DBG("Kernel consumer snapshot channel %" PRIu64
, key
);
143 /* Splice is not supported yet for channel snapshot. */
144 if (channel
->output
!= CONSUMER_CHANNEL_MMAP
) {
145 ERR("Unsupported output %d", channel
->output
);
150 cds_list_for_each_entry(stream
, &channel
->streams
.head
, send_node
) {
151 unsigned long consumed_pos
, produced_pos
;
153 health_code_update();
156 * Lock stream because we are about to change its state.
158 pthread_mutex_lock(&stream
->lock
);
161 * Assign the received relayd ID so we can use it for streaming. The streams
162 * are not visible to anyone so this is OK to change it.
164 stream
->net_seq_idx
= relayd_id
;
165 channel
->relayd_id
= relayd_id
;
166 if (relayd_id
!= (uint64_t) -1ULL) {
167 ret
= consumer_send_relayd_stream(stream
, path
);
169 ERR("sending stream to relayd");
173 ret
= utils_create_stream_file(path
, stream
->name
,
174 stream
->chan
->tracefile_size
,
175 stream
->tracefile_count_current
,
176 stream
->uid
, stream
->gid
, NULL
);
178 ERR("utils_create_stream_file");
182 stream
->out_fd
= ret
;
183 stream
->tracefile_size_current
= 0;
185 DBG("Kernel consumer snapshot stream %s/%s (%" PRIu64
")",
186 path
, stream
->name
, stream
->key
);
189 ret
= kernctl_buffer_flush_empty(stream
->wait_fd
);
192 * Doing a buffer flush which does not take into
193 * account empty packets. This is not perfect
194 * for stream intersection, but required as a
195 * fall-back when "flush_empty" is not
196 * implemented by lttng-modules.
198 ret
= kernctl_buffer_flush(stream
->wait_fd
);
200 ERR("Failed to flush kernel stream");
206 ret
= lttng_kconsumer_take_snapshot(stream
);
208 ERR("Taking kernel snapshot");
212 ret
= lttng_kconsumer_get_produced_snapshot(stream
, &produced_pos
);
214 ERR("Produced kernel snapshot position");
218 ret
= lttng_kconsumer_get_consumed_snapshot(stream
, &consumed_pos
);
220 ERR("Consumerd kernel snapshot position");
224 if (stream
->max_sb_size
== 0) {
225 ret
= kernctl_get_max_subbuf_size(stream
->wait_fd
,
226 &stream
->max_sb_size
);
228 ERR("Getting kernel max_sb_size");
233 consumed_pos
= consumer_get_consume_start_pos(consumed_pos
,
234 produced_pos
, nb_packets_per_stream
,
235 stream
->max_sb_size
);
237 while (consumed_pos
< produced_pos
) {
239 unsigned long len
, padded_len
;
241 health_code_update();
243 DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos
);
245 ret
= kernctl_get_subbuf(stream
->wait_fd
, &consumed_pos
);
247 if (ret
!= -EAGAIN
) {
248 PERROR("kernctl_get_subbuf snapshot");
251 DBG("Kernel consumer get subbuf failed. Skipping it.");
252 consumed_pos
+= stream
->max_sb_size
;
253 stream
->chan
->lost_packets
++;
257 ret
= kernctl_get_subbuf_size(stream
->wait_fd
, &len
);
259 ERR("Snapshot kernctl_get_subbuf_size");
260 goto error_put_subbuf
;
263 ret
= kernctl_get_padded_subbuf_size(stream
->wait_fd
, &padded_len
);
265 ERR("Snapshot kernctl_get_padded_subbuf_size");
266 goto error_put_subbuf
;
269 read_len
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, len
,
270 padded_len
- len
, NULL
);
272 * We write the padded len in local tracefiles but the data len
273 * when using a relay. Display the error but continue processing
274 * to try to release the subbuffer.
276 if (relayd_id
!= (uint64_t) -1ULL) {
277 if (read_len
!= len
) {
278 ERR("Error sending to the relay (ret: %zd != len: %lu)",
282 if (read_len
!= padded_len
) {
283 ERR("Error writing to tracefile (ret: %zd != len: %lu)",
284 read_len
, padded_len
);
288 ret
= kernctl_put_subbuf(stream
->wait_fd
);
290 ERR("Snapshot kernctl_put_subbuf");
293 consumed_pos
+= stream
->max_sb_size
;
296 if (relayd_id
== (uint64_t) -1ULL) {
297 if (stream
->out_fd
>= 0) {
298 ret
= close(stream
->out_fd
);
300 PERROR("Kernel consumer snapshot close out_fd");
306 close_relayd_stream(stream
);
307 stream
->net_seq_idx
= (uint64_t) -1ULL;
309 pthread_mutex_unlock(&stream
->lock
);
317 ret
= kernctl_put_subbuf(stream
->wait_fd
);
319 ERR("Snapshot kernctl_put_subbuf error path");
322 pthread_mutex_unlock(&stream
->lock
);
329 * Read the whole metadata available for a snapshot.
330 * RCU read-side lock must be held across this function to ensure existence of
333 * Returns 0 on success, < 0 on error
335 static int lttng_kconsumer_snapshot_metadata(struct lttng_consumer_channel
*metadata_channel
,
336 uint64_t key
, char *path
, uint64_t relayd_id
,
337 struct lttng_consumer_local_data
*ctx
)
339 int ret
, use_relayd
= 0;
341 struct lttng_consumer_stream
*metadata_stream
;
345 DBG("Kernel consumer snapshot metadata with key %" PRIu64
" at path %s",
350 metadata_stream
= metadata_channel
->metadata_stream
;
351 assert(metadata_stream
);
352 pthread_mutex_lock(&metadata_stream
->lock
);
354 /* Flag once that we have a valid relayd for the stream. */
355 if (relayd_id
!= (uint64_t) -1ULL) {
360 ret
= consumer_send_relayd_stream(metadata_stream
, path
);
365 ret
= utils_create_stream_file(path
, metadata_stream
->name
,
366 metadata_stream
->chan
->tracefile_size
,
367 metadata_stream
->tracefile_count_current
,
368 metadata_stream
->uid
, metadata_stream
->gid
, NULL
);
372 metadata_stream
->out_fd
= ret
;
376 health_code_update();
378 ret_read
= lttng_kconsumer_read_subbuffer(metadata_stream
, ctx
, NULL
);
380 if (ret_read
!= -EAGAIN
) {
381 ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
386 /* ret_read is negative at this point so we will exit the loop. */
389 } while (ret_read
>= 0);
392 close_relayd_stream(metadata_stream
);
393 metadata_stream
->net_seq_idx
= (uint64_t) -1ULL;
395 if (metadata_stream
->out_fd
>= 0) {
396 ret
= close(metadata_stream
->out_fd
);
398 PERROR("Kernel consumer snapshot metadata close out_fd");
400 * Don't go on error here since the snapshot was successful at this
401 * point but somehow the close failed.
404 metadata_stream
->out_fd
= -1;
410 pthread_mutex_unlock(&metadata_stream
->lock
);
411 cds_list_del(&metadata_stream
->send_node
);
412 consumer_stream_destroy(metadata_stream
, NULL
);
413 metadata_channel
->metadata_stream
= NULL
;
419 * Receive command from session daemon and process it.
421 * Return 1 on success else a negative value or 0.
423 int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data
*ctx
,
424 int sock
, struct pollfd
*consumer_sockpoll
)
427 enum lttcomm_return_code ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
428 struct lttcomm_consumer_msg msg
;
430 health_code_update();
432 ret
= lttcomm_recv_unix_sock(sock
, &msg
, sizeof(msg
));
433 if (ret
!= sizeof(msg
)) {
435 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_CMD
);
441 health_code_update();
443 /* Deprecated command */
444 assert(msg
.cmd_type
!= LTTNG_CONSUMER_STOP
);
446 health_code_update();
448 /* relayd needs RCU read-side protection */
451 switch (msg
.cmd_type
) {
452 case LTTNG_CONSUMER_ADD_RELAYD_SOCKET
:
454 /* Session daemon status message are handled in the following call. */
455 consumer_add_relayd_socket(msg
.u
.relayd_sock
.net_index
,
456 msg
.u
.relayd_sock
.type
, ctx
, sock
, consumer_sockpoll
,
457 &msg
.u
.relayd_sock
.sock
, msg
.u
.relayd_sock
.session_id
,
458 msg
.u
.relayd_sock
.relayd_session_id
);
461 case LTTNG_CONSUMER_ADD_CHANNEL
:
463 struct lttng_consumer_channel
*new_channel
;
466 health_code_update();
468 /* First send a status message before receiving the fds. */
469 ret
= consumer_send_status_msg(sock
, ret_code
);
471 /* Somehow, the session daemon is not responding anymore. */
475 health_code_update();
477 DBG("consumer_add_channel %" PRIu64
, msg
.u
.channel
.channel_key
);
478 new_channel
= consumer_allocate_channel(msg
.u
.channel
.channel_key
,
479 msg
.u
.channel
.session_id
, msg
.u
.channel
.pathname
,
480 msg
.u
.channel
.name
, msg
.u
.channel
.uid
, msg
.u
.channel
.gid
,
481 msg
.u
.channel
.relayd_id
, msg
.u
.channel
.output
,
482 msg
.u
.channel
.tracefile_size
,
483 msg
.u
.channel
.tracefile_count
, 0,
484 msg
.u
.channel
.monitor
,
485 msg
.u
.channel
.live_timer_interval
,
487 if (new_channel
== NULL
) {
488 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
491 new_channel
->nb_init_stream_left
= msg
.u
.channel
.nb_init_streams
;
492 switch (msg
.u
.channel
.output
) {
493 case LTTNG_EVENT_SPLICE
:
494 new_channel
->output
= CONSUMER_CHANNEL_SPLICE
;
496 case LTTNG_EVENT_MMAP
:
497 new_channel
->output
= CONSUMER_CHANNEL_MMAP
;
500 ERR("Channel output unknown %d", msg
.u
.channel
.output
);
504 /* Translate and save channel type. */
505 switch (msg
.u
.channel
.type
) {
506 case CONSUMER_CHANNEL_TYPE_DATA
:
507 case CONSUMER_CHANNEL_TYPE_METADATA
:
508 new_channel
->type
= msg
.u
.channel
.type
;
515 health_code_update();
517 if (ctx
->on_recv_channel
!= NULL
) {
518 ret_recv
= ctx
->on_recv_channel(new_channel
);
520 ret
= consumer_add_channel(new_channel
, ctx
);
521 } else if (ret_recv
< 0) {
525 ret
= consumer_add_channel(new_channel
, ctx
);
527 if (msg
.u
.channel
.type
== CONSUMER_CHANNEL_TYPE_DATA
&& !ret
) {
528 int monitor_start_ret
;
530 DBG("Consumer starting monitor timer");
531 consumer_timer_live_start(new_channel
,
532 msg
.u
.channel
.live_timer_interval
);
533 monitor_start_ret
= consumer_timer_monitor_start(
535 msg
.u
.channel
.monitor_timer_interval
);
536 if (monitor_start_ret
< 0) {
537 ERR("Starting channel monitoring timer failed");
543 health_code_update();
545 /* If we received an error in add_channel, we need to report it. */
547 ret
= consumer_send_status_msg(sock
, ret
);
556 case LTTNG_CONSUMER_ADD_STREAM
:
559 struct lttng_pipe
*stream_pipe
;
560 struct lttng_consumer_stream
*new_stream
;
561 struct lttng_consumer_channel
*channel
;
565 * Get stream's channel reference. Needed when adding the stream to the
568 channel
= consumer_find_channel(msg
.u
.stream
.channel_key
);
571 * We could not find the channel. Can happen if cpu hotplug
572 * happens while tearing down.
574 ERR("Unable to find channel key %" PRIu64
, msg
.u
.stream
.channel_key
);
575 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
578 health_code_update();
580 /* First send a status message before receiving the fds. */
581 ret
= consumer_send_status_msg(sock
, ret_code
);
583 /* Somehow, the session daemon is not responding anymore. */
587 health_code_update();
589 if (ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
590 /* Channel was not found. */
596 ret
= lttng_consumer_poll_socket(consumer_sockpoll
);
602 health_code_update();
604 /* Get stream file descriptor from socket */
605 ret
= lttcomm_recv_fds_unix_sock(sock
, &fd
, 1);
606 if (ret
!= sizeof(fd
)) {
607 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_ERROR_RECV_FD
);
612 health_code_update();
615 * Send status code to session daemon only if the recv works. If the
616 * above recv() failed, the session daemon is notified through the
617 * error socket and the teardown is eventually done.
619 ret
= consumer_send_status_msg(sock
, ret_code
);
621 /* Somehow, the session daemon is not responding anymore. */
625 health_code_update();
627 new_stream
= consumer_allocate_stream(channel
->key
,
629 LTTNG_CONSUMER_ACTIVE_STREAM
,
639 msg
.u
.stream
.trace_archive_id
);
640 if (new_stream
== NULL
) {
645 lttng_consumer_send_error(ctx
, LTTCOMM_CONSUMERD_OUTFD_ERROR
);
651 new_stream
->chan
= channel
;
652 new_stream
->wait_fd
= fd
;
653 consumer_stream_update_channel_attributes(new_stream
,
655 switch (channel
->output
) {
656 case CONSUMER_CHANNEL_SPLICE
:
657 new_stream
->output
= LTTNG_EVENT_SPLICE
;
658 ret
= utils_create_pipe(new_stream
->splice_pipe
);
663 case CONSUMER_CHANNEL_MMAP
:
664 new_stream
->output
= LTTNG_EVENT_MMAP
;
667 ERR("Stream output unknown %d", channel
->output
);
672 * We've just assigned the channel to the stream so increment the
673 * refcount right now. We don't need to increment the refcount for
674 * streams in no monitor because we handle manually the cleanup of
675 * those. It is very important to make sure there is NO prior
676 * consumer_del_stream() calls or else the refcount will be unbalanced.
678 if (channel
->monitor
) {
679 uatomic_inc(&new_stream
->chan
->refcount
);
683 * The buffer flush is done on the session daemon side for the kernel
684 * so no need for the stream "hangup_flush_done" variable to be
685 * tracked. This is important for a kernel stream since we don't rely
686 * on the flush state of the stream to read data. It's not the case for
687 * user space tracing.
689 new_stream
->hangup_flush_done
= 0;
691 health_code_update();
693 if (ctx
->on_recv_stream
) {
694 ret
= ctx
->on_recv_stream(new_stream
);
696 consumer_stream_free(new_stream
);
701 health_code_update();
703 if (new_stream
->metadata_flag
) {
704 channel
->metadata_stream
= new_stream
;
707 /* Do not monitor this stream. */
708 if (!channel
->monitor
) {
709 DBG("Kernel consumer add stream %s in no monitor mode with "
710 "relayd id %" PRIu64
, new_stream
->name
,
711 new_stream
->net_seq_idx
);
712 cds_list_add(&new_stream
->send_node
, &channel
->streams
.head
);
716 /* Send stream to relayd if the stream has an ID. */
717 if (new_stream
->net_seq_idx
!= (uint64_t) -1ULL) {
718 ret
= consumer_send_relayd_stream(new_stream
,
719 new_stream
->chan
->pathname
);
721 consumer_stream_free(new_stream
);
726 * If adding an extra stream to an already
727 * existing channel (e.g. cpu hotplug), we need
728 * to send the "streams_sent" command to relayd.
730 if (channel
->streams_sent_to_relayd
) {
731 ret
= consumer_send_relayd_streams_sent(
732 new_stream
->net_seq_idx
);
739 /* Get the right pipe where the stream will be sent. */
740 if (new_stream
->metadata_flag
) {
741 consumer_add_metadata_stream(new_stream
);
742 stream_pipe
= ctx
->consumer_metadata_pipe
;
744 consumer_add_data_stream(new_stream
);
745 stream_pipe
= ctx
->consumer_data_pipe
;
748 /* Visible to other threads */
749 new_stream
->globally_visible
= 1;
751 health_code_update();
753 ret
= lttng_pipe_write(stream_pipe
, &new_stream
, sizeof(new_stream
));
755 ERR("Consumer write %s stream to pipe %d",
756 new_stream
->metadata_flag
? "metadata" : "data",
757 lttng_pipe_get_writefd(stream_pipe
));
758 if (new_stream
->metadata_flag
) {
759 consumer_del_stream_for_metadata(new_stream
);
761 consumer_del_stream_for_data(new_stream
);
766 DBG("Kernel consumer ADD_STREAM %s (fd: %d) %s with relayd id %" PRIu64
,
767 new_stream
->name
, fd
, new_stream
->chan
->pathname
, new_stream
->relayd_stream_id
);
770 case LTTNG_CONSUMER_STREAMS_SENT
:
772 struct lttng_consumer_channel
*channel
;
775 * Get stream's channel reference. Needed when adding the stream to the
778 channel
= consumer_find_channel(msg
.u
.sent_streams
.channel_key
);
781 * We could not find the channel. Can happen if cpu hotplug
782 * happens while tearing down.
784 ERR("Unable to find channel key %" PRIu64
,
785 msg
.u
.sent_streams
.channel_key
);
786 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
789 health_code_update();
792 * Send status code to session daemon.
794 ret
= consumer_send_status_msg(sock
, ret_code
);
795 if (ret
< 0 || ret_code
!= LTTCOMM_CONSUMERD_SUCCESS
) {
796 /* Somehow, the session daemon is not responding anymore. */
800 health_code_update();
803 * We should not send this message if we don't monitor the
804 * streams in this channel.
806 if (!channel
->monitor
) {
810 health_code_update();
811 /* Send stream to relayd if the stream has an ID. */
812 if (msg
.u
.sent_streams
.net_seq_idx
!= (uint64_t) -1ULL) {
813 ret
= consumer_send_relayd_streams_sent(
814 msg
.u
.sent_streams
.net_seq_idx
);
818 channel
->streams_sent_to_relayd
= true;
822 case LTTNG_CONSUMER_UPDATE_STREAM
:
827 case LTTNG_CONSUMER_DESTROY_RELAYD
:
829 uint64_t index
= msg
.u
.destroy_relayd
.net_seq_idx
;
830 struct consumer_relayd_sock_pair
*relayd
;
832 DBG("Kernel consumer destroying relayd %" PRIu64
, index
);
834 /* Get relayd reference if exists. */
835 relayd
= consumer_find_relayd(index
);
836 if (relayd
== NULL
) {
837 DBG("Unable to find relayd %" PRIu64
, index
);
838 ret_code
= LTTCOMM_CONSUMERD_RELAYD_FAIL
;
842 * Each relayd socket pair has a refcount of stream attached to it
843 * which tells if the relayd is still active or not depending on the
846 * This will set the destroy flag of the relayd object and destroy it
847 * if the refcount reaches zero when called.
849 * The destroy can happen either here or when a stream fd hangs up.
852 consumer_flag_relayd_for_destroy(relayd
);
855 health_code_update();
857 ret
= consumer_send_status_msg(sock
, ret_code
);
859 /* Somehow, the session daemon is not responding anymore. */
865 case LTTNG_CONSUMER_DATA_PENDING
:
868 uint64_t id
= msg
.u
.data_pending
.session_id
;
870 DBG("Kernel consumer data pending command for id %" PRIu64
, id
);
872 ret
= consumer_data_pending(id
);
874 health_code_update();
876 /* Send back returned value to session daemon */
877 ret
= lttcomm_send_unix_sock(sock
, &ret
, sizeof(ret
));
879 PERROR("send data pending ret code");
884 * No need to send back a status message since the data pending
885 * returned value is the response.
889 case LTTNG_CONSUMER_SNAPSHOT_CHANNEL
:
891 struct lttng_consumer_channel
*channel
;
892 uint64_t key
= msg
.u
.snapshot_channel
.key
;
894 channel
= consumer_find_channel(key
);
896 ERR("Channel %" PRIu64
" not found", key
);
897 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
899 if (msg
.u
.snapshot_channel
.metadata
== 1) {
900 ret
= lttng_kconsumer_snapshot_metadata(channel
, key
,
901 msg
.u
.snapshot_channel
.pathname
,
902 msg
.u
.snapshot_channel
.relayd_id
, ctx
);
904 ERR("Snapshot metadata failed");
905 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
908 ret
= lttng_kconsumer_snapshot_channel(channel
, key
,
909 msg
.u
.snapshot_channel
.pathname
,
910 msg
.u
.snapshot_channel
.relayd_id
,
911 msg
.u
.snapshot_channel
.nb_packets_per_stream
,
914 ERR("Snapshot channel failed");
915 ret_code
= LTTCOMM_CONSUMERD_SNAPSHOT_FAILED
;
919 health_code_update();
921 ret
= consumer_send_status_msg(sock
, ret_code
);
923 /* Somehow, the session daemon is not responding anymore. */
928 case LTTNG_CONSUMER_DESTROY_CHANNEL
:
930 uint64_t key
= msg
.u
.destroy_channel
.key
;
931 struct lttng_consumer_channel
*channel
;
933 channel
= consumer_find_channel(key
);
935 ERR("Kernel consumer destroy channel %" PRIu64
" not found", key
);
936 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
939 health_code_update();
941 ret
= consumer_send_status_msg(sock
, ret_code
);
943 /* Somehow, the session daemon is not responding anymore. */
947 health_code_update();
949 /* Stop right now if no channel was found. */
955 * This command should ONLY be issued for channel with streams set in
958 assert(!channel
->monitor
);
961 * The refcount should ALWAYS be 0 in the case of a channel in no
964 assert(!uatomic_sub_return(&channel
->refcount
, 1));
966 consumer_del_channel(channel
);
970 case LTTNG_CONSUMER_DISCARDED_EVENTS
:
974 struct lttng_consumer_channel
*channel
;
975 uint64_t id
= msg
.u
.discarded_events
.session_id
;
976 uint64_t key
= msg
.u
.discarded_events
.channel_key
;
978 DBG("Kernel consumer discarded events command for session id %"
979 PRIu64
", channel key %" PRIu64
, id
, key
);
981 channel
= consumer_find_channel(key
);
983 ERR("Kernel consumer discarded events channel %"
984 PRIu64
" not found", key
);
987 count
= channel
->discarded_events
;
990 health_code_update();
992 /* Send back returned value to session daemon */
993 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
995 PERROR("send discarded events");
1001 case LTTNG_CONSUMER_LOST_PACKETS
:
1005 struct lttng_consumer_channel
*channel
;
1006 uint64_t id
= msg
.u
.lost_packets
.session_id
;
1007 uint64_t key
= msg
.u
.lost_packets
.channel_key
;
1009 DBG("Kernel consumer lost packets command for session id %"
1010 PRIu64
", channel key %" PRIu64
, id
, key
);
1012 channel
= consumer_find_channel(key
);
1014 ERR("Kernel consumer lost packets channel %"
1015 PRIu64
" not found", key
);
1018 count
= channel
->lost_packets
;
1021 health_code_update();
1023 /* Send back returned value to session daemon */
1024 ret
= lttcomm_send_unix_sock(sock
, &count
, sizeof(count
));
1026 PERROR("send lost packets");
1032 case LTTNG_CONSUMER_SET_CHANNEL_MONITOR_PIPE
:
1034 int channel_monitor_pipe
;
1036 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1037 /* Successfully received the command's type. */
1038 ret
= consumer_send_status_msg(sock
, ret_code
);
1043 ret
= lttcomm_recv_fds_unix_sock(sock
, &channel_monitor_pipe
,
1045 if (ret
!= sizeof(channel_monitor_pipe
)) {
1046 ERR("Failed to receive channel monitor pipe");
1050 DBG("Received channel monitor pipe (%d)", channel_monitor_pipe
);
1051 ret
= consumer_timer_thread_set_channel_monitor_pipe(
1052 channel_monitor_pipe
);
1056 ret_code
= LTTCOMM_CONSUMERD_SUCCESS
;
1057 /* Set the pipe as non-blocking. */
1058 ret
= fcntl(channel_monitor_pipe
, F_GETFL
, 0);
1060 PERROR("fcntl get flags of the channel monitoring pipe");
1065 ret
= fcntl(channel_monitor_pipe
, F_SETFL
,
1066 flags
| O_NONBLOCK
);
1068 PERROR("fcntl set O_NONBLOCK flag of the channel monitoring pipe");
1071 DBG("Channel monitor pipe set as non-blocking");
1073 ret_code
= LTTCOMM_CONSUMERD_ALREADY_SET
;
1075 ret
= consumer_send_status_msg(sock
, ret_code
);
1081 case LTTNG_CONSUMER_ROTATE_CHANNEL
:
1083 struct lttng_consumer_channel
*channel
;
1084 uint64_t key
= msg
.u
.rotate_channel
.key
;
1086 DBG("Consumer rotate channel %" PRIu64
, key
);
1088 channel
= consumer_find_channel(key
);
1090 ERR("Channel %" PRIu64
" not found", key
);
1091 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1094 * Sample the rotate position of all the streams in this channel.
1096 ret
= lttng_consumer_rotate_sample_channel(channel
, key
,
1097 msg
.u
.rotate_channel
.pathname
,
1098 msg
.u
.rotate_channel
.relayd_id
,
1099 msg
.u
.rotate_channel
.metadata
,
1100 msg
.u
.rotate_channel
.new_chunk_id
,
1103 ERR("Rotate channel failed");
1104 ret_code
= LTTCOMM_CONSUMERD_ROTATION_FAIL
;
1107 health_code_update();
1109 ret
= consumer_send_status_msg(sock
, ret_code
);
1111 /* Somehow, the session daemon is not responding anymore. */
1115 /* Rotate the streams that are ready right now. */
1116 ret
= lttng_consumer_rotate_ready_streams(
1119 ERR("Rotate ready streams failed");
1125 case LTTNG_CONSUMER_ROTATE_RENAME
:
1127 DBG("Consumer rename session %" PRIu64
" after rotation, old path = \"%s\", new path = \"%s\"",
1128 msg
.u
.rotate_rename
.session_id
,
1129 msg
.u
.rotate_rename
.old_path
,
1130 msg
.u
.rotate_rename
.new_path
);
1131 ret
= lttng_consumer_rotate_rename(msg
.u
.rotate_rename
.old_path
,
1132 msg
.u
.rotate_rename
.new_path
,
1133 msg
.u
.rotate_rename
.uid
,
1134 msg
.u
.rotate_rename
.gid
,
1135 msg
.u
.rotate_rename
.relayd_id
);
1137 ERR("Rotate rename failed");
1138 ret_code
= LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED
;
1141 health_code_update();
1143 ret
= consumer_send_status_msg(sock
, ret_code
);
1145 /* Somehow, the session daemon is not responding anymore. */
1150 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_LOCAL
:
1153 uint32_t pending_reply
;
1155 DBG("Perform local check of pending rotation for session id %" PRIu64
,
1156 msg
.u
.check_rotation_pending_local
.session_id
);
1157 pending
= lttng_consumer_check_rotation_pending_local(
1158 msg
.u
.check_rotation_pending_local
.session_id
,
1159 msg
.u
.check_rotation_pending_local
.chunk_id
);
1161 ERR("Local rotation pending check failed with code %i", pending
);
1162 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED
;
1164 pending_reply
= !!pending
;
1167 health_code_update();
1169 ret
= consumer_send_status_msg(sock
, ret_code
);
1171 /* Somehow, the session daemon is not responding anymore. */
1177 * An error occurred while running the command;
1178 * don't send the 'pending' flag as the sessiond
1184 /* Send back returned value to session daemon */
1185 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1186 sizeof(pending_reply
));
1188 PERROR("Failed to send rotation pending return code");
1193 case LTTNG_CONSUMER_CHECK_ROTATION_PENDING_RELAY
:
1196 uint32_t pending_reply
;
1198 DBG("Perform relayd check of pending rotation for session id %" PRIu64
,
1199 msg
.u
.check_rotation_pending_relay
.session_id
);
1200 pending
= lttng_consumer_check_rotation_pending_relay(
1201 msg
.u
.check_rotation_pending_relay
.session_id
,
1202 msg
.u
.check_rotation_pending_relay
.relayd_id
,
1203 msg
.u
.check_rotation_pending_relay
.chunk_id
);
1205 ERR("Relayd rotation pending check failed with code %i", pending
);
1206 ret_code
= LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED
;
1208 pending_reply
= !!pending
;
1211 health_code_update();
1213 ret
= consumer_send_status_msg(sock
, ret_code
);
1215 /* Somehow, the session daemon is not responding anymore. */
1221 * An error occurred while running the command;
1222 * don't send the 'pending' flag as the sessiond
1228 /* Send back returned value to session daemon */
1229 ret
= lttcomm_send_unix_sock(sock
, &pending_reply
,
1230 sizeof(pending_reply
));
1232 PERROR("Failed to send rotation pending return code");
1237 case LTTNG_CONSUMER_MKDIR
:
1239 DBG("Consumer mkdir %s in session %" PRIu64
,
1241 msg
.u
.mkdir
.session_id
);
1242 ret
= lttng_consumer_mkdir(msg
.u
.mkdir
.path
,
1245 msg
.u
.mkdir
.relayd_id
);
1247 ERR("consumer mkdir failed");
1248 ret_code
= LTTCOMM_CONSUMERD_MKDIR_FAILED
;
1251 health_code_update();
1253 ret
= consumer_send_status_msg(sock
, ret_code
);
1255 /* Somehow, the session daemon is not responding anymore. */
1260 case LTTNG_CONSUMER_CLEAR_CHANNEL
:
1262 struct lttng_consumer_channel
*channel
;
1263 uint64_t key
= msg
.u
.clear_channel
.key
;
1265 channel
= consumer_find_channel(key
);
1267 DBG("Channel %" PRIu64
" not found", key
);
1268 ret_code
= LTTCOMM_CONSUMERD_CHAN_NOT_FOUND
;
1270 ret
= lttng_consumer_clear_channel(channel
);
1272 ERR("Clear channel failed");
1276 health_code_update();
1278 ret
= consumer_send_status_msg(sock
, ret_code
);
1280 /* Somehow, the session daemon is not responding anymore. */
1293 * Return 1 to indicate success since the 0 value can be a socket
1294 * shutdown during the recv() or send() call.
1296 health_code_update();
1301 /* This will issue a consumer stop. */
1306 * Populate index values of a kernel stream. Values are set in big endian order.
1308 * Return 0 on success or else a negative value.
1310 static int get_index_values(struct ctf_packet_index
*index
, int infd
)
1314 ret
= kernctl_get_timestamp_begin(infd
, &index
->timestamp_begin
);
1316 PERROR("kernctl_get_timestamp_begin");
1319 index
->timestamp_begin
= htobe64(index
->timestamp_begin
);
1321 ret
= kernctl_get_timestamp_end(infd
, &index
->timestamp_end
);
1323 PERROR("kernctl_get_timestamp_end");
1326 index
->timestamp_end
= htobe64(index
->timestamp_end
);
1328 ret
= kernctl_get_events_discarded(infd
, &index
->events_discarded
);
1330 PERROR("kernctl_get_events_discarded");
1333 index
->events_discarded
= htobe64(index
->events_discarded
);
1335 ret
= kernctl_get_content_size(infd
, &index
->content_size
);
1337 PERROR("kernctl_get_content_size");
1340 index
->content_size
= htobe64(index
->content_size
);
1342 ret
= kernctl_get_packet_size(infd
, &index
->packet_size
);
1344 PERROR("kernctl_get_packet_size");
1347 index
->packet_size
= htobe64(index
->packet_size
);
1349 ret
= kernctl_get_stream_id(infd
, &index
->stream_id
);
1351 PERROR("kernctl_get_stream_id");
1354 index
->stream_id
= htobe64(index
->stream_id
);
1356 ret
= kernctl_get_instance_id(infd
, &index
->stream_instance_id
);
1358 if (ret
== -ENOTTY
) {
1359 /* Command not implemented by lttng-modules. */
1360 index
->stream_instance_id
= -1ULL;
1362 PERROR("kernctl_get_instance_id");
1366 index
->stream_instance_id
= htobe64(index
->stream_instance_id
);
1368 ret
= kernctl_get_sequence_number(infd
, &index
->packet_seq_num
);
1370 if (ret
== -ENOTTY
) {
1371 /* Command not implemented by lttng-modules. */
1372 index
->packet_seq_num
= -1ULL;
1375 PERROR("kernctl_get_sequence_number");
1379 index
->packet_seq_num
= htobe64(index
->packet_seq_num
);
1385 * Sync metadata meaning request them to the session daemon and snapshot to the
1386 * metadata thread can consumer them.
1388 * Metadata stream lock MUST be acquired.
1390 * Return 0 if new metadatda is available, EAGAIN if the metadata stream
1391 * is empty or a negative value on error.
1393 int lttng_kconsumer_sync_metadata(struct lttng_consumer_stream
*metadata
)
1399 ret
= kernctl_buffer_flush(metadata
->wait_fd
);
1401 ERR("Failed to flush kernel stream");
1405 ret
= kernctl_snapshot(metadata
->wait_fd
);
1407 if (ret
!= -EAGAIN
) {
1408 ERR("Sync metadata, taking kernel snapshot failed.");
1411 DBG("Sync metadata, no new kernel metadata");
1412 /* No new metadata, exit. */
1422 int update_stream_stats(struct lttng_consumer_stream
*stream
)
1425 uint64_t seq
, discarded
;
1427 ret
= kernctl_get_sequence_number(stream
->wait_fd
, &seq
);
1429 if (ret
== -ENOTTY
) {
1430 /* Command not implemented by lttng-modules. */
1433 PERROR("kernctl_get_sequence_number");
1439 * Start the sequence when we extract the first packet in case we don't
1440 * start at 0 (for example if a consumer is not connected to the
1441 * session immediately after the beginning).
1443 if (stream
->last_sequence_number
== -1ULL) {
1444 stream
->last_sequence_number
= seq
;
1445 } else if (seq
> stream
->last_sequence_number
) {
1446 stream
->chan
->lost_packets
+= seq
-
1447 stream
->last_sequence_number
- 1;
1449 /* seq <= last_sequence_number */
1450 ERR("Sequence number inconsistent : prev = %" PRIu64
1451 ", current = %" PRIu64
,
1452 stream
->last_sequence_number
, seq
);
1456 stream
->last_sequence_number
= seq
;
1458 ret
= kernctl_get_events_discarded(stream
->wait_fd
, &discarded
);
1460 PERROR("kernctl_get_events_discarded");
1463 if (discarded
< stream
->last_discarded_events
) {
1465 * Overflow has occurred. We assume only one wrap-around
1468 stream
->chan
->discarded_events
+= (1ULL << (CAA_BITS_PER_LONG
- 1)) -
1469 stream
->last_discarded_events
+ discarded
;
1471 stream
->chan
->discarded_events
+= discarded
-
1472 stream
->last_discarded_events
;
1474 stream
->last_discarded_events
= discarded
;
1482 * Check if the local version of the metadata stream matches with the version
1483 * of the metadata stream in the kernel. If it was updated, set the reset flag
1487 int metadata_stream_check_version(int infd
, struct lttng_consumer_stream
*stream
)
1490 uint64_t cur_version
;
1492 ret
= kernctl_get_metadata_version(infd
, &cur_version
);
1494 if (ret
== -ENOTTY
) {
1496 * LTTng-modules does not implement this
1502 ERR("Failed to get the metadata version");
1506 if (stream
->metadata_version
== cur_version
) {
1511 DBG("New metadata version detected");
1512 stream
->metadata_version
= cur_version
;
1513 stream
->reset_metadata_flag
= 1;
1521 * Consume data on a file descriptor and write it on a trace file.
1523 ssize_t
lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream
*stream
,
1524 struct lttng_consumer_local_data
*ctx
, bool *rotated
)
1526 unsigned long len
, subbuf_size
, padding
;
1527 int err
, write_index
= 1, rotation_ret
;
1529 int infd
= stream
->wait_fd
;
1530 struct ctf_packet_index index
;
1532 DBG("In read_subbuffer (infd : %d)", infd
);
1535 * If the stream was flagged to be ready for rotation before we extract the
1536 * next packet, rotate it now.
1538 if (stream
->rotate_ready
) {
1539 DBG("Rotate stream before extracting data");
1540 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1541 if (rotation_ret
< 0) {
1542 ERR("Stream rotation error");
1548 /* Get the next subbuffer */
1549 err
= kernctl_get_next_subbuf(infd
);
1552 * This is a debug message even for single-threaded consumer,
1553 * because poll() have more relaxed criterions than get subbuf,
1554 * so get_subbuf may fail for short race windows where poll()
1555 * would issue wakeups.
1557 DBG("Reserving sub buffer failed (everything is normal, "
1558 "it is due to concurrency)");
1563 /* Get the full subbuffer size including padding */
1564 err
= kernctl_get_padded_subbuf_size(infd
, &len
);
1566 PERROR("Getting sub-buffer len failed.");
1567 err
= kernctl_put_subbuf(infd
);
1569 if (err
== -EFAULT
) {
1570 PERROR("Error in unreserving sub buffer\n");
1571 } else if (err
== -EIO
) {
1572 /* Should never happen with newer LTTng versions */
1573 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1582 if (!stream
->metadata_flag
) {
1583 ret
= get_index_values(&index
, infd
);
1585 err
= kernctl_put_subbuf(infd
);
1587 if (err
== -EFAULT
) {
1588 PERROR("Error in unreserving sub buffer\n");
1589 } else if (err
== -EIO
) {
1590 /* Should never happen with newer LTTng versions */
1591 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1598 ret
= update_stream_stats(stream
);
1600 err
= kernctl_put_subbuf(infd
);
1602 if (err
== -EFAULT
) {
1603 PERROR("Error in unreserving sub buffer\n");
1604 } else if (err
== -EIO
) {
1605 /* Should never happen with newer LTTng versions */
1606 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1615 ret
= metadata_stream_check_version(infd
, stream
);
1617 err
= kernctl_put_subbuf(infd
);
1619 if (err
== -EFAULT
) {
1620 PERROR("Error in unreserving sub buffer\n");
1621 } else if (err
== -EIO
) {
1622 /* Should never happen with newer LTTng versions */
1623 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1632 switch (stream
->chan
->output
) {
1633 case CONSUMER_CHANNEL_SPLICE
:
1635 * XXX: The lttng-modules splice "actor" does not handle copying
1636 * partial pages hence only using the subbuffer size without the
1637 * padding makes the splice fail.
1642 /* splice the subbuffer to the tracefile */
1643 ret
= lttng_consumer_on_read_subbuffer_splice(ctx
, stream
, subbuf_size
,
1646 * XXX: Splice does not support network streaming so the return value
1647 * is simply checked against subbuf_size and not like the mmap() op.
1649 if (ret
!= subbuf_size
) {
1651 * display the error but continue processing to try
1652 * to release the subbuffer
1654 ERR("Error splicing to tracefile (ret: %zd != len: %lu)",
1659 case CONSUMER_CHANNEL_MMAP
:
1660 /* Get subbuffer size without padding */
1661 err
= kernctl_get_subbuf_size(infd
, &subbuf_size
);
1663 PERROR("Getting sub-buffer len failed.");
1664 err
= kernctl_put_subbuf(infd
);
1666 if (err
== -EFAULT
) {
1667 PERROR("Error in unreserving sub buffer\n");
1668 } else if (err
== -EIO
) {
1669 /* Should never happen with newer LTTng versions */
1670 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1679 /* Make sure the tracer is not gone mad on us! */
1680 assert(len
>= subbuf_size
);
1682 padding
= len
- subbuf_size
;
1684 /* write the subbuffer to the tracefile */
1685 ret
= lttng_consumer_on_read_subbuffer_mmap(ctx
, stream
, subbuf_size
,
1688 * The mmap operation should write subbuf_size amount of data when
1689 * network streaming or the full padding (len) size when we are _not_
1692 if ((ret
!= subbuf_size
&& stream
->net_seq_idx
!= (uint64_t) -1ULL) ||
1693 (ret
!= len
&& stream
->net_seq_idx
== (uint64_t) -1ULL)) {
1695 * Display the error but continue processing to try to release the
1696 * subbuffer. This is a DBG statement since this is possible to
1697 * happen without being a critical error.
1699 DBG("Error writing to tracefile "
1700 "(ret: %zd != len: %lu != subbuf_size: %lu)",
1701 ret
, len
, subbuf_size
);
1706 ERR("Unknown output method");
1710 err
= kernctl_put_next_subbuf(infd
);
1712 if (err
== -EFAULT
) {
1713 PERROR("Error in unreserving sub buffer\n");
1714 } else if (err
== -EIO
) {
1715 /* Should never happen with newer LTTng versions */
1716 PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
1722 /* Write index if needed. */
1727 if (stream
->chan
->live_timer_interval
&& !stream
->metadata_flag
) {
1729 * In live, block until all the metadata is sent.
1731 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1732 assert(!stream
->missed_metadata_flush
);
1733 stream
->waiting_on_metadata
= true;
1734 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1736 err
= consumer_stream_sync_metadata(ctx
, stream
->session_id
);
1738 pthread_mutex_lock(&stream
->metadata_timer_lock
);
1739 stream
->waiting_on_metadata
= false;
1740 if (stream
->missed_metadata_flush
) {
1741 stream
->missed_metadata_flush
= false;
1742 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1743 (void) consumer_flush_kernel_index(stream
);
1745 pthread_mutex_unlock(&stream
->metadata_timer_lock
);
1752 err
= consumer_stream_write_index(stream
, &index
);
1759 * After extracting the packet, we check if the stream is now ready to be
1760 * rotated and perform the action immediately.
1762 rotation_ret
= lttng_consumer_stream_is_rotate_ready(stream
);
1763 if (rotation_ret
== 1) {
1764 rotation_ret
= lttng_consumer_rotate_stream(ctx
, stream
, rotated
);
1765 if (rotation_ret
< 0) {
1766 ERR("Stream rotation error");
1770 } else if (rotation_ret
< 0) {
1771 ERR("Checking if stream is ready to rotate");
1780 int lttng_kconsumer_on_recv_stream(struct lttng_consumer_stream
*stream
)
1787 * Don't create anything if this is set for streaming or should not be
1790 if (stream
->net_seq_idx
== (uint64_t) -1ULL && stream
->chan
->monitor
) {
1791 ret
= utils_create_stream_file(stream
->chan
->pathname
, stream
->name
,
1792 stream
->chan
->tracefile_size
, stream
->tracefile_count_current
,
1793 stream
->uid
, stream
->gid
, NULL
);
1797 stream
->out_fd
= ret
;
1798 stream
->tracefile_size_current
= 0;
1800 if (!stream
->metadata_flag
) {
1801 struct lttng_index_file
*index_file
;
1803 index_file
= lttng_index_file_create(stream
->chan
->pathname
,
1804 stream
->name
, stream
->uid
, stream
->gid
,
1805 stream
->chan
->tracefile_size
,
1806 stream
->tracefile_count_current
,
1807 CTF_INDEX_MAJOR
, CTF_INDEX_MINOR
);
1811 assert(!stream
->index_file
);
1812 stream
->index_file
= index_file
;
1816 if (stream
->output
== LTTNG_EVENT_MMAP
) {
1817 /* get the len of the mmap region */
1818 unsigned long mmap_len
;
1820 ret
= kernctl_get_mmap_len(stream
->wait_fd
, &mmap_len
);
1822 PERROR("kernctl_get_mmap_len");
1823 goto error_close_fd
;
1825 stream
->mmap_len
= (size_t) mmap_len
;
1827 stream
->mmap_base
= mmap(NULL
, stream
->mmap_len
, PROT_READ
,
1828 MAP_PRIVATE
, stream
->wait_fd
, 0);
1829 if (stream
->mmap_base
== MAP_FAILED
) {
1830 PERROR("Error mmaping");
1832 goto error_close_fd
;
1836 /* we return 0 to let the library handle the FD internally */
1840 if (stream
->out_fd
>= 0) {
1843 err
= close(stream
->out_fd
);
1845 stream
->out_fd
= -1;
1852 * Check if data is still being extracted from the buffers for a specific
1853 * stream. Consumer data lock MUST be acquired before calling this function
1854 * and the stream lock.
1856 * Return 1 if the traced data are still getting read else 0 meaning that the
1857 * data is available for trace viewer reading.
1859 int lttng_kconsumer_data_pending(struct lttng_consumer_stream
*stream
)
1865 if (stream
->endpoint_status
!= CONSUMER_ENDPOINT_ACTIVE
) {
1870 ret
= kernctl_get_next_subbuf(stream
->wait_fd
);
1872 /* There is still data so let's put back this subbuffer. */
1873 ret
= kernctl_put_subbuf(stream
->wait_fd
);
1875 ret
= 1; /* Data is pending */
1879 /* Data is NOT pending and ready to be read. */