2 * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/mount.h>
30 #include <sys/resource.h>
31 #include <sys/socket.h>
33 #include <sys/types.h>
36 #include <urcu/futex.h>
37 #include <urcu/uatomic.h>
42 #include <lttng/lttng.h>
43 #include <common/common.h>
44 #include <common/compat/poll.h>
45 #include <common/compat/socket.h>
46 #include <common/defaults.h>
47 #include <common/futex.h>
48 #include <common/sessiond-comm/sessiond-comm.h>
49 #include <common/sessiond-comm/inet.h>
50 #include <common/sessiond-comm/relayd.h>
51 #include <common/uri.h>
52 #include <common/utils.h>
55 #include "ctf-trace.h"
58 #include "lttng-relayd.h"
60 #include "health-relayd.h"
62 /* command line options */
63 char *opt_output_path
;
64 static int opt_daemon
;
65 static struct lttng_uri
*control_uri
;
66 static struct lttng_uri
*data_uri
;
67 static struct lttng_uri
*live_uri
;
71 const char *tracing_group_name
= DEFAULT_TRACING_GROUP
;
74 * Quit pipe for all threads. This permits a single cancellation point
75 * for all threads when receiving an event on the pipe.
77 static int thread_quit_pipe
[2] = { -1, -1 };
80 * This pipe is used to inform the worker thread that a command is queued and
81 * ready to be processed.
83 static int relay_cmd_pipe
[2] = { -1, -1 };
85 /* Shared between threads */
86 static int dispatch_thread_exit
;
88 static pthread_t listener_thread
;
89 static pthread_t dispatcher_thread
;
90 static pthread_t worker_thread
;
91 static pthread_t health_thread
;
93 static uint64_t last_relay_stream_id
;
94 static uint64_t last_relay_session_id
;
97 * Relay command queue.
99 * The relay_thread_listener and relay_thread_dispatcher communicate with this
102 static struct relay_cmd_queue relay_cmd_queue
;
104 /* buffer allocated at startup, used to store the trace data */
105 static char *data_buffer
;
106 static unsigned int data_buffer_size
;
108 /* We need those values for the file/dir creation. */
109 static uid_t relayd_uid
;
110 static gid_t relayd_gid
;
112 /* Global relay stream hash table. */
113 struct lttng_ht
*relay_streams_ht
;
115 /* Global relay viewer stream hash table. */
116 struct lttng_ht
*viewer_streams_ht
;
118 /* Global hash table that stores relay index object. */
119 struct lttng_ht
*indexes_ht
;
121 /* Relayd health monitoring */
122 struct health_app
*health_relayd
;
125 * usage function on stderr
130 fprintf(stderr
, "Usage: %s OPTIONS\n\nOptions:\n", progname
);
131 fprintf(stderr
, " -h, --help Display this usage.\n");
132 fprintf(stderr
, " -d, --daemonize Start as a daemon.\n");
133 fprintf(stderr
, " -C, --control-port URL Control port listening.\n");
134 fprintf(stderr
, " -D, --data-port URL Data port listening.\n");
135 fprintf(stderr
, " -L, --live-port URL Live view port listening.\n");
136 fprintf(stderr
, " -o, --output PATH Output path for traces. Must use an absolute path.\n");
137 fprintf(stderr
, " -v, --verbose Verbose mode. Activate DBG() macro.\n");
138 fprintf(stderr
, " -g, --group NAME Specify the tracing group name. (default: tracing)\n");
142 int parse_args(int argc
, char **argv
)
146 char *default_address
;
148 static struct option long_options
[] = {
149 { "control-port", 1, 0, 'C', },
150 { "data-port", 1, 0, 'D', },
151 { "daemonize", 0, 0, 'd', },
152 { "group", 1, 0, 'g', },
153 { "help", 0, 0, 'h', },
154 { "output", 1, 0, 'o', },
155 { "verbose", 0, 0, 'v', },
160 int option_index
= 0;
161 c
= getopt_long(argc
, argv
, "dhv" "C:D:L:o:g:",
162 long_options
, &option_index
);
169 fprintf(stderr
, "option %s", long_options
[option_index
].name
);
171 fprintf(stderr
, " with arg %s\n", optarg
);
175 ret
= uri_parse(optarg
, &control_uri
);
177 ERR("Invalid control URI specified");
180 if (control_uri
->port
== 0) {
181 control_uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
185 ret
= uri_parse(optarg
, &data_uri
);
187 ERR("Invalid data URI specified");
190 if (data_uri
->port
== 0) {
191 data_uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
195 ret
= uri_parse(optarg
, &live_uri
);
197 ERR("Invalid live URI specified");
200 if (live_uri
->port
== 0) {
201 live_uri
->port
= DEFAULT_NETWORK_VIEWER_PORT
;
208 tracing_group_name
= optarg
;
214 ret
= asprintf(&opt_output_path
, "%s", optarg
);
216 PERROR("asprintf opt_output_path");
221 /* Verbose level can increase using multiple -v */
222 lttng_opt_verbose
+= 1;
225 /* Unknown option or other error.
226 * Error is printed by getopt, just return */
232 /* assign default values */
233 if (control_uri
== NULL
) {
234 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
235 DEFAULT_NETWORK_CONTROL_PORT
);
237 PERROR("asprintf default data address");
241 ret
= uri_parse(default_address
, &control_uri
);
242 free(default_address
);
244 ERR("Invalid control URI specified");
248 if (data_uri
== NULL
) {
249 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
250 DEFAULT_NETWORK_DATA_PORT
);
252 PERROR("asprintf default data address");
256 ret
= uri_parse(default_address
, &data_uri
);
257 free(default_address
);
259 ERR("Invalid data URI specified");
263 if (live_uri
== NULL
) {
264 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
265 DEFAULT_NETWORK_VIEWER_PORT
);
267 PERROR("asprintf default viewer control address");
271 ret
= uri_parse(default_address
, &live_uri
);
272 free(default_address
);
274 ERR("Invalid viewer control URI specified");
291 /* free the dynamically allocated opt_output_path */
292 free(opt_output_path
);
294 /* Close thread quit pipes */
295 utils_close_pipe(thread_quit_pipe
);
297 uri_free(control_uri
);
299 /* Live URI is freed in the live thread. */
303 * Write to writable pipe used to notify a thread.
306 int notify_thread_pipe(int wpipe
)
310 ret
= lttng_write(wpipe
, "!", 1);
312 PERROR("write poll pipe");
318 static void notify_health_quit_pipe(int *pipe
)
322 ret
= lttng_write(pipe
[1], "4", 1);
324 PERROR("write relay health quit");
329 * Stop all threads by closing the thread quit pipe.
332 void stop_threads(void)
336 /* Stopping all threads */
337 DBG("Terminating all threads");
338 ret
= notify_thread_pipe(thread_quit_pipe
[1]);
340 ERR("write error on thread quit pipe");
343 notify_health_quit_pipe(health_quit_pipe
);
345 /* Dispatch thread */
346 CMM_STORE_SHARED(dispatch_thread_exit
, 1);
347 futex_nto1_wake(&relay_cmd_queue
.futex
);
351 * Signal handler for the daemon
353 * Simply stop all worker threads, leaving main() return gracefully after
354 * joining all threads and calling cleanup().
357 void sighandler(int sig
)
361 DBG("SIGPIPE caught");
364 DBG("SIGINT caught");
368 DBG("SIGTERM caught");
377 * Setup signal handler for :
378 * SIGINT, SIGTERM, SIGPIPE
381 int set_signal_handler(void)
387 if ((ret
= sigemptyset(&sigset
)) < 0) {
388 PERROR("sigemptyset");
392 sa
.sa_handler
= sighandler
;
395 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
400 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
405 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
410 DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT");
416 * Init thread quit pipe.
418 * Return -1 on error or 0 if all pipes are created.
421 int init_thread_quit_pipe(void)
425 ret
= utils_create_pipe_cloexec(thread_quit_pipe
);
431 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
434 int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
438 if (events
== NULL
|| size
== 0) {
443 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
449 ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
);
461 * Check if the thread quit pipe was triggered.
463 * Return 1 if it was triggered else 0;
466 int check_thread_quit_pipe(int fd
, uint32_t events
)
468 if (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) {
476 * Create and init socket from uri.
479 struct lttcomm_sock
*relay_init_sock(struct lttng_uri
*uri
)
482 struct lttcomm_sock
*sock
= NULL
;
484 sock
= lttcomm_alloc_sock_from_uri(uri
);
486 ERR("Allocating socket");
490 ret
= lttcomm_create_sock(sock
);
494 DBG("Listening on sock %d", sock
->fd
);
496 ret
= sock
->ops
->bind(sock
);
501 ret
= sock
->ops
->listen(sock
, -1);
511 lttcomm_destroy_sock(sock
);
517 * Return nonzero if stream needs to be closed.
520 int close_stream_check(struct relay_stream
*stream
)
523 if (stream
->close_flag
&& stream
->prev_seq
== stream
->last_net_seq_num
) {
525 * We are about to close the stream so set the data pending flag to 1
526 * which will make the end data pending command skip the stream which
527 * is now closed and ready. Note that after proceeding to a file close,
528 * the written file is ready for reading.
530 stream
->data_pending_check_done
= 1;
537 * This thread manages the listening for new connections on the network
540 void *relay_thread_listener(void *data
)
542 int i
, ret
, pollfd
, err
= -1;
544 uint32_t revents
, nb_fd
;
545 struct lttng_poll_event events
;
546 struct lttcomm_sock
*control_sock
, *data_sock
;
548 DBG("[thread] Relay listener started");
550 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LISTENER
);
552 health_code_update();
554 control_sock
= relay_init_sock(control_uri
);
556 goto error_sock_control
;
559 data_sock
= relay_init_sock(data_uri
);
561 goto error_sock_relay
;
565 * Pass 3 as size here for the thread quit pipe, control and data socket.
567 ret
= create_thread_poll_set(&events
, 3);
569 goto error_create_poll
;
572 /* Add the control socket */
573 ret
= lttng_poll_add(&events
, control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
578 /* Add the data socket */
579 ret
= lttng_poll_add(&events
, data_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
585 health_code_update();
587 DBG("Listener accepting connections");
591 ret
= lttng_poll_wait(&events
, -1);
595 * Restart interrupted system call.
597 if (errno
== EINTR
) {
605 DBG("Relay new connection received");
606 for (i
= 0; i
< nb_fd
; i
++) {
607 health_code_update();
609 /* Fetch once the poll data */
610 revents
= LTTNG_POLL_GETEV(&events
, i
);
611 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
613 /* Thread quit pipe has been closed. Killing thread. */
614 ret
= check_thread_quit_pipe(pollfd
, revents
);
620 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
621 ERR("socket poll error");
623 } else if (revents
& LPOLLIN
) {
625 * Get allocated in this thread,
626 * enqueued to a global queue, dequeued
627 * and freed in the worker thread.
629 struct relay_command
*relay_cmd
;
630 struct lttcomm_sock
*newsock
;
632 relay_cmd
= zmalloc(sizeof(struct relay_command
));
633 if (relay_cmd
== NULL
) {
634 PERROR("relay command zmalloc");
638 if (pollfd
== data_sock
->fd
) {
639 newsock
= data_sock
->ops
->accept(data_sock
);
641 PERROR("accepting data sock");
645 relay_cmd
->type
= RELAY_DATA
;
646 DBG("Relay data connection accepted, socket %d", newsock
->fd
);
648 assert(pollfd
== control_sock
->fd
);
649 newsock
= control_sock
->ops
->accept(control_sock
);
651 PERROR("accepting control sock");
655 relay_cmd
->type
= RELAY_CONTROL
;
656 DBG("Relay control connection accepted, socket %d", newsock
->fd
);
658 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
,
661 PERROR("setsockopt inet");
662 lttcomm_destroy_sock(newsock
);
666 relay_cmd
->sock
= newsock
;
668 * Lock free enqueue the request.
670 cds_wfq_enqueue(&relay_cmd_queue
.queue
, &relay_cmd
->node
);
673 * Wake the dispatch queue futex. Implicit memory
674 * barrier with the exchange in cds_wfq_enqueue.
676 futex_nto1_wake(&relay_cmd_queue
.futex
);
684 lttng_poll_clean(&events
);
686 if (data_sock
->fd
>= 0) {
687 ret
= data_sock
->ops
->close(data_sock
);
692 lttcomm_destroy_sock(data_sock
);
694 if (control_sock
->fd
>= 0) {
695 ret
= control_sock
->ops
->close(control_sock
);
700 lttcomm_destroy_sock(control_sock
);
704 ERR("Health error occurred in %s", __func__
);
706 health_unregister(health_relayd
);
707 DBG("Relay listener thread cleanup complete");
713 * This thread manages the dispatching of the requests to worker threads
716 void *relay_thread_dispatcher(void *data
)
720 struct cds_wfq_node
*node
;
721 struct relay_command
*relay_cmd
= NULL
;
723 DBG("[thread] Relay dispatcher started");
725 health_register(health_relayd
, HEALTH_RELAYD_TYPE_DISPATCHER
);
727 health_code_update();
729 while (!CMM_LOAD_SHARED(dispatch_thread_exit
)) {
730 health_code_update();
732 /* Atomically prepare the queue futex */
733 futex_nto1_prepare(&relay_cmd_queue
.futex
);
736 health_code_update();
738 /* Dequeue commands */
739 node
= cds_wfq_dequeue_blocking(&relay_cmd_queue
.queue
);
741 DBG("Woken up but nothing in the relay command queue");
742 /* Continue thread execution */
746 relay_cmd
= caa_container_of(node
, struct relay_command
, node
);
747 DBG("Dispatching request waiting on sock %d", relay_cmd
->sock
->fd
);
750 * Inform worker thread of the new request. This
751 * call is blocking so we can be assured that the data will be read
752 * at some point in time or wait to the end of the world :)
754 ret
= lttng_write(relay_cmd_pipe
[1], relay_cmd
,
755 sizeof(struct relay_command
));
757 if (ret
< sizeof(struct relay_command
)) {
758 PERROR("write cmd pipe");
761 } while (node
!= NULL
);
763 /* Futex wait on queue. Blocking call on futex() */
765 futex_nto1_wait(&relay_cmd_queue
.futex
);
769 /* Normal exit, no error */
775 ERR("Health error occurred in %s", __func__
);
777 health_unregister(health_relayd
);
778 DBG("Dispatch thread dying");
784 * Get stream from stream id.
785 * Need to be called with RCU read-side lock held.
787 struct relay_stream
*relay_stream_find_by_id(uint64_t stream_id
)
789 struct lttng_ht_node_ulong
*node
;
790 struct lttng_ht_iter iter
;
791 struct relay_stream
*ret
;
793 lttng_ht_lookup(relay_streams_ht
,
794 (void *)((unsigned long) stream_id
),
796 node
= lttng_ht_iter_get_node_ulong(&iter
);
798 DBG("Relay stream %" PRIu64
" not found", stream_id
);
803 ret
= caa_container_of(node
, struct relay_stream
, stream_n
);
810 void deferred_free_stream(struct rcu_head
*head
)
812 struct relay_stream
*stream
=
813 caa_container_of(head
, struct relay_stream
, rcu_node
);
815 free(stream
->path_name
);
816 free(stream
->channel_name
);
821 void deferred_free_session(struct rcu_head
*head
)
823 struct relay_session
*session
=
824 caa_container_of(head
, struct relay_session
, rcu_node
);
829 * Close a given stream. The stream is freed using a call RCU.
831 * RCU read side lock MUST be acquired. If NO close_stream_check() was called
832 * BEFORE the stream lock MUST be acquired.
834 static void destroy_stream(struct relay_stream
*stream
)
837 struct relay_viewer_stream
*vstream
;
838 struct lttng_ht_iter iter
;
842 delret
= close(stream
->fd
);
844 PERROR("close stream");
847 if (stream
->index_fd
>= 0) {
848 delret
= close(stream
->index_fd
);
850 PERROR("close stream index_fd");
854 vstream
= live_find_viewer_stream_by_id(stream
->stream_handle
);
857 * Set the last good value into the viewer stream. This is done
858 * right before the stream gets deleted from the hash table. The
859 * lookup failure on the live thread side of a stream indicates
860 * that the viewer stream index received value should be used.
862 pthread_mutex_lock(&stream
->viewer_stream_rotation_lock
);
863 vstream
->total_index_received
= stream
->total_index_received
;
864 vstream
->tracefile_count_last
= stream
->tracefile_count_current
;
865 vstream
->close_write_flag
= 1;
866 pthread_mutex_unlock(&stream
->viewer_stream_rotation_lock
);
869 /* Cleanup index of that stream. */
870 relay_index_destroy_by_stream_id(stream
->stream_handle
);
872 iter
.iter
.node
= &stream
->stream_n
.node
;
873 delret
= lttng_ht_del(relay_streams_ht
, &iter
);
875 iter
.iter
.node
= &stream
->ctf_trace_node
.node
;
876 delret
= lttng_ht_del(stream
->ctf_traces_ht
, &iter
);
879 if (stream
->ctf_trace
) {
880 ctf_trace_try_destroy(stream
->ctf_trace
);
883 call_rcu(&stream
->rcu_node
, deferred_free_stream
);
884 DBG("Closed tracefile %d from close stream", stream
->fd
);
888 * relay_delete_session: Free all memory associated with a session and
892 void relay_delete_session(struct relay_command
*cmd
,
893 struct lttng_ht
*sessions_ht
)
895 struct lttng_ht_iter iter
;
896 struct lttng_ht_node_ulong
*node
;
897 struct relay_stream
*stream
;
904 DBG("Relay deleting session %" PRIu64
, cmd
->session
->id
);
907 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, node
, node
) {
908 node
= lttng_ht_iter_get_node_ulong(&iter
);
912 stream
= caa_container_of(node
, struct relay_stream
, stream_n
);
913 if (stream
->session
== cmd
->session
) {
914 destroy_stream(stream
);
915 cmd
->session
->stream_count
--;
916 assert(cmd
->session
->stream_count
>= 0);
920 /* Make this session not visible anymore. */
921 iter
.iter
.node
= &cmd
->session
->session_n
.node
;
922 ret
= lttng_ht_del(sessions_ht
, &iter
);
924 call_rcu(&cmd
->session
->rcu_node
, deferred_free_session
);
929 * Copy index data from the control port to a given index object.
931 static void copy_index_control_data(struct relay_index
*index
,
932 struct lttcomm_relayd_index
*data
)
938 * The index on disk is encoded in big endian, so we don't need to convert
939 * the data received on the network. The data_offset value is NEVER
940 * modified here and is updated by the data thread.
942 index
->index_data
.packet_size
= data
->packet_size
;
943 index
->index_data
.content_size
= data
->content_size
;
944 index
->index_data
.timestamp_begin
= data
->timestamp_begin
;
945 index
->index_data
.timestamp_end
= data
->timestamp_end
;
946 index
->index_data
.events_discarded
= data
->events_discarded
;
947 index
->index_data
.stream_id
= data
->stream_id
;
951 * Handle the RELAYD_CREATE_SESSION command.
953 * On success, send back the session id or else return a negative value.
956 int relay_create_session(struct lttcomm_relayd_hdr
*recv_hdr
,
957 struct relay_command
*cmd
,
958 struct lttng_ht
*sessions_ht
)
960 int ret
= 0, send_ret
;
961 struct relay_session
*session
;
962 struct lttcomm_relayd_status_session reply
;
967 memset(&reply
, 0, sizeof(reply
));
969 session
= zmalloc(sizeof(struct relay_session
));
970 if (session
== NULL
) {
971 PERROR("relay session zmalloc");
976 session
->id
= ++last_relay_session_id
;
977 session
->sock
= cmd
->sock
;
978 session
->minor
= cmd
->minor
;
979 session
->major
= cmd
->major
;
980 cmd
->session
= session
;
982 reply
.session_id
= htobe64(session
->id
);
984 switch (cmd
->minor
) {
985 case 4: /* LTTng sessiond 2.4 */
987 ret
= cmd_create_session_2_4(cmd
, session
);
991 lttng_ht_node_init_ulong(&session
->session_n
,
992 (unsigned long) session
->id
);
993 lttng_ht_add_unique_ulong(sessions_ht
,
994 &session
->session_n
);
996 DBG("Created session %" PRIu64
, session
->id
);
1000 reply
.ret_code
= htobe32(LTTNG_ERR_FATAL
);
1002 reply
.ret_code
= htobe32(LTTNG_OK
);
1005 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1007 ERR("Relayd sending session id");
1015 * When we have received all the streams and the metadata for a channel,
1016 * we make them visible to the viewer threads.
1019 void set_viewer_ready_flag(struct relay_command
*cmd
)
1021 struct relay_stream_recv_handle
*node
, *tmp_node
;
1023 cds_list_for_each_entry_safe(node
, tmp_node
, &cmd
->recv_head
, node
) {
1024 struct relay_stream
*stream
;
1027 stream
= relay_stream_find_by_id(node
->id
);
1030 * Stream is most probably being cleaned up by the data thread thus
1031 * simply continue to the next one.
1037 stream
->viewer_ready
= 1;
1040 /* Clean stream handle node. */
1041 cds_list_del(&node
->node
);
1049 * Add a recv handle node to the connection recv list with the given stream
1050 * handle. A new node is allocated thus must be freed when the node is deleted
1053 static void queue_stream_handle(uint64_t handle
, struct relay_command
*cmd
)
1055 struct relay_stream_recv_handle
*node
;
1059 node
= zmalloc(sizeof(*node
));
1061 PERROR("zmalloc queue stream handle");
1066 cds_list_add(&node
->node
, &cmd
->recv_head
);
1070 * relay_add_stream: allocate a new stream for a session
1073 int relay_add_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1074 struct relay_command
*cmd
, struct lttng_ht
*sessions_ht
)
1076 struct relay_session
*session
= cmd
->session
;
1077 struct relay_stream
*stream
= NULL
;
1078 struct lttcomm_relayd_status_stream reply
;
1081 if (!session
|| cmd
->version_check_done
== 0) {
1082 ERR("Trying to add a stream before version check");
1084 goto end_no_session
;
1087 stream
= zmalloc(sizeof(struct relay_stream
));
1088 if (stream
== NULL
) {
1089 PERROR("relay stream zmalloc");
1091 goto end_no_session
;
1094 switch (cmd
->minor
) {
1095 case 1: /* LTTng sessiond 2.1 */
1096 ret
= cmd_recv_stream_2_1(cmd
, stream
);
1098 case 2: /* LTTng sessiond 2.2 */
1100 ret
= cmd_recv_stream_2_2(cmd
, stream
);
1104 goto err_free_stream
;
1108 stream
->stream_handle
= ++last_relay_stream_id
;
1109 stream
->prev_seq
= -1ULL;
1110 stream
->session
= session
;
1111 stream
->index_fd
= -1;
1112 stream
->read_index_fd
= -1;
1113 stream
->ctf_trace
= NULL
;
1114 pthread_mutex_init(&stream
->lock
, NULL
);
1116 ret
= utils_mkdir_recursive(stream
->path_name
, S_IRWXU
| S_IRWXG
);
1118 ERR("relay creating output directory");
1123 * No need to use run_as API here because whatever we receives, the relayd
1124 * uses its own credentials for the stream files.
1126 ret
= utils_create_stream_file(stream
->path_name
, stream
->channel_name
,
1127 stream
->tracefile_size
, 0, relayd_uid
, relayd_gid
, NULL
);
1129 ERR("Create output file");
1133 if (stream
->tracefile_size
) {
1134 DBG("Tracefile %s/%s_0 created", stream
->path_name
, stream
->channel_name
);
1136 DBG("Tracefile %s/%s created", stream
->path_name
, stream
->channel_name
);
1139 if (!strncmp(stream
->channel_name
, DEFAULT_METADATA_NAME
, NAME_MAX
)) {
1140 stream
->metadata_flag
= 1;
1142 * When we receive a new metadata stream, we create a new
1143 * ctf_trace and we assign this ctf_trace to all streams with
1146 * If later on we receive a new stream for the same ctf_trace,
1147 * we copy the information from the first hit in the HT to the
1150 stream
->ctf_trace
= ctf_trace_create();
1151 if (!stream
->ctf_trace
) {
1155 stream
->ctf_trace
->refcount
++;
1156 stream
->ctf_trace
->metadata_stream
= stream
;
1158 ctf_trace_assign(cmd
->ctf_traces_ht
, stream
);
1159 stream
->ctf_traces_ht
= cmd
->ctf_traces_ht
;
1162 * Add the stream handle in the recv list of the connection. Once the end
1163 * stream message is received, this list is emptied and streams are set
1164 * with the viewer ready flag.
1166 if (stream
->metadata_flag
) {
1167 stream
->viewer_ready
= 1;
1169 queue_stream_handle(stream
->stream_handle
, cmd
);
1172 lttng_ht_node_init_ulong(&stream
->stream_n
,
1173 (unsigned long) stream
->stream_handle
);
1174 lttng_ht_add_unique_ulong(relay_streams_ht
,
1177 lttng_ht_node_init_str(&stream
->ctf_trace_node
, stream
->path_name
);
1178 lttng_ht_add_str(cmd
->ctf_traces_ht
, &stream
->ctf_trace_node
);
1179 session
->stream_count
++;
1181 DBG("Relay new stream added %s with ID %" PRIu64
, stream
->channel_name
,
1182 stream
->stream_handle
);
1185 reply
.handle
= htobe64(stream
->stream_handle
);
1186 /* send the session id to the client or a negative return code on error */
1188 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1189 /* stream was not properly added to the ht, so free it */
1192 reply
.ret_code
= htobe32(LTTNG_OK
);
1195 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1196 sizeof(struct lttcomm_relayd_status_stream
), 0);
1198 ERR("Relay sending stream id");
1207 free(stream
->path_name
);
1208 free(stream
->channel_name
);
1214 * relay_close_stream: close a specific stream
1217 int relay_close_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1218 struct relay_command
*cmd
)
1221 struct relay_session
*session
= cmd
->session
;
1222 struct lttcomm_relayd_close_stream stream_info
;
1223 struct lttcomm_relayd_generic_reply reply
;
1224 struct relay_stream
*stream
;
1226 DBG("Close stream received");
1228 if (!session
|| cmd
->version_check_done
== 0) {
1229 ERR("Trying to close a stream before version check");
1231 goto end_no_session
;
1234 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &stream_info
,
1235 sizeof(struct lttcomm_relayd_close_stream
), 0);
1236 if (ret
< sizeof(struct lttcomm_relayd_close_stream
)) {
1238 /* Orderly shutdown. Not necessary to print an error. */
1239 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1241 ERR("Relay didn't receive valid add_stream struct size : %d", ret
);
1244 goto end_no_session
;
1248 stream
= relay_stream_find_by_id(be64toh(stream_info
.stream_id
));
1254 stream
->last_net_seq_num
= be64toh(stream_info
.last_net_seq_num
);
1255 stream
->close_flag
= 1;
1256 session
->stream_count
--;
1257 assert(session
->stream_count
>= 0);
1259 if (close_stream_check(stream
)) {
1260 destroy_stream(stream
);
1267 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1269 reply
.ret_code
= htobe32(LTTNG_OK
);
1271 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1272 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1274 ERR("Relay sending stream id");
1283 * relay_unknown_command: send -1 if received unknown command
1286 void relay_unknown_command(struct relay_command
*cmd
)
1288 struct lttcomm_relayd_generic_reply reply
;
1291 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1292 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1293 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1295 ERR("Relay sending unknown command");
1300 * relay_start: send an acknowledgment to the client to tell if we are
1301 * ready to receive data. We are ready if a session is established.
1304 int relay_start(struct lttcomm_relayd_hdr
*recv_hdr
,
1305 struct relay_command
*cmd
)
1307 int ret
= htobe32(LTTNG_OK
);
1308 struct lttcomm_relayd_generic_reply reply
;
1309 struct relay_session
*session
= cmd
->session
;
1312 DBG("Trying to start the streaming without a session established");
1313 ret
= htobe32(LTTNG_ERR_UNK
);
1316 reply
.ret_code
= ret
;
1317 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1318 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1320 ERR("Relay sending start ack");
1327 * Append padding to the file pointed by the file descriptor fd.
1329 static int write_padding_to_file(int fd
, uint32_t size
)
1338 zeros
= zmalloc(size
);
1339 if (zeros
== NULL
) {
1340 PERROR("zmalloc zeros for padding");
1345 ret
= lttng_write(fd
, zeros
, size
);
1347 PERROR("write padding to file");
1357 * relay_recv_metadata: receive the metada for the session.
1360 int relay_recv_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1361 struct relay_command
*cmd
)
1363 int ret
= htobe32(LTTNG_OK
);
1365 struct relay_session
*session
= cmd
->session
;
1366 struct lttcomm_relayd_metadata_payload
*metadata_struct
;
1367 struct relay_stream
*metadata_stream
;
1368 uint64_t data_size
, payload_size
;
1371 ERR("Metadata sent before version check");
1376 data_size
= payload_size
= be64toh(recv_hdr
->data_size
);
1377 if (data_size
< sizeof(struct lttcomm_relayd_metadata_payload
)) {
1378 ERR("Incorrect data size");
1382 payload_size
-= sizeof(struct lttcomm_relayd_metadata_payload
);
1384 if (data_buffer_size
< data_size
) {
1385 /* In case the realloc fails, we can free the memory */
1388 tmp_data_ptr
= realloc(data_buffer
, data_size
);
1389 if (!tmp_data_ptr
) {
1390 ERR("Allocating data buffer");
1395 data_buffer
= tmp_data_ptr
;
1396 data_buffer_size
= data_size
;
1398 memset(data_buffer
, 0, data_size
);
1399 DBG2("Relay receiving metadata, waiting for %" PRIu64
" bytes", data_size
);
1400 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, data_buffer
, data_size
, 0);
1401 if (ret
< 0 || ret
!= data_size
) {
1403 /* Orderly shutdown. Not necessary to print an error. */
1404 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1406 ERR("Relay didn't receive the whole metadata");
1411 metadata_struct
= (struct lttcomm_relayd_metadata_payload
*) data_buffer
;
1414 metadata_stream
= relay_stream_find_by_id(
1415 be64toh(metadata_struct
->stream_id
));
1416 if (!metadata_stream
) {
1421 size_ret
= lttng_write(metadata_stream
->fd
, metadata_struct
->payload
,
1423 if (size_ret
< payload_size
) {
1424 ERR("Relay error writing metadata on file");
1429 ret
= write_padding_to_file(metadata_stream
->fd
,
1430 be32toh(metadata_struct
->padding_size
));
1434 metadata_stream
->ctf_trace
->metadata_received
+=
1435 payload_size
+ be32toh(metadata_struct
->padding_size
);
1437 DBG2("Relay metadata written");
1446 * relay_send_version: send relayd version number
1449 int relay_send_version(struct lttcomm_relayd_hdr
*recv_hdr
,
1450 struct relay_command
*cmd
, struct lttng_ht
*sessions_ht
)
1453 struct lttcomm_relayd_version reply
, msg
;
1457 cmd
->version_check_done
= 1;
1459 /* Get version from the other side. */
1460 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1461 if (ret
< 0 || ret
!= sizeof(msg
)) {
1463 /* Orderly shutdown. Not necessary to print an error. */
1464 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1466 ERR("Relay failed to receive the version values.");
1472 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
1473 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
1475 /* Major versions must be the same */
1476 if (reply
.major
!= be32toh(msg
.major
)) {
1477 DBG("Incompatible major versions (%u vs %u), deleting session",
1478 reply
.major
, be32toh(msg
.major
));
1479 relay_delete_session(cmd
, sessions_ht
);
1484 cmd
->major
= reply
.major
;
1485 /* We adapt to the lowest compatible version */
1486 if (reply
.minor
<= be32toh(msg
.minor
)) {
1487 cmd
->minor
= reply
.minor
;
1489 cmd
->minor
= be32toh(msg
.minor
);
1492 reply
.major
= htobe32(reply
.major
);
1493 reply
.minor
= htobe32(reply
.minor
);
1494 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1495 sizeof(struct lttcomm_relayd_version
), 0);
1497 ERR("Relay sending version");
1500 DBG("Version check done using protocol %u.%u", cmd
->major
,
1508 * Check for data pending for a given stream id from the session daemon.
1511 int relay_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1512 struct relay_command
*cmd
)
1514 struct relay_session
*session
= cmd
->session
;
1515 struct lttcomm_relayd_data_pending msg
;
1516 struct lttcomm_relayd_generic_reply reply
;
1517 struct relay_stream
*stream
;
1519 uint64_t last_net_seq_num
, stream_id
;
1521 DBG("Data pending command received");
1523 if (!session
|| cmd
->version_check_done
== 0) {
1524 ERR("Trying to check for data before version check");
1526 goto end_no_session
;
1529 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1530 if (ret
< sizeof(msg
)) {
1532 /* Orderly shutdown. Not necessary to print an error. */
1533 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1535 ERR("Relay didn't receive valid data_pending struct size : %d",
1539 goto end_no_session
;
1542 stream_id
= be64toh(msg
.stream_id
);
1543 last_net_seq_num
= be64toh(msg
.last_net_seq_num
);
1546 stream
= relay_stream_find_by_id(stream_id
);
1547 if (stream
== NULL
) {
1552 DBG("Data pending for stream id %" PRIu64
" prev_seq %" PRIu64
1553 " and last_seq %" PRIu64
, stream_id
, stream
->prev_seq
,
1556 /* Avoid wrapping issue */
1557 if (((int64_t) (stream
->prev_seq
- last_net_seq_num
)) >= 0) {
1558 /* Data has in fact been written and is NOT pending */
1561 /* Data still being streamed thus pending */
1565 /* Pending check is now done. */
1566 stream
->data_pending_check_done
= 1;
1571 reply
.ret_code
= htobe32(ret
);
1572 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1574 ERR("Relay data pending ret code failed");
1582 * Wait for the control socket to reach a quiescent state.
1584 * Note that for now, when receiving this command from the session daemon, this
1585 * means that every subsequent commands or data received on the control socket
1586 * has been handled. So, this is why we simply return OK here.
1589 int relay_quiescent_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1590 struct relay_command
*cmd
)
1594 struct relay_stream
*stream
;
1595 struct lttng_ht_iter iter
;
1596 struct lttcomm_relayd_quiescent_control msg
;
1597 struct lttcomm_relayd_generic_reply reply
;
1599 DBG("Checking quiescent state on control socket");
1601 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1602 ERR("Trying to check for data before version check");
1604 goto end_no_session
;
1607 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1608 if (ret
< sizeof(msg
)) {
1610 /* Orderly shutdown. Not necessary to print an error. */
1611 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1613 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1617 goto end_no_session
;
1620 stream_id
= be64toh(msg
.stream_id
);
1623 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1625 if (stream
->stream_handle
== stream_id
) {
1626 stream
->data_pending_check_done
= 1;
1627 DBG("Relay quiescent control pending flag set to %" PRIu64
,
1634 reply
.ret_code
= htobe32(LTTNG_OK
);
1635 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1637 ERR("Relay data quiescent control ret code failed");
1645 * Initialize a data pending command. This means that a client is about to ask
1646 * for data pending for each stream he/she holds. Simply iterate over all
1647 * streams of a session and set the data_pending_check_done flag.
1649 * This command returns to the client a LTTNG_OK code.
1652 int relay_begin_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1653 struct relay_command
*cmd
)
1656 struct lttng_ht_iter iter
;
1657 struct lttcomm_relayd_begin_data_pending msg
;
1658 struct lttcomm_relayd_generic_reply reply
;
1659 struct relay_stream
*stream
;
1660 uint64_t session_id
;
1665 DBG("Init streams for data pending");
1667 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1668 ERR("Trying to check for data before version check");
1670 goto end_no_session
;
1673 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1674 if (ret
< sizeof(msg
)) {
1676 /* Orderly shutdown. Not necessary to print an error. */
1677 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1679 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1683 goto end_no_session
;
1686 session_id
= be64toh(msg
.session_id
);
1689 * Iterate over all streams to set the begin data pending flag. For now, the
1690 * streams are indexed by stream handle so we have to iterate over all
1691 * streams to find the one associated with the right session_id.
1694 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1696 if (stream
->session
->id
== session_id
) {
1697 stream
->data_pending_check_done
= 0;
1698 DBG("Set begin data pending flag to stream %" PRIu64
,
1699 stream
->stream_handle
);
1704 /* All good, send back reply. */
1705 reply
.ret_code
= htobe32(LTTNG_OK
);
1707 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1709 ERR("Relay begin data pending send reply failed");
1717 * End data pending command. This will check, for a given session id, if each
1718 * stream associated with it has its data_pending_check_done flag set. If not,
1719 * this means that the client lost track of the stream but the data is still
1720 * being streamed on our side. In this case, we inform the client that data is
1723 * Return to the client if there is data in flight or not with a ret_code.
1726 int relay_end_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1727 struct relay_command
*cmd
)
1730 struct lttng_ht_iter iter
;
1731 struct lttcomm_relayd_end_data_pending msg
;
1732 struct lttcomm_relayd_generic_reply reply
;
1733 struct relay_stream
*stream
;
1734 uint64_t session_id
;
1735 uint32_t is_data_inflight
= 0;
1740 DBG("End data pending command");
1742 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1743 ERR("Trying to check for data before version check");
1745 goto end_no_session
;
1748 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1749 if (ret
< sizeof(msg
)) {
1751 /* Orderly shutdown. Not necessary to print an error. */
1752 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1754 ERR("Relay didn't receive valid end data_pending struct size: %d",
1758 goto end_no_session
;
1761 session_id
= be64toh(msg
.session_id
);
1763 /* Iterate over all streams to see if the begin data pending flag is set. */
1765 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1767 if (stream
->session
->id
== session_id
&&
1768 !stream
->data_pending_check_done
) {
1769 is_data_inflight
= 1;
1770 DBG("Data is still in flight for stream %" PRIu64
,
1771 stream
->stream_handle
);
1777 /* All good, send back reply. */
1778 reply
.ret_code
= htobe32(is_data_inflight
);
1780 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1782 ERR("Relay end data pending send reply failed");
1790 * Receive an index for a specific stream.
1792 * Return 0 on success else a negative value.
1795 int relay_recv_index(struct lttcomm_relayd_hdr
*recv_hdr
,
1796 struct relay_command
*cmd
)
1798 int ret
, send_ret
, index_created
= 0;
1799 struct relay_session
*session
= cmd
->session
;
1800 struct lttcomm_relayd_index index_info
;
1801 struct relay_index
*index
, *wr_index
= NULL
;
1802 struct lttcomm_relayd_generic_reply reply
;
1803 struct relay_stream
*stream
;
1804 uint64_t net_seq_num
;
1808 DBG("Relay receiving index");
1810 if (!session
|| cmd
->version_check_done
== 0) {
1811 ERR("Trying to close a stream before version check");
1813 goto end_no_session
;
1816 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &index_info
,
1817 sizeof(index_info
), 0);
1818 if (ret
< sizeof(index_info
)) {
1820 /* Orderly shutdown. Not necessary to print an error. */
1821 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1823 ERR("Relay didn't receive valid index struct size : %d", ret
);
1826 goto end_no_session
;
1829 net_seq_num
= be64toh(index_info
.net_seq_num
);
1832 stream
= relay_stream_find_by_id(be64toh(index_info
.relay_stream_id
));
1835 goto end_rcu_unlock
;
1838 /* Live beacon handling */
1839 if (index_info
.packet_size
== 0) {
1840 DBG("Received live beacon for stream %" PRIu64
, stream
->stream_handle
);
1843 * Only flag a stream inactive when it has already received data.
1845 if (stream
->total_index_received
> 0) {
1846 stream
->beacon_ts_end
= be64toh(index_info
.timestamp_end
);
1849 goto end_rcu_unlock
;
1851 stream
->beacon_ts_end
= -1ULL;
1854 index
= relay_index_find(stream
->stream_handle
, net_seq_num
);
1856 /* A successful creation will add the object to the HT. */
1857 index
= relay_index_create(stream
->stream_handle
, net_seq_num
);
1859 goto end_rcu_unlock
;
1864 copy_index_control_data(index
, &index_info
);
1866 if (index_created
) {
1868 * Try to add the relay index object to the hash table. If an object
1869 * already exist, destroy back the index created, set the data in this
1870 * object and write it on disk.
1872 relay_index_add(index
, &wr_index
);
1874 copy_index_control_data(wr_index
, &index_info
);
1878 /* The index already exists so write it on disk. */
1882 /* Do we have a writable ready index to write on disk. */
1884 /* Starting at 2.4, create the index file if none available. */
1885 if (cmd
->minor
>= 4 && stream
->index_fd
< 0) {
1886 ret
= index_create_file(stream
->path_name
, stream
->channel_name
,
1887 relayd_uid
, relayd_gid
, stream
->tracefile_size
,
1888 stream
->tracefile_count_current
);
1890 goto end_rcu_unlock
;
1892 stream
->index_fd
= ret
;
1895 ret
= relay_index_write(wr_index
->fd
, wr_index
);
1897 goto end_rcu_unlock
;
1899 stream
->total_index_received
++;
1906 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1908 reply
.ret_code
= htobe32(LTTNG_OK
);
1910 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1912 ERR("Relay sending close index id reply");
1921 * Receive the streams_sent message.
1923 * Return 0 on success else a negative value.
1926 int relay_streams_sent(struct lttcomm_relayd_hdr
*recv_hdr
,
1927 struct relay_command
*cmd
)
1930 struct lttcomm_relayd_generic_reply reply
;
1934 DBG("Relay receiving streams_sent");
1936 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1937 ERR("Trying to close a stream before version check");
1939 goto end_no_session
;
1943 * Flag every pending stream in the connection recv list that they are
1944 * ready to be used by the viewer.
1946 set_viewer_ready_flag(cmd
);
1948 reply
.ret_code
= htobe32(LTTNG_OK
);
1949 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1951 ERR("Relay sending sent_stream reply");
1963 * Process the commands received on the control socket
1966 int relay_process_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1967 struct relay_command
*cmd
, struct relay_local_data
*ctx
)
1971 switch (be32toh(recv_hdr
->cmd
)) {
1972 case RELAYD_CREATE_SESSION
:
1973 ret
= relay_create_session(recv_hdr
, cmd
, ctx
->sessions_ht
);
1975 case RELAYD_ADD_STREAM
:
1976 ret
= relay_add_stream(recv_hdr
, cmd
, ctx
->sessions_ht
);
1978 case RELAYD_START_DATA
:
1979 ret
= relay_start(recv_hdr
, cmd
);
1981 case RELAYD_SEND_METADATA
:
1982 ret
= relay_recv_metadata(recv_hdr
, cmd
);
1984 case RELAYD_VERSION
:
1985 ret
= relay_send_version(recv_hdr
, cmd
, ctx
->sessions_ht
);
1987 case RELAYD_CLOSE_STREAM
:
1988 ret
= relay_close_stream(recv_hdr
, cmd
);
1990 case RELAYD_DATA_PENDING
:
1991 ret
= relay_data_pending(recv_hdr
, cmd
);
1993 case RELAYD_QUIESCENT_CONTROL
:
1994 ret
= relay_quiescent_control(recv_hdr
, cmd
);
1996 case RELAYD_BEGIN_DATA_PENDING
:
1997 ret
= relay_begin_data_pending(recv_hdr
, cmd
);
1999 case RELAYD_END_DATA_PENDING
:
2000 ret
= relay_end_data_pending(recv_hdr
, cmd
);
2002 case RELAYD_SEND_INDEX
:
2003 ret
= relay_recv_index(recv_hdr
, cmd
);
2005 case RELAYD_STREAMS_SENT
:
2006 ret
= relay_streams_sent(recv_hdr
, cmd
);
2008 case RELAYD_UPDATE_SYNC_INFO
:
2010 ERR("Received unknown command (%u)", be32toh(recv_hdr
->cmd
));
2011 relay_unknown_command(cmd
);
2021 * Handle index for a data stream.
2023 * RCU read side lock MUST be acquired.
2025 * Return 0 on success else a negative value.
2027 static int handle_index_data(struct relay_stream
*stream
, uint64_t net_seq_num
,
2030 int ret
= 0, index_created
= 0;
2031 uint64_t stream_id
, data_offset
;
2032 struct relay_index
*index
, *wr_index
= NULL
;
2036 stream_id
= stream
->stream_handle
;
2037 /* Get data offset because we are about to update the index. */
2038 data_offset
= htobe64(stream
->tracefile_size_current
);
2041 * Lookup for an existing index for that stream id/sequence number. If on
2042 * exists, the control thread already received the data for it thus we need
2043 * to write it on disk.
2045 index
= relay_index_find(stream_id
, net_seq_num
);
2047 /* A successful creation will add the object to the HT. */
2048 index
= relay_index_create(stream_id
, net_seq_num
);
2056 if (rotate_index
|| stream
->index_fd
< 0) {
2057 index
->to_close_fd
= stream
->index_fd
;
2058 ret
= index_create_file(stream
->path_name
, stream
->channel_name
,
2059 relayd_uid
, relayd_gid
, stream
->tracefile_size
,
2060 stream
->tracefile_count_current
);
2062 /* This will close the stream's index fd if one. */
2063 relay_index_free_safe(index
);
2066 stream
->index_fd
= ret
;
2068 index
->fd
= stream
->index_fd
;
2069 index
->index_data
.offset
= data_offset
;
2071 if (index_created
) {
2073 * Try to add the relay index object to the hash table. If an object
2074 * already exist, destroy back the index created and set the data.
2076 relay_index_add(index
, &wr_index
);
2078 /* Copy back data from the created index. */
2079 wr_index
->fd
= index
->fd
;
2080 wr_index
->to_close_fd
= index
->to_close_fd
;
2081 wr_index
->index_data
.offset
= data_offset
;
2085 /* The index already exists so write it on disk. */
2089 /* Do we have a writable ready index to write on disk. */
2091 ret
= relay_index_write(wr_index
->fd
, wr_index
);
2095 stream
->total_index_received
++;
2103 * relay_process_data: Process the data received on the data socket
2106 int relay_process_data(struct relay_command
*cmd
)
2108 int ret
= 0, rotate_index
= 0;
2110 struct relay_stream
*stream
;
2111 struct lttcomm_relayd_data_hdr data_hdr
;
2113 uint64_t net_seq_num
;
2116 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &data_hdr
,
2117 sizeof(struct lttcomm_relayd_data_hdr
), 0);
2120 /* Orderly shutdown. Not necessary to print an error. */
2121 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
2123 ERR("Unable to receive data header on sock %d", cmd
->sock
->fd
);
2129 stream_id
= be64toh(data_hdr
.stream_id
);
2132 stream
= relay_stream_find_by_id(stream_id
);
2135 goto end_rcu_unlock
;
2138 data_size
= be32toh(data_hdr
.data_size
);
2139 if (data_buffer_size
< data_size
) {
2142 tmp_data_ptr
= realloc(data_buffer
, data_size
);
2143 if (!tmp_data_ptr
) {
2144 ERR("Allocating data buffer");
2147 goto end_rcu_unlock
;
2149 data_buffer
= tmp_data_ptr
;
2150 data_buffer_size
= data_size
;
2152 memset(data_buffer
, 0, data_size
);
2154 net_seq_num
= be64toh(data_hdr
.net_seq_num
);
2156 DBG3("Receiving data of size %u for stream id %" PRIu64
" seqnum %" PRIu64
,
2157 data_size
, stream_id
, net_seq_num
);
2158 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, data_buffer
, data_size
, 0);
2161 /* Orderly shutdown. Not necessary to print an error. */
2162 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
2165 goto end_rcu_unlock
;
2168 /* Check if a rotation is needed. */
2169 if (stream
->tracefile_size
> 0 &&
2170 (stream
->tracefile_size_current
+ data_size
) >
2171 stream
->tracefile_size
) {
2172 struct relay_viewer_stream
*vstream
;
2175 new_id
= (stream
->tracefile_count_current
+ 1) %
2176 stream
->tracefile_count
;
2178 * When we wrap-around back to 0, we start overwriting old
2181 if (!stream
->tracefile_overwrite
&& new_id
== 0) {
2182 stream
->tracefile_overwrite
= 1;
2184 pthread_mutex_lock(&stream
->viewer_stream_rotation_lock
);
2185 if (stream
->tracefile_overwrite
) {
2186 stream
->oldest_tracefile_id
=
2187 (stream
->oldest_tracefile_id
+ 1) %
2188 stream
->tracefile_count
;
2190 vstream
= live_find_viewer_stream_by_id(stream
->stream_handle
);
2193 * The viewer is reading a file about to be
2194 * overwritten. Close the FDs it is
2195 * currently using and let it handle the fault.
2197 if (vstream
->tracefile_count_current
== new_id
) {
2198 pthread_mutex_lock(&vstream
->overwrite_lock
);
2199 vstream
->abort_flag
= 1;
2200 pthread_mutex_unlock(&vstream
->overwrite_lock
);
2201 DBG("Streaming side setting abort_flag on stream %s_%lu\n",
2202 stream
->channel_name
, new_id
);
2203 } else if (vstream
->tracefile_count_current
==
2204 stream
->tracefile_count_current
) {
2206 * The reader and writer were in the
2207 * same trace file, inform the viewer
2208 * that no new index will ever be added
2211 vstream
->close_write_flag
= 1;
2214 ret
= utils_rotate_stream_file(stream
->path_name
, stream
->channel_name
,
2215 stream
->tracefile_size
, stream
->tracefile_count
,
2216 relayd_uid
, relayd_gid
, stream
->fd
,
2217 &(stream
->tracefile_count_current
), &stream
->fd
);
2218 stream
->total_index_received
= 0;
2219 pthread_mutex_unlock(&stream
->viewer_stream_rotation_lock
);
2221 ERR("Rotating stream output file");
2222 goto end_rcu_unlock
;
2224 /* Reset current size because we just perform a stream rotation. */
2225 stream
->tracefile_size_current
= 0;
2230 * Index are handled in protocol version 2.4 and above. Also, snapshot and
2231 * index are NOT supported.
2233 if (stream
->session
->minor
>= 4 && !stream
->session
->snapshot
) {
2234 ret
= handle_index_data(stream
, net_seq_num
, rotate_index
);
2236 goto end_rcu_unlock
;
2240 /* Write data to stream output fd. */
2241 size_ret
= lttng_write(stream
->fd
, data_buffer
, data_size
);
2242 if (size_ret
< data_size
) {
2243 ERR("Relay error writing data to file");
2245 goto end_rcu_unlock
;
2248 DBG2("Relay wrote %d bytes to tracefile for stream id %" PRIu64
,
2249 ret
, stream
->stream_handle
);
2251 ret
= write_padding_to_file(stream
->fd
, be32toh(data_hdr
.padding_size
));
2253 goto end_rcu_unlock
;
2255 stream
->tracefile_size_current
+= data_size
+ be32toh(data_hdr
.padding_size
);
2257 stream
->prev_seq
= net_seq_num
;
2259 /* Check if we need to close the FD */
2260 if (close_stream_check(stream
)) {
2261 destroy_stream(stream
);
2271 void relay_cleanup_poll_connection(struct lttng_poll_event
*events
, int pollfd
)
2275 lttng_poll_del(events
, pollfd
);
2277 ret
= close(pollfd
);
2279 ERR("Closing pollfd %d", pollfd
);
2284 int relay_add_connection(int fd
, struct lttng_poll_event
*events
,
2285 struct lttng_ht
*relay_connections_ht
)
2287 struct relay_command
*relay_connection
;
2290 relay_connection
= zmalloc(sizeof(struct relay_command
));
2291 if (relay_connection
== NULL
) {
2292 PERROR("Relay command zmalloc");
2295 ret
= lttng_read(fd
, relay_connection
, sizeof(struct relay_command
));
2296 if (ret
< sizeof(struct relay_command
)) {
2297 PERROR("read relay cmd pipe");
2300 CDS_INIT_LIST_HEAD(&relay_connection
->recv_head
);
2303 * Only used by the control side and the reference is copied inside each
2304 * stream from that connection. Thus a destroy HT must be done after every
2305 * stream has been destroyed.
2307 if (relay_connection
->type
== RELAY_CONTROL
) {
2308 relay_connection
->ctf_traces_ht
= lttng_ht_new(0,
2309 LTTNG_HT_TYPE_STRING
);
2310 if (!relay_connection
->ctf_traces_ht
) {
2315 lttng_ht_node_init_ulong(&relay_connection
->sock_n
,
2316 (unsigned long) relay_connection
->sock
->fd
);
2318 lttng_ht_add_unique_ulong(relay_connections_ht
,
2319 &relay_connection
->sock_n
);
2321 return lttng_poll_add(events
,
2322 relay_connection
->sock
->fd
,
2323 LPOLLIN
| LPOLLRDHUP
);
2326 free(relay_connection
);
2332 void deferred_free_connection(struct rcu_head
*head
)
2334 struct relay_command
*relay_connection
=
2335 caa_container_of(head
, struct relay_command
, rcu_node
);
2337 lttcomm_destroy_sock(relay_connection
->sock
);
2338 free(relay_connection
);
2342 void relay_del_connection(struct lttng_ht
*relay_connections_ht
,
2343 struct lttng_ht_iter
*iter
, struct relay_command
*relay_connection
,
2344 struct lttng_ht
*sessions_ht
)
2348 ret
= lttng_ht_del(relay_connections_ht
, iter
);
2351 if (relay_connection
->type
== RELAY_CONTROL
) {
2352 struct relay_stream_recv_handle
*node
, *tmp_node
;
2354 relay_delete_session(relay_connection
, sessions_ht
);
2355 lttng_ht_destroy(relay_connection
->ctf_traces_ht
);
2357 /* Clean up recv list. */
2358 cds_list_for_each_entry_safe(node
, tmp_node
,
2359 &relay_connection
->recv_head
, node
) {
2360 cds_list_del(&node
->node
);
2365 call_rcu(&relay_connection
->rcu_node
, deferred_free_connection
);
2369 * This thread does the actual work
2372 void *relay_thread_worker(void *data
)
2374 int ret
, err
= -1, last_seen_data_fd
= -1;
2376 struct relay_command
*relay_connection
;
2377 struct lttng_poll_event events
;
2378 struct lttng_ht
*relay_connections_ht
;
2379 struct lttng_ht_node_ulong
*node
;
2380 struct lttng_ht_iter iter
;
2381 struct lttcomm_relayd_hdr recv_hdr
;
2382 struct relay_local_data
*relay_ctx
= (struct relay_local_data
*) data
;
2383 struct lttng_ht
*sessions_ht
= relay_ctx
->sessions_ht
;
2385 DBG("[thread] Relay worker started");
2387 rcu_register_thread();
2389 health_register(health_relayd
, HEALTH_RELAYD_TYPE_WORKER
);
2391 health_code_update();
2393 /* table of connections indexed on socket */
2394 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2395 if (!relay_connections_ht
) {
2396 goto relay_connections_ht_error
;
2399 /* Tables of received indexes indexed by index handle and net_seq_num. */
2400 indexes_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_TWO_U64
);
2402 goto indexes_ht_error
;
2405 ret
= create_thread_poll_set(&events
, 2);
2407 goto error_poll_create
;
2410 ret
= lttng_poll_add(&events
, relay_cmd_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
2417 int idx
= -1, i
, seen_control
= 0, last_notdel_data_fd
= -1;
2419 health_code_update();
2421 /* Infinite blocking call, waiting for transmission */
2422 DBG3("Relayd worker thread polling...");
2423 health_poll_entry();
2424 ret
= lttng_poll_wait(&events
, -1);
2428 * Restart interrupted system call.
2430 if (errno
== EINTR
) {
2439 * Process control. The control connection is prioritised so we don't
2440 * starve it with high throughout put tracing data on the data
2443 for (i
= 0; i
< nb_fd
; i
++) {
2444 /* Fetch once the poll data */
2445 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2446 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2448 health_code_update();
2450 /* Thread quit pipe has been closed. Killing thread. */
2451 ret
= check_thread_quit_pipe(pollfd
, revents
);
2457 /* Inspect the relay cmd pipe for new connection */
2458 if (pollfd
== relay_cmd_pipe
[0]) {
2459 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2460 ERR("Relay pipe error");
2462 } else if (revents
& LPOLLIN
) {
2463 DBG("Relay command received");
2464 ret
= relay_add_connection(relay_cmd_pipe
[0],
2465 &events
, relay_connections_ht
);
2470 } else if (revents
) {
2472 lttng_ht_lookup(relay_connections_ht
,
2473 (void *)((unsigned long) pollfd
),
2475 node
= lttng_ht_iter_get_node_ulong(&iter
);
2477 DBG2("Relay sock %d not found", pollfd
);
2481 relay_connection
= caa_container_of(node
,
2482 struct relay_command
, sock_n
);
2484 if (revents
& (LPOLLERR
)) {
2486 relay_cleanup_poll_connection(&events
, pollfd
);
2487 relay_del_connection(relay_connections_ht
,
2488 &iter
, relay_connection
, sessions_ht
);
2489 if (last_seen_data_fd
== pollfd
) {
2490 last_seen_data_fd
= last_notdel_data_fd
;
2492 } else if (revents
& (LPOLLHUP
| LPOLLRDHUP
)) {
2493 DBG("Socket %d hung up", pollfd
);
2494 relay_cleanup_poll_connection(&events
, pollfd
);
2495 relay_del_connection(relay_connections_ht
,
2496 &iter
, relay_connection
, sessions_ht
);
2497 if (last_seen_data_fd
== pollfd
) {
2498 last_seen_data_fd
= last_notdel_data_fd
;
2500 } else if (revents
& LPOLLIN
) {
2501 /* control socket */
2502 if (relay_connection
->type
== RELAY_CONTROL
) {
2503 ret
= relay_connection
->sock
->ops
->recvmsg(
2504 relay_connection
->sock
, &recv_hdr
,
2505 sizeof(struct lttcomm_relayd_hdr
), 0);
2506 /* connection closed */
2508 relay_cleanup_poll_connection(&events
, pollfd
);
2509 relay_del_connection(relay_connections_ht
,
2510 &iter
, relay_connection
, sessions_ht
);
2511 DBG("Control connection closed with %d", pollfd
);
2513 if (relay_connection
->session
) {
2514 DBG2("Relay worker receiving data for session : %" PRIu64
,
2515 relay_connection
->session
->id
);
2517 ret
= relay_process_control(&recv_hdr
,
2518 relay_connection
, relay_ctx
);
2520 /* Clear the session on error. */
2521 relay_cleanup_poll_connection(&events
, pollfd
);
2522 relay_del_connection(relay_connections_ht
,
2523 &iter
, relay_connection
, sessions_ht
);
2524 DBG("Connection closed with %d", pollfd
);
2530 * Flag the last seen data fd not deleted. It will be
2531 * used as the last seen fd if any fd gets deleted in
2534 last_notdel_data_fd
= pollfd
;
2542 * The last loop handled a control request, go back to poll to make
2543 * sure we prioritise the control socket.
2549 if (last_seen_data_fd
>= 0) {
2550 for (i
= 0; i
< nb_fd
; i
++) {
2551 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2553 health_code_update();
2555 if (last_seen_data_fd
== pollfd
) {
2562 /* Process data connection. */
2563 for (i
= idx
+ 1; i
< nb_fd
; i
++) {
2564 /* Fetch the poll data. */
2565 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2566 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2568 health_code_update();
2570 /* Skip the command pipe. It's handled in the first loop. */
2571 if (pollfd
== relay_cmd_pipe
[0]) {
2577 lttng_ht_lookup(relay_connections_ht
,
2578 (void *)((unsigned long) pollfd
),
2580 node
= lttng_ht_iter_get_node_ulong(&iter
);
2582 /* Skip it. Might be removed before. */
2586 relay_connection
= caa_container_of(node
,
2587 struct relay_command
, sock_n
);
2589 if (revents
& LPOLLIN
) {
2590 if (relay_connection
->type
!= RELAY_DATA
) {
2594 ret
= relay_process_data(relay_connection
);
2595 /* connection closed */
2597 relay_cleanup_poll_connection(&events
, pollfd
);
2598 relay_del_connection(relay_connections_ht
,
2599 &iter
, relay_connection
, sessions_ht
);
2600 DBG("Data connection closed with %d", pollfd
);
2602 * Every goto restart call sets the last seen fd where
2603 * here we don't really care since we gracefully
2604 * continue the loop after the connection is deleted.
2607 /* Keep last seen port. */
2608 last_seen_data_fd
= pollfd
;
2616 last_seen_data_fd
= -1;
2619 /* Normal exit, no error */
2624 lttng_poll_clean(&events
);
2626 /* empty the hash table and free the memory */
2628 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
, node
, node
) {
2629 health_code_update();
2631 node
= lttng_ht_iter_get_node_ulong(&iter
);
2633 relay_connection
= caa_container_of(node
,
2634 struct relay_command
, sock_n
);
2635 relay_del_connection(relay_connections_ht
,
2636 &iter
, relay_connection
, sessions_ht
);
2641 lttng_ht_destroy(indexes_ht
);
2643 lttng_ht_destroy(relay_connections_ht
);
2644 relay_connections_ht_error
:
2645 /* Close relay cmd pipes */
2646 utils_close_pipe(relay_cmd_pipe
);
2648 DBG("Thread exited with error");
2650 DBG("Worker thread cleanup complete");
2654 ERR("Health error occurred in %s", __func__
);
2656 health_unregister(health_relayd
);
2657 rcu_unregister_thread();
2663 * Create the relay command pipe to wake thread_manage_apps.
2664 * Closed in cleanup().
2666 static int create_relay_cmd_pipe(void)
2670 ret
= utils_create_pipe_cloexec(relay_cmd_pipe
);
2678 int main(int argc
, char **argv
)
2682 struct relay_local_data
*relay_ctx
;
2684 /* Create thread quit pipe */
2685 if ((ret
= init_thread_quit_pipe()) < 0) {
2689 /* Parse arguments */
2691 if ((ret
= parse_args(argc
, argv
)) < 0) {
2695 if ((ret
= set_signal_handler()) < 0) {
2699 /* Try to create directory if -o, --output is specified. */
2700 if (opt_output_path
) {
2701 if (*opt_output_path
!= '/') {
2702 ERR("Please specify an absolute path for -o, --output PATH");
2706 ret
= utils_mkdir_recursive(opt_output_path
, S_IRWXU
| S_IRWXG
);
2708 ERR("Unable to create %s", opt_output_path
);
2722 /* We need those values for the file/dir creation. */
2723 relayd_uid
= getuid();
2724 relayd_gid
= getgid();
2726 /* Check if daemon is UID = 0 */
2727 if (relayd_uid
== 0) {
2728 if (control_uri
->port
< 1024 || data_uri
->port
< 1024 ||
2729 live_uri
->port
< 1024) {
2730 ERR("Need to be root to use ports < 1024");
2736 /* Setup the thread apps communication pipe. */
2737 if ((ret
= create_relay_cmd_pipe()) < 0) {
2741 /* Init relay command queue. */
2742 cds_wfq_init(&relay_cmd_queue
.queue
);
2744 /* Set up max poll set size */
2745 lttng_poll_set_max_size();
2747 /* Initialize communication library */
2750 relay_ctx
= zmalloc(sizeof(struct relay_local_data
));
2752 PERROR("relay_ctx");
2756 /* tables of sessions indexed by session ID */
2757 relay_ctx
->sessions_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2758 if (!relay_ctx
->sessions_ht
) {
2759 goto exit_relay_ctx_sessions
;
2762 /* tables of streams indexed by stream ID */
2763 relay_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2764 if (!relay_streams_ht
) {
2765 goto exit_relay_ctx_streams
;
2768 /* tables of streams indexed by stream ID */
2769 viewer_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2770 if (!viewer_streams_ht
) {
2771 goto exit_relay_ctx_viewer_streams
;
2774 /* Initialize thread health monitoring */
2775 health_relayd
= health_app_create(NR_HEALTH_RELAYD_TYPES
);
2776 if (!health_relayd
) {
2777 PERROR("health_app_create error");
2778 goto exit_health_app_create
;
2781 ret
= utils_create_pipe(health_quit_pipe
);
2783 goto error_health_pipe
;
2786 /* Create thread to manage the client socket */
2787 ret
= pthread_create(&health_thread
, NULL
,
2788 thread_manage_health
, (void *) NULL
);
2790 PERROR("pthread_create health");
2794 /* Setup the dispatcher thread */
2795 ret
= pthread_create(&dispatcher_thread
, NULL
,
2796 relay_thread_dispatcher
, (void *) NULL
);
2798 PERROR("pthread_create dispatcher");
2799 goto exit_dispatcher
;
2802 /* Setup the worker thread */
2803 ret
= pthread_create(&worker_thread
, NULL
,
2804 relay_thread_worker
, (void *) relay_ctx
);
2806 PERROR("pthread_create worker");
2810 /* Setup the listener thread */
2811 ret
= pthread_create(&listener_thread
, NULL
,
2812 relay_thread_listener
, (void *) NULL
);
2814 PERROR("pthread_create listener");
2818 ret
= live_start_threads(live_uri
, relay_ctx
, thread_quit_pipe
);
2820 ERR("Starting live viewer threads");
2825 ret
= pthread_join(listener_thread
, &status
);
2827 PERROR("pthread_join");
2828 goto error
; /* join error, exit without cleanup */
2832 ret
= pthread_join(worker_thread
, &status
);
2834 PERROR("pthread_join");
2835 goto error
; /* join error, exit without cleanup */
2839 ret
= pthread_join(dispatcher_thread
, &status
);
2841 PERROR("pthread_join");
2842 goto error
; /* join error, exit without cleanup */
2846 ret
= pthread_join(health_thread
, &status
);
2848 PERROR("pthread_join health thread");
2849 goto error
; /* join error, exit without cleanup */
2853 * Stop live threads only after joining other threads.
2855 live_stop_threads();
2858 utils_close_pipe(health_quit_pipe
);
2861 health_app_destroy(health_relayd
);
2863 exit_health_app_create
:
2864 lttng_ht_destroy(viewer_streams_ht
);
2866 exit_relay_ctx_viewer_streams
:
2867 lttng_ht_destroy(relay_streams_ht
);
2869 exit_relay_ctx_streams
:
2870 lttng_ht_destroy(relay_ctx
->sessions_ht
);
2872 exit_relay_ctx_sessions
: