2 * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
4 * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License, version 2 only,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <sys/mount.h>
32 #include <sys/resource.h>
33 #include <sys/socket.h>
35 #include <sys/types.h>
38 #include <urcu/futex.h>
39 #include <urcu/uatomic.h>
43 #include <lttng/lttng.h>
44 #include <common/common.h>
45 #include <common/compat/poll.h>
46 #include <common/compat/socket.h>
47 #include <common/compat/endian.h>
48 #include <common/compat/getenv.h>
49 #include <common/defaults.h>
50 #include <common/daemonize.h>
51 #include <common/futex.h>
52 #include <common/sessiond-comm/sessiond-comm.h>
53 #include <common/sessiond-comm/inet.h>
54 #include <common/sessiond-comm/relayd.h>
55 #include <common/uri.h>
56 #include <common/utils.h>
57 #include <common/config/session-config.h>
58 #include <urcu/rculist.h>
61 #include "ctf-trace.h"
64 #include "lttng-relayd.h"
66 #include "health-relayd.h"
67 #include "testpoint.h"
68 #include "viewer-stream.h"
71 #include "connection.h"
72 #include "tracefile-array.h"
74 /* command line options */
75 char *opt_output_path
;
76 static int opt_daemon
, opt_background
;
79 * We need to wait for listener and live listener threads, as well as
80 * health check thread, before being ready to signal readiness.
82 #define NR_LTTNG_RELAY_READY 3
83 static int lttng_relay_ready
= NR_LTTNG_RELAY_READY
;
84 static int recv_child_signal
; /* Set to 1 when a SIGUSR1 signal is received. */
85 static pid_t child_ppid
; /* Internal parent PID use with daemonize. */
87 static struct lttng_uri
*control_uri
;
88 static struct lttng_uri
*data_uri
;
89 static struct lttng_uri
*live_uri
;
93 const char *tracing_group_name
= DEFAULT_TRACING_GROUP
;
94 static int tracing_group_name_override
;
96 const char * const config_section_name
= "relayd";
99 * Quit pipe for all threads. This permits a single cancellation point
100 * for all threads when receiving an event on the pipe.
102 int thread_quit_pipe
[2] = { -1, -1 };
105 * This pipe is used to inform the worker thread that a command is queued and
106 * ready to be processed.
108 static int relay_conn_pipe
[2] = { -1, -1 };
110 /* Shared between threads */
111 static int dispatch_thread_exit
;
113 static pthread_t listener_thread
;
114 static pthread_t dispatcher_thread
;
115 static pthread_t worker_thread
;
116 static pthread_t health_thread
;
119 * last_relay_stream_id_lock protects last_relay_stream_id increment
120 * atomicity on 32-bit architectures.
122 static pthread_mutex_t last_relay_stream_id_lock
= PTHREAD_MUTEX_INITIALIZER
;
123 static uint64_t last_relay_stream_id
;
126 * Relay command queue.
128 * The relay_thread_listener and relay_thread_dispatcher communicate with this
131 static struct relay_conn_queue relay_conn_queue
;
133 /* buffer allocated at startup, used to store the trace data */
134 static char *data_buffer
;
135 static unsigned int data_buffer_size
;
137 /* Global relay stream hash table. */
138 struct lttng_ht
*relay_streams_ht
;
140 /* Global relay viewer stream hash table. */
141 struct lttng_ht
*viewer_streams_ht
;
143 /* Global relay sessions hash table. */
144 struct lttng_ht
*sessions_ht
;
146 /* Relayd health monitoring */
147 struct health_app
*health_relayd
;
149 static struct option long_options
[] = {
150 { "control-port", 1, 0, 'C', },
151 { "data-port", 1, 0, 'D', },
152 { "live-port", 1, 0, 'L', },
153 { "daemonize", 0, 0, 'd', },
154 { "background", 0, 0, 'b', },
155 { "group", 1, 0, 'g', },
156 { "help", 0, 0, 'h', },
157 { "output", 1, 0, 'o', },
158 { "verbose", 0, 0, 'v', },
159 { "config", 1, 0, 'f' },
163 static const char *config_ignore_options
[] = { "help", "config" };
166 * Take an option from the getopt output and set it in the right variable to be
169 * Return 0 on success else a negative value.
171 static int set_option(int opt
, const char *arg
, const char *optname
)
177 fprintf(stderr
, "option %s", optname
);
179 fprintf(stderr
, " with arg %s\n", arg
);
183 if (lttng_is_setuid_setgid()) {
184 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
185 "-C, --control-port");
187 ret
= uri_parse(arg
, &control_uri
);
189 ERR("Invalid control URI specified");
192 if (control_uri
->port
== 0) {
193 control_uri
->port
= DEFAULT_NETWORK_CONTROL_PORT
;
198 if (lttng_is_setuid_setgid()) {
199 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
202 ret
= uri_parse(arg
, &data_uri
);
204 ERR("Invalid data URI specified");
207 if (data_uri
->port
== 0) {
208 data_uri
->port
= DEFAULT_NETWORK_DATA_PORT
;
213 if (lttng_is_setuid_setgid()) {
214 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
217 ret
= uri_parse(arg
, &live_uri
);
219 ERR("Invalid live URI specified");
222 if (live_uri
->port
== 0) {
223 live_uri
->port
= DEFAULT_NETWORK_VIEWER_PORT
;
234 if (lttng_is_setuid_setgid()) {
235 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
238 tracing_group_name
= strdup(arg
);
239 if (tracing_group_name
== NULL
) {
244 tracing_group_name_override
= 1;
248 ret
= utils_show_man_page(8, "lttng-relayd");
250 ERR("Cannot view man page lttng-relayd(8)");
255 if (lttng_is_setuid_setgid()) {
256 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
259 ret
= asprintf(&opt_output_path
, "%s", arg
);
262 PERROR("asprintf opt_output_path");
268 /* Verbose level can increase using multiple -v */
270 lttng_opt_verbose
= config_parse_value(arg
);
272 /* Only 3 level of verbosity (-vvv). */
273 if (lttng_opt_verbose
< 3) {
274 lttng_opt_verbose
+= 1;
279 /* Unknown option or other error.
280 * Error is printed by getopt, just return */
293 * config_entry_handler_cb used to handle options read from a config file.
294 * See config_entry_handler_cb comment in common/config/session-config.h for the
295 * return value conventions.
297 static int config_entry_handler(const struct config_entry
*entry
, void *unused
)
301 if (!entry
|| !entry
->name
|| !entry
->value
) {
306 /* Check if the option is to be ignored */
307 for (i
= 0; i
< sizeof(config_ignore_options
) / sizeof(char *); i
++) {
308 if (!strcmp(entry
->name
, config_ignore_options
[i
])) {
313 for (i
= 0; i
< (sizeof(long_options
) / sizeof(struct option
)) - 1; i
++) {
314 /* Ignore if entry name is not fully matched. */
315 if (strcmp(entry
->name
, long_options
[i
].name
)) {
320 * If the option takes no argument on the command line,
321 * we have to check if the value is "true". We support
322 * non-zero numeric values, true, on and yes.
324 if (!long_options
[i
].has_arg
) {
325 ret
= config_parse_value(entry
->value
);
328 WARN("Invalid configuration value \"%s\" for option %s",
329 entry
->value
, entry
->name
);
331 /* False, skip boolean config option. */
336 ret
= set_option(long_options
[i
].val
, entry
->value
, entry
->name
);
340 WARN("Unrecognized option \"%s\" in daemon configuration file.",
347 static int set_options(int argc
, char **argv
)
349 int c
, ret
= 0, option_index
= 0, retval
= 0;
350 int orig_optopt
= optopt
, orig_optind
= optind
;
351 char *default_address
, *optstring
;
352 const char *config_path
= NULL
;
354 optstring
= utils_generate_optstring(long_options
,
355 sizeof(long_options
) / sizeof(struct option
));
361 /* Check for the --config option */
363 while ((c
= getopt_long(argc
, argv
, optstring
, long_options
,
364 &option_index
)) != -1) {
368 } else if (c
!= 'f') {
372 if (lttng_is_setuid_setgid()) {
373 WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
376 config_path
= utils_expand_path(optarg
);
378 ERR("Failed to resolve path: %s", optarg
);
383 ret
= config_get_section_entries(config_path
, config_section_name
,
384 config_entry_handler
, NULL
);
387 ERR("Invalid configuration option at line %i", ret
);
393 /* Reset getopt's global state */
394 optopt
= orig_optopt
;
395 optind
= orig_optind
;
397 c
= getopt_long(argc
, argv
, optstring
, long_options
, &option_index
);
402 ret
= set_option(c
, optarg
, long_options
[option_index
].name
);
409 /* assign default values */
410 if (control_uri
== NULL
) {
411 ret
= asprintf(&default_address
,
412 "tcp://" DEFAULT_NETWORK_CONTROL_BIND_ADDRESS
":%d",
413 DEFAULT_NETWORK_CONTROL_PORT
);
415 PERROR("asprintf default data address");
420 ret
= uri_parse(default_address
, &control_uri
);
421 free(default_address
);
423 ERR("Invalid control URI specified");
428 if (data_uri
== NULL
) {
429 ret
= asprintf(&default_address
,
430 "tcp://" DEFAULT_NETWORK_DATA_BIND_ADDRESS
":%d",
431 DEFAULT_NETWORK_DATA_PORT
);
433 PERROR("asprintf default data address");
438 ret
= uri_parse(default_address
, &data_uri
);
439 free(default_address
);
441 ERR("Invalid data URI specified");
446 if (live_uri
== NULL
) {
447 ret
= asprintf(&default_address
,
448 "tcp://" DEFAULT_NETWORK_VIEWER_BIND_ADDRESS
":%d",
449 DEFAULT_NETWORK_VIEWER_PORT
);
451 PERROR("asprintf default viewer control address");
456 ret
= uri_parse(default_address
, &live_uri
);
457 free(default_address
);
459 ERR("Invalid viewer control URI specified");
470 static void print_global_objects(void)
472 rcu_register_thread();
474 print_viewer_streams();
475 print_relay_streams();
478 rcu_unregister_thread();
484 static void relayd_cleanup(void)
486 print_global_objects();
490 if (viewer_streams_ht
)
491 lttng_ht_destroy(viewer_streams_ht
);
492 if (relay_streams_ht
)
493 lttng_ht_destroy(relay_streams_ht
);
495 lttng_ht_destroy(sessions_ht
);
497 /* free the dynamically allocated opt_output_path */
498 free(opt_output_path
);
500 /* Close thread quit pipes */
501 utils_close_pipe(thread_quit_pipe
);
503 uri_free(control_uri
);
505 /* Live URI is freed in the live thread. */
507 if (tracing_group_name_override
) {
508 free((void *) tracing_group_name
);
513 * Write to writable pipe used to notify a thread.
515 static int notify_thread_pipe(int wpipe
)
519 ret
= lttng_write(wpipe
, "!", 1);
521 PERROR("write poll pipe");
529 static int notify_health_quit_pipe(int *pipe
)
533 ret
= lttng_write(pipe
[1], "4", 1);
535 PERROR("write relay health quit");
544 * Stop all relayd and relayd-live threads.
546 int lttng_relay_stop_threads(void)
550 /* Stopping all threads */
551 DBG("Terminating all threads");
552 if (notify_thread_pipe(thread_quit_pipe
[1])) {
553 ERR("write error on thread quit pipe");
557 if (notify_health_quit_pipe(health_quit_pipe
)) {
558 ERR("write error on health quit pipe");
561 /* Dispatch thread */
562 CMM_STORE_SHARED(dispatch_thread_exit
, 1);
563 futex_nto1_wake(&relay_conn_queue
.futex
);
565 if (relayd_live_stop()) {
566 ERR("Error stopping live threads");
573 * Signal handler for the daemon
575 * Simply stop all worker threads, leaving main() return gracefully after
576 * joining all threads and calling cleanup().
578 static void sighandler(int sig
)
582 DBG("SIGPIPE caught");
585 DBG("SIGINT caught");
586 if (lttng_relay_stop_threads()) {
587 ERR("Error stopping threads");
591 DBG("SIGTERM caught");
592 if (lttng_relay_stop_threads()) {
593 ERR("Error stopping threads");
597 CMM_STORE_SHARED(recv_child_signal
, 1);
605 * Setup signal handler for :
606 * SIGINT, SIGTERM, SIGPIPE
608 static int set_signal_handler(void)
614 if ((ret
= sigemptyset(&sigset
)) < 0) {
615 PERROR("sigemptyset");
619 sa
.sa_handler
= sighandler
;
622 if ((ret
= sigaction(SIGTERM
, &sa
, NULL
)) < 0) {
627 if ((ret
= sigaction(SIGINT
, &sa
, NULL
)) < 0) {
632 if ((ret
= sigaction(SIGPIPE
, &sa
, NULL
)) < 0) {
637 if ((ret
= sigaction(SIGUSR1
, &sa
, NULL
)) < 0) {
642 DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
647 void lttng_relay_notify_ready(void)
649 /* Notify the parent of the fork() process that we are ready. */
650 if (opt_daemon
|| opt_background
) {
651 if (uatomic_sub_return(<tng_relay_ready
, 1) == 0) {
652 kill(child_ppid
, SIGUSR1
);
658 * Init thread quit pipe.
660 * Return -1 on error or 0 if all pipes are created.
662 static int init_thread_quit_pipe(void)
666 ret
= utils_create_pipe_cloexec(thread_quit_pipe
);
672 * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
674 static int create_thread_poll_set(struct lttng_poll_event
*events
, int size
)
678 if (events
== NULL
|| size
== 0) {
683 ret
= lttng_poll_create(events
, size
, LTTNG_CLOEXEC
);
689 ret
= lttng_poll_add(events
, thread_quit_pipe
[0], LPOLLIN
| LPOLLERR
);
701 * Check if the thread quit pipe was triggered.
703 * Return 1 if it was triggered else 0;
705 static int check_thread_quit_pipe(int fd
, uint32_t events
)
707 if (fd
== thread_quit_pipe
[0] && (events
& LPOLLIN
)) {
715 * Create and init socket from uri.
717 static struct lttcomm_sock
*relay_socket_create(struct lttng_uri
*uri
)
720 struct lttcomm_sock
*sock
= NULL
;
722 sock
= lttcomm_alloc_sock_from_uri(uri
);
724 ERR("Allocating socket");
728 ret
= lttcomm_create_sock(sock
);
732 DBG("Listening on sock %d", sock
->fd
);
734 ret
= sock
->ops
->bind(sock
);
739 ret
= sock
->ops
->listen(sock
, -1);
749 lttcomm_destroy_sock(sock
);
755 * This thread manages the listening for new connections on the network
757 static void *relay_thread_listener(void *data
)
759 int i
, ret
, pollfd
, err
= -1;
760 uint32_t revents
, nb_fd
;
761 struct lttng_poll_event events
;
762 struct lttcomm_sock
*control_sock
, *data_sock
;
764 DBG("[thread] Relay listener started");
766 health_register(health_relayd
, HEALTH_RELAYD_TYPE_LISTENER
);
768 health_code_update();
770 control_sock
= relay_socket_create(control_uri
);
772 goto error_sock_control
;
775 data_sock
= relay_socket_create(data_uri
);
777 goto error_sock_relay
;
781 * Pass 3 as size here for the thread quit pipe, control and
784 ret
= create_thread_poll_set(&events
, 3);
786 goto error_create_poll
;
789 /* Add the control socket */
790 ret
= lttng_poll_add(&events
, control_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
795 /* Add the data socket */
796 ret
= lttng_poll_add(&events
, data_sock
->fd
, LPOLLIN
| LPOLLRDHUP
);
801 lttng_relay_notify_ready();
803 if (testpoint(relayd_thread_listener
)) {
804 goto error_testpoint
;
808 health_code_update();
810 DBG("Listener accepting connections");
814 ret
= lttng_poll_wait(&events
, -1);
818 * Restart interrupted system call.
820 if (errno
== EINTR
) {
828 DBG("Relay new connection received");
829 for (i
= 0; i
< nb_fd
; i
++) {
830 health_code_update();
832 /* Fetch once the poll data */
833 revents
= LTTNG_POLL_GETEV(&events
, i
);
834 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
838 * No activity for this FD (poll
844 /* Thread quit pipe has been closed. Killing thread. */
845 ret
= check_thread_quit_pipe(pollfd
, revents
);
851 if (revents
& LPOLLIN
) {
853 * A new connection is requested, therefore a
854 * sessiond/consumerd connection is allocated in
855 * this thread, enqueued to a global queue and
856 * dequeued (and freed) in the worker thread.
859 struct relay_connection
*new_conn
;
860 struct lttcomm_sock
*newsock
;
861 enum connection_type type
;
863 if (pollfd
== data_sock
->fd
) {
865 newsock
= data_sock
->ops
->accept(data_sock
);
866 DBG("Relay data connection accepted, socket %d",
869 assert(pollfd
== control_sock
->fd
);
870 type
= RELAY_CONTROL
;
871 newsock
= control_sock
->ops
->accept(control_sock
);
872 DBG("Relay control connection accepted, socket %d",
876 PERROR("accepting sock");
880 ret
= setsockopt(newsock
->fd
, SOL_SOCKET
, SO_REUSEADDR
, &val
,
883 PERROR("setsockopt inet");
884 lttcomm_destroy_sock(newsock
);
887 new_conn
= connection_create(newsock
, type
);
889 lttcomm_destroy_sock(newsock
);
893 /* Enqueue request for the dispatcher thread. */
894 cds_wfcq_enqueue(&relay_conn_queue
.head
, &relay_conn_queue
.tail
,
898 * Wake the dispatch queue futex.
899 * Implicit memory barrier with the
900 * exchange in cds_wfcq_enqueue.
902 futex_nto1_wake(&relay_conn_queue
.futex
);
903 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
904 ERR("socket poll error");
907 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
917 lttng_poll_clean(&events
);
919 if (data_sock
->fd
>= 0) {
920 ret
= data_sock
->ops
->close(data_sock
);
925 lttcomm_destroy_sock(data_sock
);
927 if (control_sock
->fd
>= 0) {
928 ret
= control_sock
->ops
->close(control_sock
);
933 lttcomm_destroy_sock(control_sock
);
937 ERR("Health error occurred in %s", __func__
);
939 health_unregister(health_relayd
);
940 DBG("Relay listener thread cleanup complete");
941 lttng_relay_stop_threads();
946 * This thread manages the dispatching of the requests to worker threads
948 static void *relay_thread_dispatcher(void *data
)
952 struct cds_wfcq_node
*node
;
953 struct relay_connection
*new_conn
= NULL
;
955 DBG("[thread] Relay dispatcher started");
957 health_register(health_relayd
, HEALTH_RELAYD_TYPE_DISPATCHER
);
959 if (testpoint(relayd_thread_dispatcher
)) {
960 goto error_testpoint
;
963 health_code_update();
965 while (!CMM_LOAD_SHARED(dispatch_thread_exit
)) {
966 health_code_update();
968 /* Atomically prepare the queue futex */
969 futex_nto1_prepare(&relay_conn_queue
.futex
);
972 health_code_update();
974 /* Dequeue commands */
975 node
= cds_wfcq_dequeue_blocking(&relay_conn_queue
.head
,
976 &relay_conn_queue
.tail
);
978 DBG("Woken up but nothing in the relay command queue");
979 /* Continue thread execution */
982 new_conn
= caa_container_of(node
, struct relay_connection
, qnode
);
984 DBG("Dispatching request waiting on sock %d", new_conn
->sock
->fd
);
987 * Inform worker thread of the new request. This
988 * call is blocking so we can be assured that
989 * the data will be read at some point in time
990 * or wait to the end of the world :)
992 ret
= lttng_write(relay_conn_pipe
[1], &new_conn
, sizeof(new_conn
));
994 PERROR("write connection pipe");
995 connection_put(new_conn
);
998 } while (node
!= NULL
);
1000 /* Futex wait on queue. Blocking call on futex() */
1001 health_poll_entry();
1002 futex_nto1_wait(&relay_conn_queue
.futex
);
1006 /* Normal exit, no error */
1013 ERR("Health error occurred in %s", __func__
);
1015 health_unregister(health_relayd
);
1016 DBG("Dispatch thread dying");
1017 lttng_relay_stop_threads();
1022 * Set index data from the control port to a given index object.
1024 static int set_index_control_data(struct relay_index
*index
,
1025 struct lttcomm_relayd_index
*data
,
1026 struct relay_connection
*conn
)
1028 struct ctf_packet_index index_data
;
1031 * The index on disk is encoded in big endian, so we don't need
1032 * to convert the data received on the network. The data_offset
1033 * value is NEVER modified here and is updated by the data
1036 index_data
.packet_size
= data
->packet_size
;
1037 index_data
.content_size
= data
->content_size
;
1038 index_data
.timestamp_begin
= data
->timestamp_begin
;
1039 index_data
.timestamp_end
= data
->timestamp_end
;
1040 index_data
.events_discarded
= data
->events_discarded
;
1041 index_data
.stream_id
= data
->stream_id
;
1043 if (conn
->minor
>= 8) {
1044 index
->index_data
.stream_instance_id
= data
->stream_instance_id
;
1045 index
->index_data
.packet_seq_num
= data
->packet_seq_num
;
1048 return relay_index_set_data(index
, &index_data
);
1052 * Handle the RELAYD_CREATE_SESSION command.
1054 * On success, send back the session id or else return a negative value.
1056 static int relay_create_session(struct lttcomm_relayd_hdr
*recv_hdr
,
1057 struct relay_connection
*conn
)
1059 int ret
= 0, send_ret
;
1060 struct relay_session
*session
;
1061 struct lttcomm_relayd_status_session reply
;
1062 char session_name
[LTTNG_NAME_MAX
];
1063 char hostname
[LTTNG_HOST_NAME_MAX
];
1064 uint32_t live_timer
= 0;
1065 bool snapshot
= false;
1067 memset(session_name
, 0, LTTNG_NAME_MAX
);
1068 memset(hostname
, 0, LTTNG_HOST_NAME_MAX
);
1070 memset(&reply
, 0, sizeof(reply
));
1072 switch (conn
->minor
) {
1077 case 4: /* LTTng sessiond 2.4 */
1079 ret
= cmd_create_session_2_4(conn
, session_name
,
1080 hostname
, &live_timer
, &snapshot
);
1086 session
= session_create(session_name
, hostname
, live_timer
,
1087 snapshot
, conn
->major
, conn
->minor
);
1092 assert(!conn
->session
);
1093 conn
->session
= session
;
1094 DBG("Created session %" PRIu64
, session
->id
);
1096 reply
.session_id
= htobe64(session
->id
);
1100 reply
.ret_code
= htobe32(LTTNG_ERR_FATAL
);
1102 reply
.ret_code
= htobe32(LTTNG_OK
);
1105 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1107 ERR("Relayd sending session id");
1115 * When we have received all the streams and the metadata for a channel,
1116 * we make them visible to the viewer threads.
1118 static void publish_connection_local_streams(struct relay_connection
*conn
)
1120 struct relay_stream
*stream
;
1121 struct relay_session
*session
= conn
->session
;
1124 * We publish all streams belonging to a session atomically wrt
1127 pthread_mutex_lock(&session
->lock
);
1129 cds_list_for_each_entry_rcu(stream
, &session
->recv_list
,
1131 stream_publish(stream
);
1136 * Inform the viewer that there are new streams in the session.
1138 if (session
->viewer_attached
) {
1139 uatomic_set(&session
->new_streams
, 1);
1141 pthread_mutex_unlock(&session
->lock
);
1145 * relay_add_stream: allocate a new stream for a session
1147 static int relay_add_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1148 struct relay_connection
*conn
)
1152 struct relay_session
*session
= conn
->session
;
1153 struct relay_stream
*stream
= NULL
;
1154 struct lttcomm_relayd_status_stream reply
;
1155 struct ctf_trace
*trace
= NULL
;
1156 uint64_t stream_handle
= -1ULL;
1157 char *path_name
= NULL
, *channel_name
= NULL
;
1158 uint64_t tracefile_size
= 0, tracefile_count
= 0;
1160 if (!session
|| conn
->version_check_done
== 0) {
1161 ERR("Trying to add a stream before version check");
1163 goto end_no_session
;
1166 switch (session
->minor
) {
1167 case 1: /* LTTng sessiond 2.1. Allocates path_name and channel_name. */
1168 ret
= cmd_recv_stream_2_1(conn
, &path_name
,
1171 case 2: /* LTTng sessiond 2.2. Allocates path_name and channel_name. */
1173 ret
= cmd_recv_stream_2_2(conn
, &path_name
,
1174 &channel_name
, &tracefile_size
, &tracefile_count
);
1181 trace
= ctf_trace_get_by_path_or_create(session
, path_name
);
1185 /* This stream here has one reference on the trace. */
1187 pthread_mutex_lock(&last_relay_stream_id_lock
);
1188 stream_handle
= ++last_relay_stream_id
;
1189 pthread_mutex_unlock(&last_relay_stream_id_lock
);
1191 /* We pass ownership of path_name and channel_name. */
1192 stream
= stream_create(trace
, stream_handle
, path_name
,
1193 channel_name
, tracefile_size
, tracefile_count
);
1195 channel_name
= NULL
;
1198 * Streams are the owners of their trace. Reference to trace is
1199 * kept within stream_create().
1201 ctf_trace_put(trace
);
1204 memset(&reply
, 0, sizeof(reply
));
1205 reply
.handle
= htobe64(stream_handle
);
1207 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1209 reply
.ret_code
= htobe32(LTTNG_OK
);
1212 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1213 sizeof(struct lttcomm_relayd_status_stream
), 0);
1215 ERR("Relay sending stream id");
1216 ret
= (int) send_ret
;
1226 * relay_close_stream: close a specific stream
1228 static int relay_close_stream(struct lttcomm_relayd_hdr
*recv_hdr
,
1229 struct relay_connection
*conn
)
1232 struct relay_session
*session
= conn
->session
;
1233 struct lttcomm_relayd_close_stream stream_info
;
1234 struct lttcomm_relayd_generic_reply reply
;
1235 struct relay_stream
*stream
;
1237 DBG("Close stream received");
1239 if (!session
|| conn
->version_check_done
== 0) {
1240 ERR("Trying to close a stream before version check");
1242 goto end_no_session
;
1245 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1246 sizeof(struct lttcomm_relayd_close_stream
), 0);
1247 if (ret
< sizeof(struct lttcomm_relayd_close_stream
)) {
1249 /* Orderly shutdown. Not necessary to print an error. */
1250 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1252 ERR("Relay didn't receive valid add_stream struct size : %d", ret
);
1255 goto end_no_session
;
1258 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1265 * Set last_net_seq_num before the close flag. Required by data
1268 pthread_mutex_lock(&stream
->lock
);
1269 stream
->last_net_seq_num
= be64toh(stream_info
.last_net_seq_num
);
1270 pthread_mutex_unlock(&stream
->lock
);
1273 * This is one of the conditions which may trigger a stream close
1274 * with the others being:
1275 * 1) A close command is received for a stream
1276 * 2) The control connection owning the stream is closed
1277 * 3) We have received all of the stream's data _after_ a close
1280 try_stream_close(stream
);
1281 if (stream
->is_metadata
) {
1282 struct relay_viewer_stream
*vstream
;
1284 vstream
= viewer_stream_get_by_id(stream
->stream_handle
);
1286 if (vstream
->metadata_sent
== stream
->metadata_received
) {
1288 * Since all the metadata has been sent to the
1289 * viewer and that we have a request to close
1290 * its stream, we can safely teardown the
1291 * corresponding metadata viewer stream.
1293 viewer_stream_put(vstream
);
1295 /* Put local reference. */
1296 viewer_stream_put(vstream
);
1302 memset(&reply
, 0, sizeof(reply
));
1304 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1306 reply
.ret_code
= htobe32(LTTNG_OK
);
1308 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1309 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1311 ERR("Relay sending stream id");
1320 * relay_reset_metadata: reset a metadata stream
1323 int relay_reset_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1324 struct relay_connection
*conn
)
1327 struct relay_session
*session
= conn
->session
;
1328 struct lttcomm_relayd_reset_metadata stream_info
;
1329 struct lttcomm_relayd_generic_reply reply
;
1330 struct relay_stream
*stream
;
1332 DBG("Reset metadata received");
1334 if (!session
|| conn
->version_check_done
== 0) {
1335 ERR("Trying to reset a metadata stream before version check");
1337 goto end_no_session
;
1340 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &stream_info
,
1341 sizeof(struct lttcomm_relayd_reset_metadata
), 0);
1342 if (ret
< sizeof(struct lttcomm_relayd_reset_metadata
)) {
1344 /* Orderly shutdown. Not necessary to print an error. */
1345 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1347 ERR("Relay didn't receive valid reset_metadata struct "
1351 goto end_no_session
;
1353 DBG("Update metadata to version %" PRIu64
, be64toh(stream_info
.version
));
1355 /* Unsupported for live sessions for now. */
1356 if (session
->live_timer
!= 0) {
1361 stream
= stream_get_by_id(be64toh(stream_info
.stream_id
));
1366 pthread_mutex_lock(&stream
->lock
);
1367 if (!stream
->is_metadata
) {
1372 ret
= utils_rotate_stream_file(stream
->path_name
, stream
->channel_name
,
1373 0, 0, -1, -1, stream
->stream_fd
->fd
, NULL
,
1374 &stream
->stream_fd
->fd
);
1376 ERR("Failed to rotate metadata file %s of channel %s",
1377 stream
->path_name
, stream
->channel_name
);
1382 pthread_mutex_unlock(&stream
->lock
);
1386 memset(&reply
, 0, sizeof(reply
));
1388 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1390 reply
.ret_code
= htobe32(LTTNG_OK
);
1392 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1393 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1395 ERR("Relay sending reset metadata reply");
1404 * relay_unknown_command: send -1 if received unknown command
1406 static void relay_unknown_command(struct relay_connection
*conn
)
1408 struct lttcomm_relayd_generic_reply reply
;
1411 memset(&reply
, 0, sizeof(reply
));
1412 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
1413 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1414 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1416 ERR("Relay sending unknown command");
1421 * relay_start: send an acknowledgment to the client to tell if we are
1422 * ready to receive data. We are ready if a session is established.
1424 static int relay_start(struct lttcomm_relayd_hdr
*recv_hdr
,
1425 struct relay_connection
*conn
)
1427 int ret
= htobe32(LTTNG_OK
);
1428 struct lttcomm_relayd_generic_reply reply
;
1429 struct relay_session
*session
= conn
->session
;
1432 DBG("Trying to start the streaming without a session established");
1433 ret
= htobe32(LTTNG_ERR_UNK
);
1436 memset(&reply
, 0, sizeof(reply
));
1437 reply
.ret_code
= ret
;
1438 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1439 sizeof(struct lttcomm_relayd_generic_reply
), 0);
1441 ERR("Relay sending start ack");
1448 * Append padding to the file pointed by the file descriptor fd.
1450 static int write_padding_to_file(int fd
, uint32_t size
)
1459 zeros
= zmalloc(size
);
1460 if (zeros
== NULL
) {
1461 PERROR("zmalloc zeros for padding");
1466 ret
= lttng_write(fd
, zeros
, size
);
1468 PERROR("write padding to file");
1478 * relay_recv_metadata: receive the metadata for the session.
1480 static int relay_recv_metadata(struct lttcomm_relayd_hdr
*recv_hdr
,
1481 struct relay_connection
*conn
)
1485 struct relay_session
*session
= conn
->session
;
1486 struct lttcomm_relayd_metadata_payload
*metadata_struct
;
1487 struct relay_stream
*metadata_stream
;
1488 uint64_t data_size
, payload_size
;
1491 ERR("Metadata sent before version check");
1496 data_size
= payload_size
= be64toh(recv_hdr
->data_size
);
1497 if (data_size
< sizeof(struct lttcomm_relayd_metadata_payload
)) {
1498 ERR("Incorrect data size");
1502 payload_size
-= sizeof(struct lttcomm_relayd_metadata_payload
);
1504 if (data_buffer_size
< data_size
) {
1505 /* In case the realloc fails, we can free the memory */
1508 tmp_data_ptr
= realloc(data_buffer
, data_size
);
1509 if (!tmp_data_ptr
) {
1510 ERR("Allocating data buffer");
1515 data_buffer
= tmp_data_ptr
;
1516 data_buffer_size
= data_size
;
1518 memset(data_buffer
, 0, data_size
);
1519 DBG2("Relay receiving metadata, waiting for %" PRIu64
" bytes", data_size
);
1520 size_ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, data_size
, 0);
1521 if (size_ret
< 0 || size_ret
!= data_size
) {
1522 if (size_ret
== 0) {
1523 /* Orderly shutdown. Not necessary to print an error. */
1524 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1526 ERR("Relay didn't receive the whole metadata");
1531 metadata_struct
= (struct lttcomm_relayd_metadata_payload
*) data_buffer
;
1533 metadata_stream
= stream_get_by_id(be64toh(metadata_struct
->stream_id
));
1534 if (!metadata_stream
) {
1539 pthread_mutex_lock(&metadata_stream
->lock
);
1541 size_ret
= lttng_write(metadata_stream
->stream_fd
->fd
, metadata_struct
->payload
,
1543 if (size_ret
< payload_size
) {
1544 ERR("Relay error writing metadata on file");
1549 size_ret
= write_padding_to_file(metadata_stream
->stream_fd
->fd
,
1550 be32toh(metadata_struct
->padding_size
));
1555 metadata_stream
->metadata_received
+=
1556 payload_size
+ be32toh(metadata_struct
->padding_size
);
1557 DBG2("Relay metadata written. Updated metadata_received %" PRIu64
,
1558 metadata_stream
->metadata_received
);
1561 pthread_mutex_unlock(&metadata_stream
->lock
);
1562 stream_put(metadata_stream
);
1568 * relay_send_version: send relayd version number
1570 static int relay_send_version(struct lttcomm_relayd_hdr
*recv_hdr
,
1571 struct relay_connection
*conn
)
1574 struct lttcomm_relayd_version reply
, msg
;
1576 conn
->version_check_done
= 1;
1578 /* Get version from the other side. */
1579 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1580 if (ret
< 0 || ret
!= sizeof(msg
)) {
1582 /* Orderly shutdown. Not necessary to print an error. */
1583 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1585 ERR("Relay failed to receive the version values.");
1591 memset(&reply
, 0, sizeof(reply
));
1592 reply
.major
= RELAYD_VERSION_COMM_MAJOR
;
1593 reply
.minor
= RELAYD_VERSION_COMM_MINOR
;
1595 /* Major versions must be the same */
1596 if (reply
.major
!= be32toh(msg
.major
)) {
1597 DBG("Incompatible major versions (%u vs %u), deleting session",
1598 reply
.major
, be32toh(msg
.major
));
1599 connection_put(conn
);
1604 conn
->major
= reply
.major
;
1605 /* We adapt to the lowest compatible version */
1606 if (reply
.minor
<= be32toh(msg
.minor
)) {
1607 conn
->minor
= reply
.minor
;
1609 conn
->minor
= be32toh(msg
.minor
);
1612 reply
.major
= htobe32(reply
.major
);
1613 reply
.minor
= htobe32(reply
.minor
);
1614 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
,
1615 sizeof(struct lttcomm_relayd_version
), 0);
1617 ERR("Relay sending version");
1620 DBG("Version check done using protocol %u.%u", conn
->major
,
1628 * Check for data pending for a given stream id from the session daemon.
1630 static int relay_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1631 struct relay_connection
*conn
)
1633 struct relay_session
*session
= conn
->session
;
1634 struct lttcomm_relayd_data_pending msg
;
1635 struct lttcomm_relayd_generic_reply reply
;
1636 struct relay_stream
*stream
;
1638 uint64_t last_net_seq_num
, stream_id
;
1640 DBG("Data pending command received");
1642 if (!session
|| conn
->version_check_done
== 0) {
1643 ERR("Trying to check for data before version check");
1645 goto end_no_session
;
1648 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1649 if (ret
< sizeof(msg
)) {
1651 /* Orderly shutdown. Not necessary to print an error. */
1652 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1654 ERR("Relay didn't receive valid data_pending struct size : %d",
1658 goto end_no_session
;
1661 stream_id
= be64toh(msg
.stream_id
);
1662 last_net_seq_num
= be64toh(msg
.last_net_seq_num
);
1664 stream
= stream_get_by_id(stream_id
);
1665 if (stream
== NULL
) {
1670 pthread_mutex_lock(&stream
->lock
);
1672 DBG("Data pending for stream id %" PRIu64
" prev_seq %" PRIu64
1673 " and last_seq %" PRIu64
, stream_id
, stream
->prev_seq
,
1676 /* Avoid wrapping issue */
1677 if (((int64_t) (stream
->prev_seq
- last_net_seq_num
)) >= 0) {
1678 /* Data has in fact been written and is NOT pending */
1681 /* Data still being streamed thus pending */
1685 stream
->data_pending_check_done
= true;
1686 pthread_mutex_unlock(&stream
->lock
);
1691 memset(&reply
, 0, sizeof(reply
));
1692 reply
.ret_code
= htobe32(ret
);
1693 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1695 ERR("Relay data pending ret code failed");
1703 * Wait for the control socket to reach a quiescent state.
1705 * Note that for now, when receiving this command from the session
1706 * daemon, this means that every subsequent commands or data received on
1707 * the control socket has been handled. So, this is why we simply return
1710 static int relay_quiescent_control(struct lttcomm_relayd_hdr
*recv_hdr
,
1711 struct relay_connection
*conn
)
1715 struct relay_stream
*stream
;
1716 struct lttcomm_relayd_quiescent_control msg
;
1717 struct lttcomm_relayd_generic_reply reply
;
1719 DBG("Checking quiescent state on control socket");
1721 if (!conn
->session
|| conn
->version_check_done
== 0) {
1722 ERR("Trying to check for data before version check");
1724 goto end_no_session
;
1727 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1728 if (ret
< sizeof(msg
)) {
1730 /* Orderly shutdown. Not necessary to print an error. */
1731 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1733 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1737 goto end_no_session
;
1740 stream_id
= be64toh(msg
.stream_id
);
1741 stream
= stream_get_by_id(stream_id
);
1745 pthread_mutex_lock(&stream
->lock
);
1746 stream
->data_pending_check_done
= true;
1747 pthread_mutex_unlock(&stream
->lock
);
1748 DBG("Relay quiescent control pending flag set to %" PRIu64
, stream_id
);
1751 memset(&reply
, 0, sizeof(reply
));
1752 reply
.ret_code
= htobe32(LTTNG_OK
);
1753 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1755 ERR("Relay data quiescent control ret code failed");
1763 * Initialize a data pending command. This means that a consumer is about
1764 * to ask for data pending for each stream it holds. Simply iterate over
1765 * all streams of a session and set the data_pending_check_done flag.
1767 * This command returns to the client a LTTNG_OK code.
1769 static int relay_begin_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1770 struct relay_connection
*conn
)
1773 struct lttng_ht_iter iter
;
1774 struct lttcomm_relayd_begin_data_pending msg
;
1775 struct lttcomm_relayd_generic_reply reply
;
1776 struct relay_stream
*stream
;
1777 uint64_t session_id
;
1782 DBG("Init streams for data pending");
1784 if (!conn
->session
|| conn
->version_check_done
== 0) {
1785 ERR("Trying to check for data before version check");
1787 goto end_no_session
;
1790 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1791 if (ret
< sizeof(msg
)) {
1793 /* Orderly shutdown. Not necessary to print an error. */
1794 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1796 ERR("Relay didn't receive valid begin data_pending struct size: %d",
1800 goto end_no_session
;
1803 session_id
= be64toh(msg
.session_id
);
1806 * Iterate over all streams to set the begin data pending flag.
1807 * For now, the streams are indexed by stream handle so we have
1808 * to iterate over all streams to find the one associated with
1809 * the right session_id.
1812 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1814 if (!stream_get(stream
)) {
1817 if (stream
->trace
->session
->id
== session_id
) {
1818 pthread_mutex_lock(&stream
->lock
);
1819 stream
->data_pending_check_done
= false;
1820 pthread_mutex_unlock(&stream
->lock
);
1821 DBG("Set begin data pending flag to stream %" PRIu64
,
1822 stream
->stream_handle
);
1828 memset(&reply
, 0, sizeof(reply
));
1829 /* All good, send back reply. */
1830 reply
.ret_code
= htobe32(LTTNG_OK
);
1832 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1834 ERR("Relay begin data pending send reply failed");
1842 * End data pending command. This will check, for a given session id, if
1843 * each stream associated with it has its data_pending_check_done flag
1844 * set. If not, this means that the client lost track of the stream but
1845 * the data is still being streamed on our side. In this case, we inform
1846 * the client that data is in flight.
1848 * Return to the client if there is data in flight or not with a ret_code.
1850 static int relay_end_data_pending(struct lttcomm_relayd_hdr
*recv_hdr
,
1851 struct relay_connection
*conn
)
1854 struct lttng_ht_iter iter
;
1855 struct lttcomm_relayd_end_data_pending msg
;
1856 struct lttcomm_relayd_generic_reply reply
;
1857 struct relay_stream
*stream
;
1858 uint64_t session_id
;
1859 uint32_t is_data_inflight
= 0;
1861 DBG("End data pending command");
1863 if (!conn
->session
|| conn
->version_check_done
== 0) {
1864 ERR("Trying to check for data before version check");
1866 goto end_no_session
;
1869 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &msg
, sizeof(msg
), 0);
1870 if (ret
< sizeof(msg
)) {
1872 /* Orderly shutdown. Not necessary to print an error. */
1873 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1875 ERR("Relay didn't receive valid end data_pending struct size: %d",
1879 goto end_no_session
;
1882 session_id
= be64toh(msg
.session_id
);
1885 * Iterate over all streams to see if the begin data pending
1889 cds_lfht_for_each_entry(relay_streams_ht
->ht
, &iter
.iter
, stream
,
1891 if (!stream_get(stream
)) {
1894 if (stream
->trace
->session
->id
!= session_id
) {
1898 pthread_mutex_lock(&stream
->lock
);
1899 if (!stream
->data_pending_check_done
) {
1900 if (!stream
->closed
|| !(((int64_t) (stream
->prev_seq
- stream
->last_net_seq_num
)) >= 0)) {
1901 is_data_inflight
= 1;
1902 DBG("Data is still in flight for stream %" PRIu64
,
1903 stream
->stream_handle
);
1904 pthread_mutex_unlock(&stream
->lock
);
1909 pthread_mutex_unlock(&stream
->lock
);
1914 memset(&reply
, 0, sizeof(reply
));
1915 /* All good, send back reply. */
1916 reply
.ret_code
= htobe32(is_data_inflight
);
1918 ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
1920 ERR("Relay end data pending send reply failed");
1928 * Receive an index for a specific stream.
1930 * Return 0 on success else a negative value.
1932 static int relay_recv_index(struct lttcomm_relayd_hdr
*recv_hdr
,
1933 struct relay_connection
*conn
)
1936 struct relay_session
*session
= conn
->session
;
1937 struct lttcomm_relayd_index index_info
;
1938 struct relay_index
*index
;
1939 struct lttcomm_relayd_generic_reply reply
;
1940 struct relay_stream
*stream
;
1941 uint64_t net_seq_num
;
1945 DBG("Relay receiving index");
1947 if (!session
|| conn
->version_check_done
== 0) {
1948 ERR("Trying to close a stream before version check");
1950 goto end_no_session
;
1953 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &index_info
,
1954 sizeof(index_info
), 0);
1955 if (ret
< sizeof(index_info
)) {
1957 /* Orderly shutdown. Not necessary to print an error. */
1958 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
1960 ERR("Relay didn't receive valid index struct size : %d", ret
);
1963 goto end_no_session
;
1966 net_seq_num
= be64toh(index_info
.net_seq_num
);
1968 stream
= stream_get_by_id(be64toh(index_info
.relay_stream_id
));
1970 ERR("stream_get_by_id not found");
1974 pthread_mutex_lock(&stream
->lock
);
1976 /* Live beacon handling */
1977 if (index_info
.packet_size
== 0) {
1978 DBG("Received live beacon for stream %" PRIu64
,
1979 stream
->stream_handle
);
1982 * Only flag a stream inactive when it has already
1983 * received data and no indexes are in flight.
1985 if (stream
->index_received_seqcount
> 0
1986 && stream
->indexes_in_flight
== 0) {
1987 stream
->beacon_ts_end
=
1988 be64toh(index_info
.timestamp_end
);
1991 goto end_stream_put
;
1993 stream
->beacon_ts_end
= -1ULL;
1996 if (stream
->ctf_stream_id
== -1ULL) {
1997 stream
->ctf_stream_id
= be64toh(index_info
.stream_id
);
1999 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2002 ERR("relay_index_get_by_id_or_create index NULL");
2003 goto end_stream_put
;
2005 if (set_index_control_data(index
, &index_info
, conn
)) {
2006 ERR("set_index_control_data error");
2007 relay_index_put(index
);
2009 goto end_stream_put
;
2011 ret
= relay_index_try_flush(index
);
2013 tracefile_array_commit_seq(stream
->tfa
);
2014 stream
->index_received_seqcount
++;
2015 } else if (ret
> 0) {
2019 ERR("relay_index_try_flush error %d", ret
);
2020 relay_index_put(index
);
2025 pthread_mutex_unlock(&stream
->lock
);
2030 memset(&reply
, 0, sizeof(reply
));
2032 reply
.ret_code
= htobe32(LTTNG_ERR_UNK
);
2034 reply
.ret_code
= htobe32(LTTNG_OK
);
2036 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2038 ERR("Relay sending close index id reply");
2047 * Receive the streams_sent message.
2049 * Return 0 on success else a negative value.
2051 static int relay_streams_sent(struct lttcomm_relayd_hdr
*recv_hdr
,
2052 struct relay_connection
*conn
)
2055 struct lttcomm_relayd_generic_reply reply
;
2059 DBG("Relay receiving streams_sent");
2061 if (!conn
->session
|| conn
->version_check_done
== 0) {
2062 ERR("Trying to close a stream before version check");
2064 goto end_no_session
;
2068 * Publish every pending stream in the connection recv list which are
2069 * now ready to be used by the viewer.
2071 publish_connection_local_streams(conn
);
2073 memset(&reply
, 0, sizeof(reply
));
2074 reply
.ret_code
= htobe32(LTTNG_OK
);
2075 send_ret
= conn
->sock
->ops
->sendmsg(conn
->sock
, &reply
, sizeof(reply
), 0);
2077 ERR("Relay sending sent_stream reply");
2089 * Process the commands received on the control socket
2091 static int relay_process_control(struct lttcomm_relayd_hdr
*recv_hdr
,
2092 struct relay_connection
*conn
)
2096 switch (be32toh(recv_hdr
->cmd
)) {
2097 case RELAYD_CREATE_SESSION
:
2098 ret
= relay_create_session(recv_hdr
, conn
);
2100 case RELAYD_ADD_STREAM
:
2101 ret
= relay_add_stream(recv_hdr
, conn
);
2103 case RELAYD_START_DATA
:
2104 ret
= relay_start(recv_hdr
, conn
);
2106 case RELAYD_SEND_METADATA
:
2107 ret
= relay_recv_metadata(recv_hdr
, conn
);
2109 case RELAYD_VERSION
:
2110 ret
= relay_send_version(recv_hdr
, conn
);
2112 case RELAYD_CLOSE_STREAM
:
2113 ret
= relay_close_stream(recv_hdr
, conn
);
2115 case RELAYD_DATA_PENDING
:
2116 ret
= relay_data_pending(recv_hdr
, conn
);
2118 case RELAYD_QUIESCENT_CONTROL
:
2119 ret
= relay_quiescent_control(recv_hdr
, conn
);
2121 case RELAYD_BEGIN_DATA_PENDING
:
2122 ret
= relay_begin_data_pending(recv_hdr
, conn
);
2124 case RELAYD_END_DATA_PENDING
:
2125 ret
= relay_end_data_pending(recv_hdr
, conn
);
2127 case RELAYD_SEND_INDEX
:
2128 ret
= relay_recv_index(recv_hdr
, conn
);
2130 case RELAYD_STREAMS_SENT
:
2131 ret
= relay_streams_sent(recv_hdr
, conn
);
2133 case RELAYD_RESET_METADATA
:
2134 ret
= relay_reset_metadata(recv_hdr
, conn
);
2136 case RELAYD_UPDATE_SYNC_INFO
:
2138 ERR("Received unknown command (%u)", be32toh(recv_hdr
->cmd
));
2139 relay_unknown_command(conn
);
2149 * Handle index for a data stream.
2151 * Called with the stream lock held.
2153 * Return 0 on success else a negative value.
2155 static int handle_index_data(struct relay_stream
*stream
, uint64_t net_seq_num
,
2159 uint64_t data_offset
;
2160 struct relay_index
*index
;
2162 /* Get data offset because we are about to update the index. */
2163 data_offset
= htobe64(stream
->tracefile_size_current
);
2165 DBG("handle_index_data: stream %" PRIu64
" net_seq_num %" PRIu64
" data offset %" PRIu64
,
2166 stream
->stream_handle
, net_seq_num
, stream
->tracefile_size_current
);
2169 * Lookup for an existing index for that stream id/sequence
2170 * number. If it exists, the control thread has already received the
2171 * data for it, thus we need to write it to disk.
2173 index
= relay_index_get_by_id_or_create(stream
, net_seq_num
);
2179 if (rotate_index
|| !stream
->index_fd
) {
2182 /* Put ref on previous index_fd. */
2183 if (stream
->index_fd
) {
2184 stream_fd_put(stream
->index_fd
);
2185 stream
->index_fd
= NULL
;
2188 fd
= index_create_file(stream
->path_name
, stream
->channel_name
,
2189 -1, -1, stream
->tracefile_size
,
2190 tracefile_array_get_file_index_head(stream
->tfa
));
2193 /* Put self-ref for this index due to error. */
2194 relay_index_put(index
);
2197 stream
->index_fd
= stream_fd_create(fd
);
2198 if (!stream
->index_fd
) {
2201 PERROR("Error closing FD %d", fd
);
2203 /* Put self-ref for this index due to error. */
2204 relay_index_put(index
);
2205 /* Will put the local ref. */
2210 if (relay_index_set_fd(index
, stream
->index_fd
, data_offset
)) {
2212 /* Put self-ref for this index due to error. */
2213 relay_index_put(index
);
2217 ret
= relay_index_try_flush(index
);
2219 tracefile_array_commit_seq(stream
->tfa
);
2220 stream
->index_received_seqcount
++;
2221 } else if (ret
> 0) {
2225 /* Put self-ref for this index due to error. */
2226 relay_index_put(index
);
2234 * relay_process_data: Process the data received on the data socket
2236 static int relay_process_data(struct relay_connection
*conn
)
2238 int ret
= 0, rotate_index
= 0;
2240 struct relay_stream
*stream
;
2241 struct lttcomm_relayd_data_hdr data_hdr
;
2243 uint64_t net_seq_num
;
2245 struct relay_session
*session
;
2246 bool new_stream
= false, close_requested
= false;
2248 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, &data_hdr
,
2249 sizeof(struct lttcomm_relayd_data_hdr
), 0);
2252 /* Orderly shutdown. Not necessary to print an error. */
2253 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2255 ERR("Unable to receive data header on sock %d", conn
->sock
->fd
);
2261 stream_id
= be64toh(data_hdr
.stream_id
);
2262 stream
= stream_get_by_id(stream_id
);
2264 ERR("relay_process_data: Cannot find stream %" PRIu64
, stream_id
);
2268 session
= stream
->trace
->session
;
2269 data_size
= be32toh(data_hdr
.data_size
);
2270 if (data_buffer_size
< data_size
) {
2273 tmp_data_ptr
= realloc(data_buffer
, data_size
);
2274 if (!tmp_data_ptr
) {
2275 ERR("Allocating data buffer");
2278 goto end_stream_put
;
2280 data_buffer
= tmp_data_ptr
;
2281 data_buffer_size
= data_size
;
2283 memset(data_buffer
, 0, data_size
);
2285 net_seq_num
= be64toh(data_hdr
.net_seq_num
);
2287 DBG3("Receiving data of size %u for stream id %" PRIu64
" seqnum %" PRIu64
,
2288 data_size
, stream_id
, net_seq_num
);
2289 ret
= conn
->sock
->ops
->recvmsg(conn
->sock
, data_buffer
, data_size
, 0);
2292 /* Orderly shutdown. Not necessary to print an error. */
2293 DBG("Socket %d did an orderly shutdown", conn
->sock
->fd
);
2295 ERR("Socket %d error %d", conn
->sock
->fd
, ret
);
2298 goto end_stream_put
;
2301 pthread_mutex_lock(&stream
->lock
);
2303 /* Check if a rotation is needed. */
2304 if (stream
->tracefile_size
> 0 &&
2305 (stream
->tracefile_size_current
+ data_size
) >
2306 stream
->tracefile_size
) {
2307 uint64_t old_id
, new_id
;
2309 old_id
= tracefile_array_get_file_index_head(stream
->tfa
);
2310 tracefile_array_file_rotate(stream
->tfa
);
2312 /* new_id is updated by utils_rotate_stream_file. */
2315 ret
= utils_rotate_stream_file(stream
->path_name
,
2316 stream
->channel_name
, stream
->tracefile_size
,
2317 stream
->tracefile_count
, -1,
2318 -1, stream
->stream_fd
->fd
,
2319 &new_id
, &stream
->stream_fd
->fd
);
2321 ERR("Rotating stream output file");
2322 goto end_stream_unlock
;
2325 * Reset current size because we just performed a stream
2328 stream
->tracefile_size_current
= 0;
2333 * Index are handled in protocol version 2.4 and above. Also,
2334 * snapshot and index are NOT supported.
2336 if (session
->minor
>= 4 && !session
->snapshot
) {
2337 ret
= handle_index_data(stream
, net_seq_num
, rotate_index
);
2339 ERR("handle_index_data: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2340 stream
->stream_handle
, net_seq_num
, ret
);
2341 goto end_stream_unlock
;
2345 /* Write data to stream output fd. */
2346 size_ret
= lttng_write(stream
->stream_fd
->fd
, data_buffer
, data_size
);
2347 if (size_ret
< data_size
) {
2348 ERR("Relay error writing data to file");
2350 goto end_stream_unlock
;
2353 DBG2("Relay wrote %zd bytes to tracefile for stream id %" PRIu64
,
2354 size_ret
, stream
->stream_handle
);
2356 ret
= write_padding_to_file(stream
->stream_fd
->fd
,
2357 be32toh(data_hdr
.padding_size
));
2359 ERR("write_padding_to_file: fail stream %" PRIu64
" net_seq_num %" PRIu64
" ret %d",
2360 stream
->stream_handle
, net_seq_num
, ret
);
2361 goto end_stream_unlock
;
2363 stream
->tracefile_size_current
+=
2364 data_size
+ be32toh(data_hdr
.padding_size
);
2365 if (stream
->prev_seq
== -1ULL) {
2369 stream
->prev_seq
= net_seq_num
;
2372 close_requested
= stream
->close_requested
;
2373 pthread_mutex_unlock(&stream
->lock
);
2374 if (close_requested
) {
2375 try_stream_close(stream
);
2379 pthread_mutex_lock(&session
->lock
);
2380 uatomic_set(&session
->new_streams
, 1);
2381 pthread_mutex_unlock(&session
->lock
);
2389 static void cleanup_connection_pollfd(struct lttng_poll_event
*events
, int pollfd
)
2393 (void) lttng_poll_del(events
, pollfd
);
2395 ret
= close(pollfd
);
2397 ERR("Closing pollfd %d", pollfd
);
2401 static void relay_thread_close_connection(struct lttng_poll_event
*events
,
2402 int pollfd
, struct relay_connection
*conn
)
2404 const char *type_str
;
2406 switch (conn
->type
) {
2411 type_str
= "Control";
2413 case RELAY_VIEWER_COMMAND
:
2414 type_str
= "Viewer Command";
2416 case RELAY_VIEWER_NOTIFICATION
:
2417 type_str
= "Viewer Notification";
2420 type_str
= "Unknown";
2422 cleanup_connection_pollfd(events
, pollfd
);
2423 connection_put(conn
);
2424 DBG("%s connection closed with %d", type_str
, pollfd
);
2428 * This thread does the actual work
2430 static void *relay_thread_worker(void *data
)
2432 int ret
, err
= -1, last_seen_data_fd
= -1;
2434 struct lttng_poll_event events
;
2435 struct lttng_ht
*relay_connections_ht
;
2436 struct lttng_ht_iter iter
;
2437 struct lttcomm_relayd_hdr recv_hdr
;
2438 struct relay_connection
*destroy_conn
= NULL
;
2440 DBG("[thread] Relay worker started");
2442 rcu_register_thread();
2444 health_register(health_relayd
, HEALTH_RELAYD_TYPE_WORKER
);
2446 if (testpoint(relayd_thread_worker
)) {
2447 goto error_testpoint
;
2450 health_code_update();
2452 /* table of connections indexed on socket */
2453 relay_connections_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
2454 if (!relay_connections_ht
) {
2455 goto relay_connections_ht_error
;
2458 ret
= create_thread_poll_set(&events
, 2);
2460 goto error_poll_create
;
2463 ret
= lttng_poll_add(&events
, relay_conn_pipe
[0], LPOLLIN
| LPOLLRDHUP
);
2470 int idx
= -1, i
, seen_control
= 0, last_notdel_data_fd
= -1;
2472 health_code_update();
2474 /* Infinite blocking call, waiting for transmission */
2475 DBG3("Relayd worker thread polling...");
2476 health_poll_entry();
2477 ret
= lttng_poll_wait(&events
, -1);
2481 * Restart interrupted system call.
2483 if (errno
== EINTR
) {
2492 * Process control. The control connection is
2493 * prioritized so we don't starve it with high
2494 * throughput tracing data on the data connection.
2496 for (i
= 0; i
< nb_fd
; i
++) {
2497 /* Fetch once the poll data */
2498 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2499 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2501 health_code_update();
2505 * No activity for this FD (poll
2511 /* Thread quit pipe has been closed. Killing thread. */
2512 ret
= check_thread_quit_pipe(pollfd
, revents
);
2518 /* Inspect the relay conn pipe for new connection */
2519 if (pollfd
== relay_conn_pipe
[0]) {
2520 if (revents
& LPOLLIN
) {
2521 struct relay_connection
*conn
;
2523 ret
= lttng_read(relay_conn_pipe
[0], &conn
, sizeof(conn
));
2527 lttng_poll_add(&events
, conn
->sock
->fd
,
2528 LPOLLIN
| LPOLLRDHUP
);
2529 connection_ht_add(relay_connections_ht
, conn
);
2530 DBG("Connection socket %d added", conn
->sock
->fd
);
2531 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2532 ERR("Relay connection pipe error");
2535 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
2539 struct relay_connection
*ctrl_conn
;
2541 ctrl_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2542 /* If not found, there is a synchronization issue. */
2545 if (ctrl_conn
->type
== RELAY_DATA
) {
2546 if (revents
& LPOLLIN
) {
2548 * Flag the last seen data fd not deleted. It will be
2549 * used as the last seen fd if any fd gets deleted in
2552 last_notdel_data_fd
= pollfd
;
2554 goto put_ctrl_connection
;
2556 assert(ctrl_conn
->type
== RELAY_CONTROL
);
2558 if (revents
& LPOLLIN
) {
2559 ret
= ctrl_conn
->sock
->ops
->recvmsg(ctrl_conn
->sock
,
2560 &recv_hdr
, sizeof(recv_hdr
), 0);
2562 /* Connection closed */
2563 relay_thread_close_connection(&events
, pollfd
,
2566 ret
= relay_process_control(&recv_hdr
, ctrl_conn
);
2568 /* Clear the session on error. */
2569 relay_thread_close_connection(&events
,
2574 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2575 relay_thread_close_connection(&events
,
2577 if (last_seen_data_fd
== pollfd
) {
2578 last_seen_data_fd
= last_notdel_data_fd
;
2581 ERR("Unexpected poll events %u for control sock %d",
2583 connection_put(ctrl_conn
);
2586 put_ctrl_connection
:
2587 connection_put(ctrl_conn
);
2592 * The last loop handled a control request, go back to poll to make
2593 * sure we prioritise the control socket.
2599 if (last_seen_data_fd
>= 0) {
2600 for (i
= 0; i
< nb_fd
; i
++) {
2601 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2603 health_code_update();
2605 if (last_seen_data_fd
== pollfd
) {
2612 /* Process data connection. */
2613 for (i
= idx
+ 1; i
< nb_fd
; i
++) {
2614 /* Fetch the poll data. */
2615 uint32_t revents
= LTTNG_POLL_GETEV(&events
, i
);
2616 int pollfd
= LTTNG_POLL_GETFD(&events
, i
);
2617 struct relay_connection
*data_conn
;
2619 health_code_update();
2622 /* No activity for this FD (poll implementation). */
2626 /* Skip the command pipe. It's handled in the first loop. */
2627 if (pollfd
== relay_conn_pipe
[0]) {
2631 data_conn
= connection_get_by_sock(relay_connections_ht
, pollfd
);
2633 /* Skip it. Might be removed before. */
2636 if (data_conn
->type
== RELAY_CONTROL
) {
2637 goto put_data_connection
;
2639 assert(data_conn
->type
== RELAY_DATA
);
2641 if (revents
& LPOLLIN
) {
2642 ret
= relay_process_data(data_conn
);
2643 /* Connection closed */
2645 relay_thread_close_connection(&events
, pollfd
,
2648 * Every goto restart call sets the last seen fd where
2649 * here we don't really care since we gracefully
2650 * continue the loop after the connection is deleted.
2653 /* Keep last seen port. */
2654 last_seen_data_fd
= pollfd
;
2655 connection_put(data_conn
);
2658 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
2659 relay_thread_close_connection(&events
, pollfd
,
2662 ERR("Unknown poll events %u for data sock %d",
2665 put_data_connection
:
2666 connection_put(data_conn
);
2668 last_seen_data_fd
= -1;
2671 /* Normal exit, no error */
2676 /* Cleanup reamaining connection object. */
2678 cds_lfht_for_each_entry(relay_connections_ht
->ht
, &iter
.iter
,
2681 health_code_update();
2683 * No need to grab another ref, because we own
2686 relay_thread_close_connection(&events
, destroy_conn
->sock
->fd
,
2691 lttng_poll_clean(&events
);
2693 lttng_ht_destroy(relay_connections_ht
);
2694 relay_connections_ht_error
:
2695 /* Close relay conn pipes */
2696 utils_close_pipe(relay_conn_pipe
);
2698 DBG("Thread exited with error");
2700 DBG("Worker thread cleanup complete");
2705 ERR("Health error occurred in %s", __func__
);
2707 health_unregister(health_relayd
);
2708 rcu_unregister_thread();
2709 lttng_relay_stop_threads();
2714 * Create the relay command pipe to wake thread_manage_apps.
2715 * Closed in cleanup().
2717 static int create_relay_conn_pipe(void)
2721 ret
= utils_create_pipe_cloexec(relay_conn_pipe
);
2729 int main(int argc
, char **argv
)
2731 int ret
= 0, retval
= 0;
2734 /* Parse arguments */
2736 if (set_options(argc
, argv
)) {
2741 if (set_signal_handler()) {
2746 /* Try to create directory if -o, --output is specified. */
2747 if (opt_output_path
) {
2748 if (*opt_output_path
!= '/') {
2749 ERR("Please specify an absolute path for -o, --output PATH");
2754 ret
= utils_mkdir_recursive(opt_output_path
, S_IRWXU
| S_IRWXG
,
2757 ERR("Unable to create %s", opt_output_path
);
2764 if (opt_daemon
|| opt_background
) {
2767 ret
= lttng_daemonize(&child_ppid
, &recv_child_signal
,
2775 * We are in the child. Make sure all other file
2776 * descriptors are closed, in case we are called with
2777 * more opened file descriptors than the standard ones.
2779 for (i
= 3; i
< sysconf(_SC_OPEN_MAX
); i
++) {
2785 /* Initialize thread health monitoring */
2786 health_relayd
= health_app_create(NR_HEALTH_RELAYD_TYPES
);
2787 if (!health_relayd
) {
2788 PERROR("health_app_create error");
2790 goto exit_health_app_create
;
2793 /* Create thread quit pipe */
2794 if (init_thread_quit_pipe()) {
2796 goto exit_init_data
;
2799 /* Check if daemon is UID = 0 */
2801 if (control_uri
->port
< 1024 || data_uri
->port
< 1024 || live_uri
->port
< 1024) {
2802 ERR("Need to be root to use ports < 1024");
2804 goto exit_init_data
;
2808 /* Setup the thread apps communication pipe. */
2809 if (create_relay_conn_pipe()) {
2811 goto exit_init_data
;
2814 /* Init relay command queue. */
2815 cds_wfcq_init(&relay_conn_queue
.head
, &relay_conn_queue
.tail
);
2817 /* Set up max poll set size */
2818 if (lttng_poll_set_max_size()) {
2820 goto exit_init_data
;
2823 /* Initialize communication library */
2825 lttcomm_inet_init();
2827 /* tables of sessions indexed by session ID */
2828 sessions_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2831 goto exit_init_data
;
2834 /* tables of streams indexed by stream ID */
2835 relay_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2836 if (!relay_streams_ht
) {
2838 goto exit_init_data
;
2841 /* tables of streams indexed by stream ID */
2842 viewer_streams_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
2843 if (!viewer_streams_ht
) {
2845 goto exit_init_data
;
2848 ret
= utils_create_pipe(health_quit_pipe
);
2851 goto exit_health_quit_pipe
;
2854 /* Create thread to manage the client socket */
2855 ret
= pthread_create(&health_thread
, NULL
,
2856 thread_manage_health
, (void *) NULL
);
2859 PERROR("pthread_create health");
2861 goto exit_health_thread
;
2864 /* Setup the dispatcher thread */
2865 ret
= pthread_create(&dispatcher_thread
, NULL
,
2866 relay_thread_dispatcher
, (void *) NULL
);
2869 PERROR("pthread_create dispatcher");
2871 goto exit_dispatcher_thread
;
2874 /* Setup the worker thread */
2875 ret
= pthread_create(&worker_thread
, NULL
,
2876 relay_thread_worker
, NULL
);
2879 PERROR("pthread_create worker");
2881 goto exit_worker_thread
;
2884 /* Setup the listener thread */
2885 ret
= pthread_create(&listener_thread
, NULL
,
2886 relay_thread_listener
, (void *) NULL
);
2889 PERROR("pthread_create listener");
2891 goto exit_listener_thread
;
2894 ret
= relayd_live_create(live_uri
);
2896 ERR("Starting live viewer threads");
2902 * This is where we start awaiting program completion (e.g. through
2903 * signal that asks threads to teardown).
2906 ret
= relayd_live_join();
2912 ret
= pthread_join(listener_thread
, &status
);
2915 PERROR("pthread_join listener_thread");
2919 exit_listener_thread
:
2920 ret
= pthread_join(worker_thread
, &status
);
2923 PERROR("pthread_join worker_thread");
2928 ret
= pthread_join(dispatcher_thread
, &status
);
2931 PERROR("pthread_join dispatcher_thread");
2934 exit_dispatcher_thread
:
2936 ret
= pthread_join(health_thread
, &status
);
2939 PERROR("pthread_join health_thread");
2944 utils_close_pipe(health_quit_pipe
);
2945 exit_health_quit_pipe
:
2948 health_app_destroy(health_relayd
);
2949 exit_health_app_create
:
2953 /* Ensure all prior call_rcu are done. */