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
, opt_background
;
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
, " -b, --background Start as a daemon, keeping console open.\n");
134 fprintf(stderr
, " -C, --control-port URL Control port listening.\n");
135 fprintf(stderr
, " -D, --data-port URL Data port listening.\n");
136 fprintf(stderr
, " -L, --live-port URL Live view port listening.\n");
137 fprintf(stderr
, " -o, --output PATH Output path for traces. Must use an absolute path.\n");
138 fprintf(stderr
, " -v, --verbose Verbose mode. Activate DBG() macro.\n");
139 fprintf(stderr
, " -g, --group NAME Specify the tracing group name. (default: tracing)\n");
143 int parse_args(int argc
, char **argv
)
147 char *default_address
;
149 static struct option long_options
[] = {
150 { "control-port", 1, 0, 'C', },
151 { "data-port", 1, 0, 'D', },
152 { "daemonize", 0, 0, 'd', },
153 { "group", 1, 0, 'g', },
154 { "help", 0, 0, 'h', },
155 { "output", 1, 0, 'o', },
156 { "verbose", 0, 0, 'v', },
161 int option_index
= 0;
162 c
= getopt_long(argc
, argv
, "dhv" "C:D:L:o:g:",
163 long_options
, &option_index
);
170 fprintf(stderr
, "option %s", long_options
[option_index
].name
);
172 fprintf(stderr
, " with arg %s\n", optarg
);
176 ret
= uri_parse(optarg
, &control_uri
);
178 ERR("Invalid control URI specified");
181 if (control_uri
->port
== 0) {
182 control_uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
186 ret
= uri_parse(optarg
, &data_uri
);
188 ERR("Invalid data URI specified");
191 if (data_uri
->port
== 0) {
192 data_uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
196 ret
= uri_parse(optarg
, &live_uri
);
198 ERR("Invalid live URI specified");
201 if (live_uri
->port
== 0) {
202 live_uri
->port
= DEFAULT_NETWORK_VIEWER_PORT
;
209 tracing_group_name
= optarg
;
215 ret
= asprintf(&opt_output_path
, "%s", optarg
);
217 PERROR("asprintf opt_output_path");
222 /* Verbose level can increase using multiple -v */
223 lttng_opt_verbose
+= 1;
226 /* Unknown option or other error.
227 * Error is printed by getopt, just return */
233 /* assign default values */
234 if (control_uri
== NULL
) {
235 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
236 DEFAULT_NETWORK_CONTROL_PORT
);
238 PERROR("asprintf default data address");
242 ret
= uri_parse(default_address
, &control_uri
);
243 free(default_address
);
245 ERR("Invalid control URI specified");
249 if (data_uri
== NULL
) {
250 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
251 DEFAULT_NETWORK_DATA_PORT
);
253 PERROR("asprintf default data address");
257 ret
= uri_parse(default_address
, &data_uri
);
258 free(default_address
);
260 ERR("Invalid data URI specified");
264 if (live_uri
== NULL
) {
265 ret
= asprintf(&default_address
, "tcp://0.0.0.0:%d",
266 DEFAULT_NETWORK_VIEWER_PORT
);
268 PERROR("asprintf default viewer control address");
272 ret
= uri_parse(default_address
, &live_uri
);
273 free(default_address
);
275 ERR("Invalid viewer control URI specified");
292 /* free the dynamically allocated opt_output_path */
293 free(opt_output_path
);
295 /* Close thread quit pipes */
296 utils_close_pipe(thread_quit_pipe
);
298 uri_free(control_uri
);
300 /* Live URI is freed in the live thread. */
304 * Write to writable pipe used to notify a thread.
307 int notify_thread_pipe(int wpipe
)
311 ret
= lttng_write(wpipe
, "!", 1);
313 PERROR("write poll pipe");
319 static void notify_health_quit_pipe(int *pipe
)
323 ret
= lttng_write(pipe
[1], "4", 1);
325 PERROR("write relay health quit");
330 * Stop all threads by closing the thread quit pipe.
333 void stop_threads(void)
337 /* Stopping all threads */
338 DBG("Terminating all threads");
339 ret
= notify_thread_pipe(thread_quit_pipe
[1]);
341 ERR("write error on thread quit pipe");
344 notify_health_quit_pipe(health_quit_pipe
);
346 /* Dispatch thread */
347 CMM_STORE_SHARED(dispatch_thread_exit
, 1);
348 futex_nto1_wake(&relay_cmd_queue
.futex
);
352 * Signal handler for the daemon
354 * Simply stop all worker threads, leaving main() return gracefully after
355 * joining all threads and calling cleanup().
358 void sighandler(int sig
)
362 DBG("SIGPIPE caught");
365 DBG("SIGINT caught");
369 DBG("SIGTERM caught");
378 * Setup signal handler for :
379 * SIGINT, SIGTERM, SIGPIPE
382 int set_signal_handler(void)
388 if ((ret
= sigemptyset(&sigset
)) < 0) {
389 PERROR("sigemptyset");
393 sa
.sa_handler
= sighandler
;
396 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
401 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
406 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
411 DBG("Signal handler set for SIGTERM, SIGPIPE and SIGINT");
417 * Init thread quit pipe.
419 * Return -1 on error or 0 if all pipes are created.
422 int init_thread_quit_pipe(void)
426 ret
= utils_create_pipe_cloexec(thread_quit_pipe
);
432 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
435 int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
439 if (events
== NULL
|| size
== 0) {
444 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
450 ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
);
462 * Check if the thread quit pipe was triggered.
464 * Return 1 if it was triggered else 0;
467 int check_thread_quit_pipe(int fd
, uint32_t events
)
469 if (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) {
477 * Create and init socket from uri.
480 struct lttcomm_sock
*relay_init_sock(struct lttng_uri
*uri
)
483 struct lttcomm_sock
*sock
= NULL
;
485 sock
= lttcomm_alloc_sock_from_uri(uri
);
487 ERR("Allocating socket");
491 ret
= lttcomm_create_sock(sock
);
495 DBG("Listening on sock %d", sock
->fd
);
497 ret
= sock
->ops
->bind(sock
);
502 ret
= sock
->ops
->listen(sock
, -1);
512 lttcomm_destroy_sock(sock
);
518 * Return nonzero if stream needs to be closed.
521 int close_stream_check(struct relay_stream
*stream
)
524 if (stream
->close_flag
&& stream
->prev_seq
== stream
->last_net_seq_num
) {
526 * We are about to close the stream so set the data pending flag to 1
527 * which will make the end data pending command skip the stream which
528 * is now closed and ready. Note that after proceeding to a file close,
529 * the written file is ready for reading.
531 stream
->data_pending_check_done
= 1;
538 * This thread manages the listening for new connections on the network
541 void *relay_thread_listener(void *data
)
543 int i
, ret
, pollfd
, err
= -1;
545 uint32_t revents
, nb_fd
;
546 struct lttng_poll_event events
;
547 struct lttcomm_sock
*control_sock
, *data_sock
;
549 DBG("[thread] Relay listener started");
551 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LISTENER
);
553 health_code_update();
555 control_sock
= relay_init_sock(control_uri
);
557 goto error_sock_control
;
560 data_sock
= relay_init_sock(data_uri
);
562 goto error_sock_relay
;
566 * Pass 3 as size here for the thread quit pipe, control and data socket.
568 ret
= create_thread_poll_set(&events
, 3);
570 goto error_create_poll
;
573 /* Add the control socket */
574 ret
= lttng_poll_add(&events
, control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
579 /* Add the data socket */
580 ret
= lttng_poll_add(&events
, data_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
586 health_code_update();
588 DBG("Listener accepting connections");
592 ret
= lttng_poll_wait(&events
, -1);
596 * Restart interrupted system call.
598 if (errno
== EINTR
) {
606 DBG("Relay new connection received");
607 for (i
= 0; i
< nb_fd
; i
++) {
608 health_code_update();
610 /* Fetch once the poll data */
611 revents
= LTTNG_POLL_GETEV(&events
, i
);
612 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
614 /* Thread quit pipe has been closed. Killing thread. */
615 ret
= check_thread_quit_pipe(pollfd
, revents
);
621 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
622 ERR("socket poll error");
624 } else if (revents
& LPOLLIN
) {
626 * Get allocated in this thread,
627 * enqueued to a global queue, dequeued
628 * and freed in the worker thread.
630 struct relay_command
*relay_cmd
;
631 struct lttcomm_sock
*newsock
;
633 relay_cmd
= zmalloc(sizeof(struct relay_command
));
634 if (relay_cmd
== NULL
) {
635 PERROR("relay command zmalloc");
639 if (pollfd
== data_sock
->fd
) {
640 newsock
= data_sock
->ops
->accept(data_sock
);
642 PERROR("accepting data sock");
646 relay_cmd
->type
= RELAY_DATA
;
647 DBG("Relay data connection accepted, socket %d", newsock
->fd
);
649 assert(pollfd
== control_sock
->fd
);
650 newsock
= control_sock
->ops
->accept(control_sock
);
652 PERROR("accepting control sock");
656 relay_cmd
->type
= RELAY_CONTROL
;
657 DBG("Relay control connection accepted, socket %d", newsock
->fd
);
659 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
,
662 PERROR("setsockopt inet");
663 lttcomm_destroy_sock(newsock
);
667 relay_cmd
->sock
= newsock
;
669 * Lock free enqueue the request.
671 cds_wfq_enqueue(&relay_cmd_queue
.queue
, &relay_cmd
->node
);
674 * Wake the dispatch queue futex. Implicit memory
675 * barrier with the exchange in cds_wfq_enqueue.
677 futex_nto1_wake(&relay_cmd_queue
.futex
);
685 lttng_poll_clean(&events
);
687 if (data_sock
->fd
>= 0) {
688 ret
= data_sock
->ops
->close(data_sock
);
693 lttcomm_destroy_sock(data_sock
);
695 if (control_sock
->fd
>= 0) {
696 ret
= control_sock
->ops
->close(control_sock
);
701 lttcomm_destroy_sock(control_sock
);
705 ERR("Health error occurred in %s", __func__
);
707 health_unregister(health_relayd
);
708 DBG("Relay listener thread cleanup complete");
714 * This thread manages the dispatching of the requests to worker threads
717 void *relay_thread_dispatcher(void *data
)
721 struct cds_wfq_node
*node
;
722 struct relay_command
*relay_cmd
= NULL
;
724 DBG("[thread] Relay dispatcher started");
726 health_register(health_relayd
, HEALTH_RELAYD_TYPE_DISPATCHER
);
728 health_code_update();
730 while (!CMM_LOAD_SHARED(dispatch_thread_exit
)) {
731 health_code_update();
733 /* Atomically prepare the queue futex */
734 futex_nto1_prepare(&relay_cmd_queue
.futex
);
737 health_code_update();
739 /* Dequeue commands */
740 node
= cds_wfq_dequeue_blocking(&relay_cmd_queue
.queue
);
742 DBG("Woken up but nothing in the relay command queue");
743 /* Continue thread execution */
747 relay_cmd
= caa_container_of(node
, struct relay_command
, node
);
748 DBG("Dispatching request waiting on sock %d", relay_cmd
->sock
->fd
);
751 * Inform worker thread of the new request. This
752 * call is blocking so we can be assured that the data will be read
753 * at some point in time or wait to the end of the world :)
755 ret
= lttng_write(relay_cmd_pipe
[1], relay_cmd
,
756 sizeof(struct relay_command
));
758 if (ret
< sizeof(struct relay_command
)) {
759 PERROR("write cmd pipe");
762 } while (node
!= NULL
);
764 /* Futex wait on queue. Blocking call on futex() */
766 futex_nto1_wait(&relay_cmd_queue
.futex
);
770 /* Normal exit, no error */
776 ERR("Health error occurred in %s", __func__
);
778 health_unregister(health_relayd
);
779 DBG("Dispatch thread dying");
785 * Get stream from stream id.
786 * Need to be called with RCU read-side lock held.
788 struct relay_stream
*relay_stream_find_by_id(uint64_t stream_id
)
790 struct lttng_ht_node_ulong
*node
;
791 struct lttng_ht_iter iter
;
792 struct relay_stream
*ret
;
794 lttng_ht_lookup(relay_streams_ht
,
795 (void *)((unsigned long) stream_id
),
797 node
= lttng_ht_iter_get_node_ulong(&iter
);
799 DBG("Relay stream %" PRIu64
" not found", stream_id
);
804 ret
= caa_container_of(node
, struct relay_stream
, stream_n
);
811 void deferred_free_stream(struct rcu_head
*head
)
813 struct relay_stream
*stream
=
814 caa_container_of(head
, struct relay_stream
, rcu_node
);
816 free(stream
->path_name
);
817 free(stream
->channel_name
);
822 void deferred_free_session(struct rcu_head
*head
)
824 struct relay_session
*session
=
825 caa_container_of(head
, struct relay_session
, rcu_node
);
830 * Close a given stream. The stream is freed using a call RCU.
832 * RCU read side lock MUST be acquired. If NO close_stream_check() was called
833 * BEFORE the stream lock MUST be acquired.
835 static void destroy_stream(struct relay_stream
*stream
)
838 struct relay_viewer_stream
*vstream
;
839 struct lttng_ht_iter iter
;
843 delret
= close(stream
->fd
);
845 PERROR("close stream");
848 if (stream
->index_fd
>= 0) {
849 delret
= close(stream
->index_fd
);
851 PERROR("close stream index_fd");
855 vstream
= live_find_viewer_stream_by_id(stream
->stream_handle
);
858 * Set the last good value into the viewer stream. This is done
859 * right before the stream gets deleted from the hash table. The
860 * lookup failure on the live thread side of a stream indicates
861 * that the viewer stream index received value should be used.
863 pthread_mutex_lock(&stream
->viewer_stream_rotation_lock
);
864 vstream
->total_index_received
= stream
->total_index_received
;
865 vstream
->tracefile_count_last
= stream
->tracefile_count_current
;
866 vstream
->close_write_flag
= 1;
867 pthread_mutex_unlock(&stream
->viewer_stream_rotation_lock
);
870 /* Cleanup index of that stream. */
871 relay_index_destroy_by_stream_id(stream
->stream_handle
);
873 iter
.iter
.node
= &stream
->stream_n
.node
;
874 delret
= lttng_ht_del(relay_streams_ht
, &iter
);
876 iter
.iter
.node
= &stream
->ctf_trace_node
.node
;
877 delret
= lttng_ht_del(stream
->ctf_traces_ht
, &iter
);
880 if (stream
->ctf_trace
) {
881 ctf_trace_try_destroy(stream
->ctf_trace
);
884 call_rcu(&stream
->rcu_node
, deferred_free_stream
);
885 DBG("Closed tracefile %d from close stream", stream
->fd
);
889 * relay_delete_session: Free all memory associated with a session and
893 void relay_delete_session(struct relay_command
*cmd
,
894 struct lttng_ht
*sessions_ht
)
896 struct lttng_ht_iter iter
;
897 struct lttng_ht_node_ulong
*node
;
898 struct relay_stream
*stream
;
905 DBG("Relay deleting session %" PRIu64
, cmd
->session
->id
);
908 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, node
, node
) {
909 node
= lttng_ht_iter_get_node_ulong(&iter
);
913 stream
= caa_container_of(node
, struct relay_stream
, stream_n
);
914 if (stream
->session
== cmd
->session
) {
915 destroy_stream(stream
);
916 cmd
->session
->stream_count
--;
917 assert(cmd
->session
->stream_count
>= 0);
921 /* Make this session not visible anymore. */
922 iter
.iter
.node
= &cmd
->session
->session_n
.node
;
923 ret
= lttng_ht_del(sessions_ht
, &iter
);
925 call_rcu(&cmd
->session
->rcu_node
, deferred_free_session
);
930 * Copy index data from the control port to a given index object.
932 static void copy_index_control_data(struct relay_index
*index
,
933 struct lttcomm_relayd_index
*data
)
939 * The index on disk is encoded in big endian, so we don't need to convert
940 * the data received on the network. The data_offset value is NEVER
941 * modified here and is updated by the data thread.
943 index
->index_data
.packet_size
= data
->packet_size
;
944 index
->index_data
.content_size
= data
->content_size
;
945 index
->index_data
.timestamp_begin
= data
->timestamp_begin
;
946 index
->index_data
.timestamp_end
= data
->timestamp_end
;
947 index
->index_data
.events_discarded
= data
->events_discarded
;
948 index
->index_data
.stream_id
= data
->stream_id
;
952 * Handle the RELAYD_CREATE_SESSION command.
954 * On success, send back the session id or else return a negative value.
957 int relay_create_session(struct lttcomm_relayd_hdr
*recv_hdr
,
958 struct relay_command
*cmd
,
959 struct lttng_ht
*sessions_ht
)
961 int ret
= 0, send_ret
;
962 struct relay_session
*session
;
963 struct lttcomm_relayd_status_session reply
;
968 memset(&reply
, 0, sizeof(reply
));
970 session
= zmalloc(sizeof(struct relay_session
));
971 if (session
== NULL
) {
972 PERROR("relay session zmalloc");
977 session
->id
= ++last_relay_session_id
;
978 session
->sock
= cmd
->sock
;
979 session
->minor
= cmd
->minor
;
980 session
->major
= cmd
->major
;
981 cmd
->session
= session
;
983 reply
.session_id
= htobe64(session
->id
);
985 switch (cmd
->minor
) {
986 case 4: /* LTTng sessiond 2.4 */
988 ret
= cmd_create_session_2_4(cmd
, session
);
992 lttng_ht_node_init_ulong(&session
->session_n
,
993 (unsigned long) session
->id
);
994 lttng_ht_add_unique_ulong(sessions_ht
,
995 &session
->session_n
);
997 DBG("Created session %" PRIu64
, session
->id
);
1001 reply
.ret_code
= htobe32(LTTNG_ERR_FATAL
);
1003 reply
.ret_code
= htobe32(LTTNG_OK
);
1006 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1008 ERR("Relayd sending session id");
1016 * When we have received all the streams and the metadata for a channel,
1017 * we make them visible to the viewer threads.
1020 void set_viewer_ready_flag(struct relay_command
*cmd
)
1022 struct relay_stream_recv_handle
*node
, *tmp_node
;
1024 cds_list_for_each_entry_safe(node
, tmp_node
, &cmd
->recv_head
, node
) {
1025 struct relay_stream
*stream
;
1028 stream
= relay_stream_find_by_id(node
->id
);
1031 * Stream is most probably being cleaned up by the data thread thus
1032 * simply continue to the next one.
1038 stream
->viewer_ready
= 1;
1041 /* Clean stream handle node. */
1042 cds_list_del(&node
->node
);
1050 * Add a recv handle node to the connection recv list with the given stream
1051 * handle. A new node is allocated thus must be freed when the node is deleted
1054 static void queue_stream_handle(uint64_t handle
, struct relay_command
*cmd
)
1056 struct relay_stream_recv_handle
*node
;
1060 node
= zmalloc(sizeof(*node
));
1062 PERROR("zmalloc queue stream handle");
1067 cds_list_add(&node
->node
, &cmd
->recv_head
);
1071 * relay_add_stream: allocate a new stream for a session
1074 int relay_add_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1075 struct relay_command
*cmd
, struct lttng_ht
*sessions_ht
)
1077 struct relay_session
*session
= cmd
->session
;
1078 struct relay_stream
*stream
= NULL
;
1079 struct lttcomm_relayd_status_stream reply
;
1082 if (!session
|| cmd
->version_check_done
== 0) {
1083 ERR("Trying to add a stream before version check");
1085 goto end_no_session
;
1088 stream
= zmalloc(sizeof(struct relay_stream
));
1089 if (stream
== NULL
) {
1090 PERROR("relay stream zmalloc");
1092 goto end_no_session
;
1095 switch (cmd
->minor
) {
1096 case 1: /* LTTng sessiond 2.1 */
1097 ret
= cmd_recv_stream_2_1(cmd
, stream
);
1099 case 2: /* LTTng sessiond 2.2 */
1101 ret
= cmd_recv_stream_2_2(cmd
, stream
);
1105 goto err_free_stream
;
1109 stream
->stream_handle
= ++last_relay_stream_id
;
1110 stream
->prev_seq
= -1ULL;
1111 stream
->session
= session
;
1112 stream
->index_fd
= -1;
1113 stream
->read_index_fd
= -1;
1114 stream
->ctf_trace
= NULL
;
1115 pthread_mutex_init(&stream
->lock
, NULL
);
1117 ret
= utils_mkdir_recursive(stream
->path_name
, S_IRWXU
| S_IRWXG
);
1119 ERR("relay creating output directory");
1124 * No need to use run_as API here because whatever we receives, the relayd
1125 * uses its own credentials for the stream files.
1127 ret
= utils_create_stream_file(stream
->path_name
, stream
->channel_name
,
1128 stream
->tracefile_size
, 0, relayd_uid
, relayd_gid
, NULL
);
1130 ERR("Create output file");
1134 if (stream
->tracefile_size
) {
1135 DBG("Tracefile %s/%s_0 created", stream
->path_name
, stream
->channel_name
);
1137 DBG("Tracefile %s/%s created", stream
->path_name
, stream
->channel_name
);
1140 if (!strncmp(stream
->channel_name
, DEFAULT_METADATA_NAME
, NAME_MAX
)) {
1141 stream
->metadata_flag
= 1;
1143 * When we receive a new metadata stream, we create a new
1144 * ctf_trace and we assign this ctf_trace to all streams with
1147 * If later on we receive a new stream for the same ctf_trace,
1148 * we copy the information from the first hit in the HT to the
1151 stream
->ctf_trace
= ctf_trace_create();
1152 if (!stream
->ctf_trace
) {
1156 stream
->ctf_trace
->refcount
++;
1157 stream
->ctf_trace
->metadata_stream
= stream
;
1159 ctf_trace_assign(cmd
->ctf_traces_ht
, stream
);
1160 stream
->ctf_traces_ht
= cmd
->ctf_traces_ht
;
1163 * Add the stream handle in the recv list of the connection. Once the end
1164 * stream message is received, this list is emptied and streams are set
1165 * with the viewer ready flag.
1167 if (stream
->metadata_flag
) {
1168 stream
->viewer_ready
= 1;
1170 queue_stream_handle(stream
->stream_handle
, cmd
);
1173 lttng_ht_node_init_ulong(&stream
->stream_n
,
1174 (unsigned long) stream
->stream_handle
);
1175 lttng_ht_add_unique_ulong(relay_streams_ht
,
1178 lttng_ht_node_init_str(&stream
->ctf_trace_node
, stream
->path_name
);
1179 lttng_ht_add_str(cmd
->ctf_traces_ht
, &stream
->ctf_trace_node
);
1180 session
->stream_count
++;
1182 DBG("Relay new stream added %s with ID %" PRIu64
, stream
->channel_name
,
1183 stream
->stream_handle
);
1186 reply
.handle
= htobe64(stream
->stream_handle
);
1187 /* send the session id to the client or a negative return code on error */
1189 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1190 /* stream was not properly added to the ht, so free it */
1193 reply
.ret_code
= htobe32(LTTNG_OK
);
1196 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1197 sizeof(struct lttcomm_relayd_status_stream
), 0);
1199 ERR("Relay sending stream id");
1208 free(stream
->path_name
);
1209 free(stream
->channel_name
);
1215 * relay_close_stream: close a specific stream
1218 int relay_close_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1219 struct relay_command
*cmd
)
1222 struct relay_session
*session
= cmd
->session
;
1223 struct lttcomm_relayd_close_stream stream_info
;
1224 struct lttcomm_relayd_generic_reply reply
;
1225 struct relay_stream
*stream
;
1227 DBG("Close stream received");
1229 if (!session
|| cmd
->version_check_done
== 0) {
1230 ERR("Trying to close a stream before version check");
1232 goto end_no_session
;
1235 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &stream_info
,
1236 sizeof(struct lttcomm_relayd_close_stream
), 0);
1237 if (ret
< sizeof(struct lttcomm_relayd_close_stream
)) {
1239 /* Orderly shutdown. Not necessary to print an error. */
1240 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1242 ERR("Relay didn't receive valid add_stream struct size : %d", ret
);
1245 goto end_no_session
;
1249 stream
= relay_stream_find_by_id(be64toh(stream_info
.stream_id
));
1255 stream
->last_net_seq_num
= be64toh(stream_info
.last_net_seq_num
);
1256 stream
->close_flag
= 1;
1257 session
->stream_count
--;
1258 assert(session
->stream_count
>= 0);
1260 if (close_stream_check(stream
)) {
1261 destroy_stream(stream
);
1268 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1270 reply
.ret_code
= htobe32(LTTNG_OK
);
1272 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1273 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1275 ERR("Relay sending stream id");
1284 * relay_unknown_command: send -1 if received unknown command
1287 void relay_unknown_command(struct relay_command
*cmd
)
1289 struct lttcomm_relayd_generic_reply reply
;
1292 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1293 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1294 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1296 ERR("Relay sending unknown command");
1301 * relay_start: send an acknowledgment to the client to tell if we are
1302 * ready to receive data. We are ready if a session is established.
1305 int relay_start(struct lttcomm_relayd_hdr
*recv_hdr
,
1306 struct relay_command
*cmd
)
1308 int ret
= htobe32(LTTNG_OK
);
1309 struct lttcomm_relayd_generic_reply reply
;
1310 struct relay_session
*session
= cmd
->session
;
1313 DBG("Trying to start the streaming without a session established");
1314 ret
= htobe32(LTTNG_ERR_UNK
);
1317 reply
.ret_code
= ret
;
1318 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1319 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1321 ERR("Relay sending start ack");
1328 * Append padding to the file pointed by the file descriptor fd.
1330 static int write_padding_to_file(int fd
, uint32_t size
)
1339 zeros
= zmalloc(size
);
1340 if (zeros
== NULL
) {
1341 PERROR("zmalloc zeros for padding");
1346 ret
= lttng_write(fd
, zeros
, size
);
1348 PERROR("write padding to file");
1358 * relay_recv_metadata: receive the metada for the session.
1361 int relay_recv_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1362 struct relay_command
*cmd
)
1364 int ret
= htobe32(LTTNG_OK
);
1366 struct relay_session
*session
= cmd
->session
;
1367 struct lttcomm_relayd_metadata_payload
*metadata_struct
;
1368 struct relay_stream
*metadata_stream
;
1369 uint64_t data_size
, payload_size
;
1372 ERR("Metadata sent before version check");
1377 data_size
= payload_size
= be64toh(recv_hdr
->data_size
);
1378 if (data_size
< sizeof(struct lttcomm_relayd_metadata_payload
)) {
1379 ERR("Incorrect data size");
1383 payload_size
-= sizeof(struct lttcomm_relayd_metadata_payload
);
1385 if (data_buffer_size
< data_size
) {
1386 /* In case the realloc fails, we can free the memory */
1389 tmp_data_ptr
= realloc(data_buffer
, data_size
);
1390 if (!tmp_data_ptr
) {
1391 ERR("Allocating data buffer");
1396 data_buffer
= tmp_data_ptr
;
1397 data_buffer_size
= data_size
;
1399 memset(data_buffer
, 0, data_size
);
1400 DBG2("Relay receiving metadata, waiting for %" PRIu64
" bytes", data_size
);
1401 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, data_buffer
, data_size
, 0);
1402 if (ret
< 0 || ret
!= data_size
) {
1404 /* Orderly shutdown. Not necessary to print an error. */
1405 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1407 ERR("Relay didn't receive the whole metadata");
1412 metadata_struct
= (struct lttcomm_relayd_metadata_payload
*) data_buffer
;
1415 metadata_stream
= relay_stream_find_by_id(
1416 be64toh(metadata_struct
->stream_id
));
1417 if (!metadata_stream
) {
1422 size_ret
= lttng_write(metadata_stream
->fd
, metadata_struct
->payload
,
1424 if (size_ret
< payload_size
) {
1425 ERR("Relay error writing metadata on file");
1430 ret
= write_padding_to_file(metadata_stream
->fd
,
1431 be32toh(metadata_struct
->padding_size
));
1435 metadata_stream
->ctf_trace
->metadata_received
+=
1436 payload_size
+ be32toh(metadata_struct
->padding_size
);
1438 DBG2("Relay metadata written");
1447 * relay_send_version: send relayd version number
1450 int relay_send_version(struct lttcomm_relayd_hdr
*recv_hdr
,
1451 struct relay_command
*cmd
, struct lttng_ht
*sessions_ht
)
1454 struct lttcomm_relayd_version reply
, msg
;
1458 cmd
->version_check_done
= 1;
1460 /* Get version from the other side. */
1461 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1462 if (ret
< 0 || ret
!= sizeof(msg
)) {
1464 /* Orderly shutdown. Not necessary to print an error. */
1465 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1467 ERR("Relay failed to receive the version values.");
1473 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
1474 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
1476 /* Major versions must be the same */
1477 if (reply
.major
!= be32toh(msg
.major
)) {
1478 DBG("Incompatible major versions (%u vs %u), deleting session",
1479 reply
.major
, be32toh(msg
.major
));
1480 relay_delete_session(cmd
, sessions_ht
);
1485 cmd
->major
= reply
.major
;
1486 /* We adapt to the lowest compatible version */
1487 if (reply
.minor
<= be32toh(msg
.minor
)) {
1488 cmd
->minor
= reply
.minor
;
1490 cmd
->minor
= be32toh(msg
.minor
);
1493 reply
.major
= htobe32(reply
.major
);
1494 reply
.minor
= htobe32(reply
.minor
);
1495 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
,
1496 sizeof(struct lttcomm_relayd_version
), 0);
1498 ERR("Relay sending version");
1501 DBG("Version check done using protocol %u.%u", cmd
->major
,
1509 * Check for data pending for a given stream id from the session daemon.
1512 int relay_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1513 struct relay_command
*cmd
)
1515 struct relay_session
*session
= cmd
->session
;
1516 struct lttcomm_relayd_data_pending msg
;
1517 struct lttcomm_relayd_generic_reply reply
;
1518 struct relay_stream
*stream
;
1520 uint64_t last_net_seq_num
, stream_id
;
1522 DBG("Data pending command received");
1524 if (!session
|| cmd
->version_check_done
== 0) {
1525 ERR("Trying to check for data before version check");
1527 goto end_no_session
;
1530 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1531 if (ret
< sizeof(msg
)) {
1533 /* Orderly shutdown. Not necessary to print an error. */
1534 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1536 ERR("Relay didn't receive valid data_pending struct size : %d",
1540 goto end_no_session
;
1543 stream_id
= be64toh(msg
.stream_id
);
1544 last_net_seq_num
= be64toh(msg
.last_net_seq_num
);
1547 stream
= relay_stream_find_by_id(stream_id
);
1548 if (stream
== NULL
) {
1553 DBG("Data pending for stream id %" PRIu64
" prev_seq %" PRIu64
1554 " and last_seq %" PRIu64
, stream_id
, stream
->prev_seq
,
1557 /* Avoid wrapping issue */
1558 if (((int64_t) (stream
->prev_seq
- last_net_seq_num
)) >= 0) {
1559 /* Data has in fact been written and is NOT pending */
1562 /* Data still being streamed thus pending */
1566 /* Pending check is now done. */
1567 stream
->data_pending_check_done
= 1;
1572 reply
.ret_code
= htobe32(ret
);
1573 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1575 ERR("Relay data pending ret code failed");
1583 * Wait for the control socket to reach a quiescent state.
1585 * Note that for now, when receiving this command from the session daemon, this
1586 * means that every subsequent commands or data received on the control socket
1587 * has been handled. So, this is why we simply return OK here.
1590 int relay_quiescent_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1591 struct relay_command
*cmd
)
1595 struct relay_stream
*stream
;
1596 struct lttng_ht_iter iter
;
1597 struct lttcomm_relayd_quiescent_control msg
;
1598 struct lttcomm_relayd_generic_reply reply
;
1600 DBG("Checking quiescent state on control socket");
1602 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1603 ERR("Trying to check for data before version check");
1605 goto end_no_session
;
1608 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1609 if (ret
< sizeof(msg
)) {
1611 /* Orderly shutdown. Not necessary to print an error. */
1612 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1614 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1618 goto end_no_session
;
1621 stream_id
= be64toh(msg
.stream_id
);
1624 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1626 if (stream
->stream_handle
== stream_id
) {
1627 stream
->data_pending_check_done
= 1;
1628 DBG("Relay quiescent control pending flag set to %" PRIu64
,
1635 reply
.ret_code
= htobe32(LTTNG_OK
);
1636 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1638 ERR("Relay data quiescent control ret code failed");
1646 * Initialize a data pending command. This means that a client is about to ask
1647 * for data pending for each stream he/she holds. Simply iterate over all
1648 * streams of a session and set the data_pending_check_done flag.
1650 * This command returns to the client a LTTNG_OK code.
1653 int relay_begin_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1654 struct relay_command
*cmd
)
1657 struct lttng_ht_iter iter
;
1658 struct lttcomm_relayd_begin_data_pending msg
;
1659 struct lttcomm_relayd_generic_reply reply
;
1660 struct relay_stream
*stream
;
1661 uint64_t session_id
;
1666 DBG("Init streams for data pending");
1668 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1669 ERR("Trying to check for data before version check");
1671 goto end_no_session
;
1674 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1675 if (ret
< sizeof(msg
)) {
1677 /* Orderly shutdown. Not necessary to print an error. */
1678 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1680 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1684 goto end_no_session
;
1687 session_id
= be64toh(msg
.session_id
);
1690 * Iterate over all streams to set the begin data pending flag. For now, the
1691 * streams are indexed by stream handle so we have to iterate over all
1692 * streams to find the one associated with the right session_id.
1695 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1697 if (stream
->session
->id
== session_id
) {
1698 stream
->data_pending_check_done
= 0;
1699 DBG("Set begin data pending flag to stream %" PRIu64
,
1700 stream
->stream_handle
);
1705 /* All good, send back reply. */
1706 reply
.ret_code
= htobe32(LTTNG_OK
);
1708 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1710 ERR("Relay begin data pending send reply failed");
1718 * End data pending command. This will check, for a given session id, if each
1719 * stream associated with it has its data_pending_check_done flag set. If not,
1720 * this means that the client lost track of the stream but the data is still
1721 * being streamed on our side. In this case, we inform the client that data is
1724 * Return to the client if there is data in flight or not with a ret_code.
1727 int relay_end_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1728 struct relay_command
*cmd
)
1731 struct lttng_ht_iter iter
;
1732 struct lttcomm_relayd_end_data_pending msg
;
1733 struct lttcomm_relayd_generic_reply reply
;
1734 struct relay_stream
*stream
;
1735 uint64_t session_id
;
1736 uint32_t is_data_inflight
= 0;
1741 DBG("End data pending command");
1743 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1744 ERR("Trying to check for data before version check");
1746 goto end_no_session
;
1749 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &msg
, sizeof(msg
), 0);
1750 if (ret
< sizeof(msg
)) {
1752 /* Orderly shutdown. Not necessary to print an error. */
1753 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1755 ERR("Relay didn't receive valid end data_pending struct size: %d",
1759 goto end_no_session
;
1762 session_id
= be64toh(msg
.session_id
);
1764 /* Iterate over all streams to see if the begin data pending flag is set. */
1766 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1768 if (stream
->session
->id
== session_id
&&
1769 !stream
->data_pending_check_done
) {
1770 is_data_inflight
= 1;
1771 DBG("Data is still in flight for stream %" PRIu64
,
1772 stream
->stream_handle
);
1778 /* All good, send back reply. */
1779 reply
.ret_code
= htobe32(is_data_inflight
);
1781 ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1783 ERR("Relay end data pending send reply failed");
1791 * Receive an index for a specific stream.
1793 * Return 0 on success else a negative value.
1796 int relay_recv_index(struct lttcomm_relayd_hdr
*recv_hdr
,
1797 struct relay_command
*cmd
)
1799 int ret
, send_ret
, index_created
= 0;
1800 struct relay_session
*session
= cmd
->session
;
1801 struct lttcomm_relayd_index index_info
;
1802 struct relay_index
*index
, *wr_index
= NULL
;
1803 struct lttcomm_relayd_generic_reply reply
;
1804 struct relay_stream
*stream
;
1805 uint64_t net_seq_num
;
1809 DBG("Relay receiving index");
1811 if (!session
|| cmd
->version_check_done
== 0) {
1812 ERR("Trying to close a stream before version check");
1814 goto end_no_session
;
1817 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &index_info
,
1818 sizeof(index_info
), 0);
1819 if (ret
< sizeof(index_info
)) {
1821 /* Orderly shutdown. Not necessary to print an error. */
1822 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
1824 ERR("Relay didn't receive valid index struct size : %d", ret
);
1827 goto end_no_session
;
1830 net_seq_num
= be64toh(index_info
.net_seq_num
);
1833 stream
= relay_stream_find_by_id(be64toh(index_info
.relay_stream_id
));
1836 goto end_rcu_unlock
;
1839 /* Live beacon handling */
1840 if (index_info
.packet_size
== 0) {
1841 DBG("Received live beacon for stream %" PRIu64
, stream
->stream_handle
);
1844 * Only flag a stream inactive when it has already received data.
1846 if (stream
->total_index_received
> 0) {
1847 stream
->beacon_ts_end
= be64toh(index_info
.timestamp_end
);
1850 goto end_rcu_unlock
;
1852 stream
->beacon_ts_end
= -1ULL;
1855 index
= relay_index_find(stream
->stream_handle
, net_seq_num
);
1857 /* A successful creation will add the object to the HT. */
1858 index
= relay_index_create(stream
->stream_handle
, net_seq_num
);
1860 goto end_rcu_unlock
;
1865 copy_index_control_data(index
, &index_info
);
1867 if (index_created
) {
1869 * Try to add the relay index object to the hash table. If an object
1870 * already exist, destroy back the index created, set the data in this
1871 * object and write it on disk.
1873 relay_index_add(index
, &wr_index
);
1875 copy_index_control_data(wr_index
, &index_info
);
1879 /* The index already exists so write it on disk. */
1883 /* Do we have a writable ready index to write on disk. */
1885 /* Starting at 2.4, create the index file if none available. */
1886 if (cmd
->minor
>= 4 && stream
->index_fd
< 0) {
1887 ret
= index_create_file(stream
->path_name
, stream
->channel_name
,
1888 relayd_uid
, relayd_gid
, stream
->tracefile_size
,
1889 stream
->tracefile_count_current
);
1891 goto end_rcu_unlock
;
1893 stream
->index_fd
= ret
;
1896 ret
= relay_index_write(wr_index
->fd
, wr_index
);
1898 goto end_rcu_unlock
;
1900 stream
->total_index_received
++;
1907 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1909 reply
.ret_code
= htobe32(LTTNG_OK
);
1911 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1913 ERR("Relay sending close index id reply");
1922 * Receive the streams_sent message.
1924 * Return 0 on success else a negative value.
1927 int relay_streams_sent(struct lttcomm_relayd_hdr
*recv_hdr
,
1928 struct relay_command
*cmd
)
1931 struct lttcomm_relayd_generic_reply reply
;
1935 DBG("Relay receiving streams_sent");
1937 if (!cmd
->session
|| cmd
->version_check_done
== 0) {
1938 ERR("Trying to close a stream before version check");
1940 goto end_no_session
;
1944 * Flag every pending stream in the connection recv list that they are
1945 * ready to be used by the viewer.
1947 set_viewer_ready_flag(cmd
);
1949 reply
.ret_code
= htobe32(LTTNG_OK
);
1950 send_ret
= cmd
->sock
->ops
->sendmsg(cmd
->sock
, &reply
, sizeof(reply
), 0);
1952 ERR("Relay sending sent_stream reply");
1964 * Process the commands received on the control socket
1967 int relay_process_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1968 struct relay_command
*cmd
, struct relay_local_data
*ctx
)
1972 switch (be32toh(recv_hdr
->cmd
)) {
1973 case RELAYD_CREATE_SESSION
:
1974 ret
= relay_create_session(recv_hdr
, cmd
, ctx
->sessions_ht
);
1976 case RELAYD_ADD_STREAM
:
1977 ret
= relay_add_stream(recv_hdr
, cmd
, ctx
->sessions_ht
);
1979 case RELAYD_START_DATA
:
1980 ret
= relay_start(recv_hdr
, cmd
);
1982 case RELAYD_SEND_METADATA
:
1983 ret
= relay_recv_metadata(recv_hdr
, cmd
);
1985 case RELAYD_VERSION
:
1986 ret
= relay_send_version(recv_hdr
, cmd
, ctx
->sessions_ht
);
1988 case RELAYD_CLOSE_STREAM
:
1989 ret
= relay_close_stream(recv_hdr
, cmd
);
1991 case RELAYD_DATA_PENDING
:
1992 ret
= relay_data_pending(recv_hdr
, cmd
);
1994 case RELAYD_QUIESCENT_CONTROL
:
1995 ret
= relay_quiescent_control(recv_hdr
, cmd
);
1997 case RELAYD_BEGIN_DATA_PENDING
:
1998 ret
= relay_begin_data_pending(recv_hdr
, cmd
);
2000 case RELAYD_END_DATA_PENDING
:
2001 ret
= relay_end_data_pending(recv_hdr
, cmd
);
2003 case RELAYD_SEND_INDEX
:
2004 ret
= relay_recv_index(recv_hdr
, cmd
);
2006 case RELAYD_STREAMS_SENT
:
2007 ret
= relay_streams_sent(recv_hdr
, cmd
);
2009 case RELAYD_UPDATE_SYNC_INFO
:
2011 ERR("Received unknown command (%u)", be32toh(recv_hdr
->cmd
));
2012 relay_unknown_command(cmd
);
2022 * Handle index for a data stream.
2024 * RCU read side lock MUST be acquired.
2026 * Return 0 on success else a negative value.
2028 static int handle_index_data(struct relay_stream
*stream
, uint64_t net_seq_num
,
2031 int ret
= 0, index_created
= 0;
2032 uint64_t stream_id
, data_offset
;
2033 struct relay_index
*index
, *wr_index
= NULL
;
2037 stream_id
= stream
->stream_handle
;
2038 /* Get data offset because we are about to update the index. */
2039 data_offset
= htobe64(stream
->tracefile_size_current
);
2042 * Lookup for an existing index for that stream id/sequence number. If on
2043 * exists, the control thread already received the data for it thus we need
2044 * to write it on disk.
2046 index
= relay_index_find(stream_id
, net_seq_num
);
2048 /* A successful creation will add the object to the HT. */
2049 index
= relay_index_create(stream_id
, net_seq_num
);
2057 if (rotate_index
|| stream
->index_fd
< 0) {
2058 index
->to_close_fd
= stream
->index_fd
;
2059 ret
= index_create_file(stream
->path_name
, stream
->channel_name
,
2060 relayd_uid
, relayd_gid
, stream
->tracefile_size
,
2061 stream
->tracefile_count_current
);
2063 /* This will close the stream's index fd if one. */
2064 relay_index_free_safe(index
);
2067 stream
->index_fd
= ret
;
2069 index
->fd
= stream
->index_fd
;
2070 index
->index_data
.offset
= data_offset
;
2072 if (index_created
) {
2074 * Try to add the relay index object to the hash table. If an object
2075 * already exist, destroy back the index created and set the data.
2077 relay_index_add(index
, &wr_index
);
2079 /* Copy back data from the created index. */
2080 wr_index
->fd
= index
->fd
;
2081 wr_index
->to_close_fd
= index
->to_close_fd
;
2082 wr_index
->index_data
.offset
= data_offset
;
2086 /* The index already exists so write it on disk. */
2090 /* Do we have a writable ready index to write on disk. */
2092 ret
= relay_index_write(wr_index
->fd
, wr_index
);
2096 stream
->total_index_received
++;
2104 * relay_process_data: Process the data received on the data socket
2107 int relay_process_data(struct relay_command
*cmd
)
2109 int ret
= 0, rotate_index
= 0;
2111 struct relay_stream
*stream
;
2112 struct lttcomm_relayd_data_hdr data_hdr
;
2114 uint64_t net_seq_num
;
2117 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, &data_hdr
,
2118 sizeof(struct lttcomm_relayd_data_hdr
), 0);
2121 /* Orderly shutdown. Not necessary to print an error. */
2122 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
2124 ERR("Unable to receive data header on sock %d", cmd
->sock
->fd
);
2130 stream_id
= be64toh(data_hdr
.stream_id
);
2133 stream
= relay_stream_find_by_id(stream_id
);
2136 goto end_rcu_unlock
;
2139 data_size
= be32toh(data_hdr
.data_size
);
2140 if (data_buffer_size
< data_size
) {
2143 tmp_data_ptr
= realloc(data_buffer
, data_size
);
2144 if (!tmp_data_ptr
) {
2145 ERR("Allocating data buffer");
2148 goto end_rcu_unlock
;
2150 data_buffer
= tmp_data_ptr
;
2151 data_buffer_size
= data_size
;
2153 memset(data_buffer
, 0, data_size
);
2155 net_seq_num
= be64toh(data_hdr
.net_seq_num
);
2157 DBG3("Receiving data of size %u for stream id %" PRIu64
" seqnum %" PRIu64
,
2158 data_size
, stream_id
, net_seq_num
);
2159 ret
= cmd
->sock
->ops
->recvmsg(cmd
->sock
, data_buffer
, data_size
, 0);
2162 /* Orderly shutdown. Not necessary to print an error. */
2163 DBG("Socket %d did an orderly shutdown", cmd
->sock
->fd
);
2166 goto end_rcu_unlock
;
2169 /* Check if a rotation is needed. */
2170 if (stream
->tracefile_size
> 0 &&
2171 (stream
->tracefile_size_current
+ data_size
) >
2172 stream
->tracefile_size
) {
2173 struct relay_viewer_stream
*vstream
;
2176 new_id
= (stream
->tracefile_count_current
+ 1) %
2177 stream
->tracefile_count
;
2179 * When we wrap-around back to 0, we start overwriting old
2182 if (!stream
->tracefile_overwrite
&& new_id
== 0) {
2183 stream
->tracefile_overwrite
= 1;
2185 pthread_mutex_lock(&stream
->viewer_stream_rotation_lock
);
2186 if (stream
->tracefile_overwrite
) {
2187 stream
->oldest_tracefile_id
=
2188 (stream
->oldest_tracefile_id
+ 1) %
2189 stream
->tracefile_count
;
2191 vstream
= live_find_viewer_stream_by_id(stream
->stream_handle
);
2194 * The viewer is reading a file about to be
2195 * overwritten. Close the FDs it is
2196 * currently using and let it handle the fault.
2198 if (vstream
->tracefile_count_current
== new_id
) {
2199 pthread_mutex_lock(&vstream
->overwrite_lock
);
2200 vstream
->abort_flag
= 1;
2201 pthread_mutex_unlock(&vstream
->overwrite_lock
);
2202 DBG("Streaming side setting abort_flag on stream %s_%lu\n",
2203 stream
->channel_name
, new_id
);
2204 } else if (vstream
->tracefile_count_current
==
2205 stream
->tracefile_count_current
) {
2207 * The reader and writer were in the
2208 * same trace file, inform the viewer
2209 * that no new index will ever be added
2212 vstream
->close_write_flag
= 1;
2215 ret
= utils_rotate_stream_file(stream
->path_name
, stream
->channel_name
,
2216 stream
->tracefile_size
, stream
->tracefile_count
,
2217 relayd_uid
, relayd_gid
, stream
->fd
,
2218 &(stream
->tracefile_count_current
), &stream
->fd
);
2219 stream
->total_index_received
= 0;
2220 pthread_mutex_unlock(&stream
->viewer_stream_rotation_lock
);
2222 ERR("Rotating stream output file");
2223 goto end_rcu_unlock
;
2225 /* Reset current size because we just perform a stream rotation. */
2226 stream
->tracefile_size_current
= 0;
2231 * Index are handled in protocol version 2.4 and above. Also, snapshot and
2232 * index are NOT supported.
2234 if (stream
->session
->minor
>= 4 && !stream
->session
->snapshot
) {
2235 ret
= handle_index_data(stream
, net_seq_num
, rotate_index
);
2237 goto end_rcu_unlock
;
2241 /* Write data to stream output fd. */
2242 size_ret
= lttng_write(stream
->fd
, data_buffer
, data_size
);
2243 if (size_ret
< data_size
) {
2244 ERR("Relay error writing data to file");
2246 goto end_rcu_unlock
;
2249 DBG2("Relay wrote %d bytes to tracefile for stream id %" PRIu64
,
2250 ret
, stream
->stream_handle
);
2252 ret
= write_padding_to_file(stream
->fd
, be32toh(data_hdr
.padding_size
));
2254 goto end_rcu_unlock
;
2256 stream
->tracefile_size_current
+= data_size
+ be32toh(data_hdr
.padding_size
);
2258 stream
->prev_seq
= net_seq_num
;
2260 /* Check if we need to close the FD */
2261 if (close_stream_check(stream
)) {
2262 destroy_stream(stream
);
2272 void relay_cleanup_poll_connection(struct lttng_poll_event
*events
, int pollfd
)
2276 lttng_poll_del(events
, pollfd
);
2278 ret
= close(pollfd
);
2280 ERR("Closing pollfd %d", pollfd
);
2285 int relay_add_connection(int fd
, struct lttng_poll_event
*events
,
2286 struct lttng_ht
*relay_connections_ht
)
2288 struct relay_command
*relay_connection
;
2291 relay_connection
= zmalloc(sizeof(struct relay_command
));
2292 if (relay_connection
== NULL
) {
2293 PERROR("Relay command zmalloc");
2296 ret
= lttng_read(fd
, relay_connection
, sizeof(struct relay_command
));
2297 if (ret
< sizeof(struct relay_command
)) {
2298 PERROR("read relay cmd pipe");
2301 CDS_INIT_LIST_HEAD(&relay_connection
->recv_head
);
2304 * Only used by the control side and the reference is copied inside each
2305 * stream from that connection. Thus a destroy HT must be done after every
2306 * stream has been destroyed.
2308 if (relay_connection
->type
== RELAY_CONTROL
) {
2309 relay_connection
->ctf_traces_ht
= lttng_ht_new(0,
2310 LTTNG_HT_TYPE_STRING
);
2311 if (!relay_connection
->ctf_traces_ht
) {
2316 lttng_ht_node_init_ulong(&relay_connection
->sock_n
,
2317 (unsigned long) relay_connection
->sock
->fd
);
2319 lttng_ht_add_unique_ulong(relay_connections_ht
,
2320 &relay_connection
->sock_n
);
2322 return lttng_poll_add(events
,
2323 relay_connection
->sock
->fd
,
2324 LPOLLIN
| LPOLLRDHUP
);
2327 free(relay_connection
);
2333 void deferred_free_connection(struct rcu_head
*head
)
2335 struct relay_command
*relay_connection
=
2336 caa_container_of(head
, struct relay_command
, rcu_node
);
2338 lttcomm_destroy_sock(relay_connection
->sock
);
2339 free(relay_connection
);
2343 void relay_del_connection(struct lttng_ht
*relay_connections_ht
,
2344 struct lttng_ht_iter
*iter
, struct relay_command
*relay_connection
,
2345 struct lttng_ht
*sessions_ht
)
2349 ret
= lttng_ht_del(relay_connections_ht
, iter
);
2352 if (relay_connection
->type
== RELAY_CONTROL
) {
2353 struct relay_stream_recv_handle
*node
, *tmp_node
;
2355 relay_delete_session(relay_connection
, sessions_ht
);
2356 lttng_ht_destroy(relay_connection
->ctf_traces_ht
);
2358 /* Clean up recv list. */
2359 cds_list_for_each_entry_safe(node
, tmp_node
,
2360 &relay_connection
->recv_head
, node
) {
2361 cds_list_del(&node
->node
);
2366 call_rcu(&relay_connection
->rcu_node
, deferred_free_connection
);
2370 * This thread does the actual work
2373 void *relay_thread_worker(void *data
)
2375 int ret
, err
= -1, last_seen_data_fd
= -1;
2377 struct relay_command
*relay_connection
;
2378 struct lttng_poll_event events
;
2379 struct lttng_ht
*relay_connections_ht
;
2380 struct lttng_ht_node_ulong
*node
;
2381 struct lttng_ht_iter iter
;
2382 struct lttcomm_relayd_hdr recv_hdr
;
2383 struct relay_local_data
*relay_ctx
= (struct relay_local_data
*) data
;
2384 struct lttng_ht
*sessions_ht
= relay_ctx
->sessions_ht
;
2386 DBG("[thread] Relay worker started");
2388 rcu_register_thread();
2390 health_register(health_relayd
, HEALTH_RELAYD_TYPE_WORKER
);
2392 health_code_update();
2394 /* table of connections indexed on socket */
2395 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2396 if (!relay_connections_ht
) {
2397 goto relay_connections_ht_error
;
2400 /* Tables of received indexes indexed by index handle and net_seq_num. */
2401 indexes_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_TWO_U64
);
2403 goto indexes_ht_error
;
2406 ret
= create_thread_poll_set(&events
, 2);
2408 goto error_poll_create
;
2411 ret
= lttng_poll_add(&events
, relay_cmd_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
2418 int idx
= -1, i
, seen_control
= 0, last_notdel_data_fd
= -1;
2420 health_code_update();
2422 /* Infinite blocking call, waiting for transmission */
2423 DBG3("Relayd worker thread polling...");
2424 health_poll_entry();
2425 ret
= lttng_poll_wait(&events
, -1);
2429 * Restart interrupted system call.
2431 if (errno
== EINTR
) {
2440 * Process control. The control connection is prioritised so we don't
2441 * starve it with high throughout put tracing data on the data
2444 for (i
= 0; i
< nb_fd
; i
++) {
2445 /* Fetch once the poll data */
2446 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2447 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2449 health_code_update();
2451 /* Thread quit pipe has been closed. Killing thread. */
2452 ret
= check_thread_quit_pipe(pollfd
, revents
);
2458 /* Inspect the relay cmd pipe for new connection */
2459 if (pollfd
== relay_cmd_pipe
[0]) {
2460 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2461 ERR("Relay pipe error");
2463 } else if (revents
& LPOLLIN
) {
2464 DBG("Relay command received");
2465 ret
= relay_add_connection(relay_cmd_pipe
[0],
2466 &events
, relay_connections_ht
);
2471 } else if (revents
) {
2473 lttng_ht_lookup(relay_connections_ht
,
2474 (void *)((unsigned long) pollfd
),
2476 node
= lttng_ht_iter_get_node_ulong(&iter
);
2478 DBG2("Relay sock %d not found", pollfd
);
2482 relay_connection
= caa_container_of(node
,
2483 struct relay_command
, sock_n
);
2485 if (revents
& (LPOLLERR
)) {
2487 relay_cleanup_poll_connection(&events
, pollfd
);
2488 relay_del_connection(relay_connections_ht
,
2489 &iter
, relay_connection
, sessions_ht
);
2490 if (last_seen_data_fd
== pollfd
) {
2491 last_seen_data_fd
= last_notdel_data_fd
;
2493 } else if (revents
& (LPOLLHUP
| LPOLLRDHUP
)) {
2494 DBG("Socket %d hung up", pollfd
);
2495 relay_cleanup_poll_connection(&events
, pollfd
);
2496 relay_del_connection(relay_connections_ht
,
2497 &iter
, relay_connection
, sessions_ht
);
2498 if (last_seen_data_fd
== pollfd
) {
2499 last_seen_data_fd
= last_notdel_data_fd
;
2501 } else if (revents
& LPOLLIN
) {
2502 /* control socket */
2503 if (relay_connection
->type
== RELAY_CONTROL
) {
2504 ret
= relay_connection
->sock
->ops
->recvmsg(
2505 relay_connection
->sock
, &recv_hdr
,
2506 sizeof(struct lttcomm_relayd_hdr
), 0);
2507 /* connection closed */
2509 relay_cleanup_poll_connection(&events
, pollfd
);
2510 relay_del_connection(relay_connections_ht
,
2511 &iter
, relay_connection
, sessions_ht
);
2512 DBG("Control connection closed with %d", pollfd
);
2514 if (relay_connection
->session
) {
2515 DBG2("Relay worker receiving data for session : %" PRIu64
,
2516 relay_connection
->session
->id
);
2518 ret
= relay_process_control(&recv_hdr
,
2519 relay_connection
, relay_ctx
);
2521 /* Clear the session on error. */
2522 relay_cleanup_poll_connection(&events
, pollfd
);
2523 relay_del_connection(relay_connections_ht
,
2524 &iter
, relay_connection
, sessions_ht
);
2525 DBG("Connection closed with %d", pollfd
);
2531 * Flag the last seen data fd not deleted. It will be
2532 * used as the last seen fd if any fd gets deleted in
2535 last_notdel_data_fd
= pollfd
;
2543 * The last loop handled a control request, go back to poll to make
2544 * sure we prioritise the control socket.
2550 if (last_seen_data_fd
>= 0) {
2551 for (i
= 0; i
< nb_fd
; i
++) {
2552 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2554 health_code_update();
2556 if (last_seen_data_fd
== pollfd
) {
2563 /* Process data connection. */
2564 for (i
= idx
+ 1; i
< nb_fd
; i
++) {
2565 /* Fetch the poll data. */
2566 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2567 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2569 health_code_update();
2571 /* Skip the command pipe. It's handled in the first loop. */
2572 if (pollfd
== relay_cmd_pipe
[0]) {
2578 lttng_ht_lookup(relay_connections_ht
,
2579 (void *)((unsigned long) pollfd
),
2581 node
= lttng_ht_iter_get_node_ulong(&iter
);
2583 /* Skip it. Might be removed before. */
2587 relay_connection
= caa_container_of(node
,
2588 struct relay_command
, sock_n
);
2590 if (revents
& LPOLLIN
) {
2591 if (relay_connection
->type
!= RELAY_DATA
) {
2595 ret
= relay_process_data(relay_connection
);
2596 /* connection closed */
2598 relay_cleanup_poll_connection(&events
, pollfd
);
2599 relay_del_connection(relay_connections_ht
,
2600 &iter
, relay_connection
, sessions_ht
);
2601 DBG("Data connection closed with %d", pollfd
);
2603 * Every goto restart call sets the last seen fd where
2604 * here we don't really care since we gracefully
2605 * continue the loop after the connection is deleted.
2608 /* Keep last seen port. */
2609 last_seen_data_fd
= pollfd
;
2617 last_seen_data_fd
= -1;
2620 /* Normal exit, no error */
2625 lttng_poll_clean(&events
);
2627 /* empty the hash table and free the memory */
2629 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
, node
, node
) {
2630 health_code_update();
2632 node
= lttng_ht_iter_get_node_ulong(&iter
);
2634 relay_connection
= caa_container_of(node
,
2635 struct relay_command
, sock_n
);
2636 relay_del_connection(relay_connections_ht
,
2637 &iter
, relay_connection
, sessions_ht
);
2642 lttng_ht_destroy(indexes_ht
);
2644 lttng_ht_destroy(relay_connections_ht
);
2645 relay_connections_ht_error
:
2646 /* Close relay cmd pipes */
2647 utils_close_pipe(relay_cmd_pipe
);
2649 DBG("Thread exited with error");
2651 DBG("Worker thread cleanup complete");
2655 ERR("Health error occurred in %s", __func__
);
2657 health_unregister(health_relayd
);
2658 rcu_unregister_thread();
2664 * Create the relay command pipe to wake thread_manage_apps.
2665 * Closed in cleanup().
2667 static int create_relay_cmd_pipe(void)
2671 ret
= utils_create_pipe_cloexec(relay_cmd_pipe
);
2679 int main(int argc
, char **argv
)
2683 struct relay_local_data
*relay_ctx
;
2685 /* Create thread quit pipe */
2686 if ((ret
= init_thread_quit_pipe()) < 0) {
2690 /* Parse arguments */
2692 if ((ret
= parse_args(argc
, argv
)) < 0) {
2696 if ((ret
= set_signal_handler()) < 0) {
2700 /* Try to create directory if -o, --output is specified. */
2701 if (opt_output_path
) {
2702 if (*opt_output_path
!= '/') {
2703 ERR("Please specify an absolute path for -o, --output PATH");
2707 ret
= utils_mkdir_recursive(opt_output_path
, S_IRWXU
| S_IRWXG
);
2709 ERR("Unable to create %s", opt_output_path
);
2715 if (opt_daemon
|| opt_background
) {
2716 ret
= daemon(0, opt_background
);
2723 /* We need those values for the file/dir creation. */
2724 relayd_uid
= getuid();
2725 relayd_gid
= getgid();
2727 /* Check if daemon is UID = 0 */
2728 if (relayd_uid
== 0) {
2729 if (control_uri
->port
< 1024 || data_uri
->port
< 1024 ||
2730 live_uri
->port
< 1024) {
2731 ERR("Need to be root to use ports < 1024");
2737 /* Setup the thread apps communication pipe. */
2738 if ((ret
= create_relay_cmd_pipe()) < 0) {
2742 /* Init relay command queue. */
2743 cds_wfq_init(&relay_cmd_queue
.queue
);
2745 /* Set up max poll set size */
2746 lttng_poll_set_max_size();
2748 /* Initialize communication library */
2750 lttcomm_inet_init();
2752 relay_ctx
= zmalloc(sizeof(struct relay_local_data
));
2754 PERROR("relay_ctx");
2758 /* tables of sessions indexed by session ID */
2759 relay_ctx
->sessions_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2760 if (!relay_ctx
->sessions_ht
) {
2761 goto exit_relay_ctx_sessions
;
2764 /* tables of streams indexed by stream ID */
2765 relay_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2766 if (!relay_streams_ht
) {
2767 goto exit_relay_ctx_streams
;
2770 /* tables of streams indexed by stream ID */
2771 viewer_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2772 if (!viewer_streams_ht
) {
2773 goto exit_relay_ctx_viewer_streams
;
2776 /* Initialize thread health monitoring */
2777 health_relayd
= health_app_create(NR_HEALTH_RELAYD_TYPES
);
2778 if (!health_relayd
) {
2779 PERROR("health_app_create error");
2780 goto exit_health_app_create
;
2783 ret
= utils_create_pipe(health_quit_pipe
);
2785 goto error_health_pipe
;
2788 /* Create thread to manage the client socket */
2789 ret
= pthread_create(&health_thread
, NULL
,
2790 thread_manage_health
, (void *) NULL
);
2792 PERROR("pthread_create health");
2796 /* Setup the dispatcher thread */
2797 ret
= pthread_create(&dispatcher_thread
, NULL
,
2798 relay_thread_dispatcher
, (void *) NULL
);
2800 PERROR("pthread_create dispatcher");
2801 goto exit_dispatcher
;
2804 /* Setup the worker thread */
2805 ret
= pthread_create(&worker_thread
, NULL
,
2806 relay_thread_worker
, (void *) relay_ctx
);
2808 PERROR("pthread_create worker");
2812 /* Setup the listener thread */
2813 ret
= pthread_create(&listener_thread
, NULL
,
2814 relay_thread_listener
, (void *) NULL
);
2816 PERROR("pthread_create listener");
2820 ret
= live_start_threads(live_uri
, relay_ctx
, thread_quit_pipe
);
2822 ERR("Starting live viewer threads");
2827 ret
= pthread_join(listener_thread
, &status
);
2829 PERROR("pthread_join");
2830 goto error
; /* join error, exit without cleanup */
2834 ret
= pthread_join(worker_thread
, &status
);
2836 PERROR("pthread_join");
2837 goto error
; /* join error, exit without cleanup */
2841 ret
= pthread_join(dispatcher_thread
, &status
);
2843 PERROR("pthread_join");
2844 goto error
; /* join error, exit without cleanup */
2848 ret
= pthread_join(health_thread
, &status
);
2850 PERROR("pthread_join health thread");
2851 goto error
; /* join error, exit without cleanup */
2855 * Stop live threads only after joining other threads.
2857 live_stop_threads();
2860 utils_close_pipe(health_quit_pipe
);
2863 health_app_destroy(health_relayd
);
2865 exit_health_app_create
:
2866 lttng_ht_destroy(viewer_streams_ht
);
2868 exit_relay_ctx_viewer_streams
:
2869 lttng_ht_destroy(relay_streams_ht
);
2871 exit_relay_ctx_streams
:
2872 lttng_ht_destroy(relay_ctx
->sessions_ht
);
2874 exit_relay_ctx_sessions
: