From 23c8ff5013f1e8c132cab7845ca608dbed4fca7f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 12 Mar 2019 17:20:34 -0400 Subject: [PATCH] relayd: create sessiond trace chunk registry on session creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use the sessiond_trace_chunk_registry_session_created() and sessiond_trace_chunk_registry_session_destroyed() to allow the sessiond trace chunk registry the ability to manage trace chunk registries associated with the various session daemons from which the consumer daemon connections originate. These notifiers effectively manipulate the reference count (and create/destroy, as needed) of the lttng_trace_chunk_registry associated with each session daemon (using their UUID). Signed-off-by: Jérémie Galarneau --- src/bin/lttng-relayd/cmd-2-11.c | 5 ++++- src/bin/lttng-relayd/cmd-2-11.h | 4 +++- src/bin/lttng-relayd/lttng-relayd.h | 3 +++ src/bin/lttng-relayd/main.c | 25 +++++++++++++++++++++++-- src/bin/lttng-relayd/session.c | 15 ++++++++++++++- src/bin/lttng-relayd/session.h | 5 ++++- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/bin/lttng-relayd/cmd-2-11.c b/src/bin/lttng-relayd/cmd-2-11.c index e2d71a0d1..857f35942 100644 --- a/src/bin/lttng-relayd/cmd-2-11.c +++ b/src/bin/lttng-relayd/cmd-2-11.c @@ -31,7 +31,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, char *session_name, char *hostname, - uint32_t *live_timer, bool *snapshot) + uint32_t *live_timer, bool *snapshot, + lttng_uuid sessiond_uuid) { int ret; struct lttcomm_relayd_create_session_2_11 header; @@ -53,6 +54,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload, header.hostname_len = be32toh(header.hostname_len); header.live_timer = be32toh(header.live_timer); + lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid); + received_names_size = header.session_name_len + header.hostname_len; if (payload->size < header_len + received_names_size) { ERR("Unexpected payload size in \"cmd_create_session_2_11\": expected >= %zu bytes, got %zu bytes", diff --git a/src/bin/lttng-relayd/cmd-2-11.h b/src/bin/lttng-relayd/cmd-2-11.h index a50872bd3..54f6f409f 100644 --- a/src/bin/lttng-relayd/cmd-2-11.h +++ b/src/bin/lttng-relayd/cmd-2-11.h @@ -19,10 +19,12 @@ #include "lttng-relayd.h" #include +#include int cmd_create_session_2_11(const struct lttng_buffer_view *payload, char *session_name, char *hostname, - uint32_t *live_timer, bool *snapshot); + uint32_t *live_timer, bool *snapshot, + lttng_uuid sessiond_uuid); int cmd_recv_stream_2_11(const struct lttng_buffer_view *payload, char **ret_path_name, char **ret_channel_name, diff --git a/src/bin/lttng-relayd/lttng-relayd.h b/src/bin/lttng-relayd/lttng-relayd.h index e4e29e781..40fecd603 100644 --- a/src/bin/lttng-relayd/lttng-relayd.h +++ b/src/bin/lttng-relayd/lttng-relayd.h @@ -26,6 +26,8 @@ #include +struct sessiond_trace_chunk_registry; + /* * Queue used to enqueue relay requests */ @@ -43,6 +45,7 @@ struct relay_conn_queue { extern struct lttng_ht *sessions_ht; extern struct lttng_ht *relay_streams_ht; extern struct lttng_ht *viewer_streams_ht; +extern struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry; extern char *opt_output_path; extern const char *tracing_group_name; diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 0ee27efce..c7760cca4 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -74,6 +74,7 @@ #include "connection.h" #include "tracefile-array.h" #include "tcp_keep_alive.h" +#include "sessiond-trace-chunks.h" static const char *help_msg = #ifdef LTTNG_EMBED_HELP @@ -167,6 +168,8 @@ struct lttng_ht *sessions_ht; /* Relayd health monitoring */ struct health_app *health_relayd; +struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry; + static struct option long_options[] = { { "control-port", 1, 0, 'C', }, { "data-port", 1, 0, 'D', }, @@ -1097,6 +1100,8 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, char hostname[LTTNG_HOST_NAME_MAX]; uint32_t live_timer = 0; bool snapshot = false; + /* Left nil for peers < 2.11. */ + lttng_uuid sessiond_uuid = {}; memset(session_name, 0, LTTNG_NAME_MAX); memset(hostname, 0, LTTNG_HOST_NAME_MAX); @@ -1113,7 +1118,14 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, } else { /* From 2.11 to ... */ ret = cmd_create_session_2_11(payload, session_name, - hostname, &live_timer, &snapshot); + hostname, &live_timer, &snapshot, + sessiond_uuid); + if (lttng_uuid_is_nil(sessiond_uuid)) { + /* The nil UUID is reserved for pre-2.11 clients. */ + ERR("Illegal nil UUID announced by peer in create session command"); + ret = -1; + goto send_reply; + } } if (ret < 0) { @@ -1121,7 +1133,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr, } session = session_create(session_name, hostname, live_timer, - snapshot, conn->major, conn->minor); + snapshot, sessiond_uuid, conn->major, conn->minor); if (!session) { ret = -1; goto send_reply; @@ -4116,6 +4128,13 @@ int main(int argc, char **argv) } } + sessiond_trace_chunk_registry = sessiond_trace_chunk_registry_create(); + if (!sessiond_trace_chunk_registry) { + ERR("Failed to initialize session daemon trace chunk registry"); + retval = -1; + goto exit_sessiond_trace_chunk_registry; + } + /* Initialize thread health monitoring */ health_relayd = health_app_create(NR_HEALTH_RELAYD_TYPES); if (!health_relayd) { @@ -4265,7 +4284,9 @@ exit_health_quit_pipe: exit_init_data: health_app_destroy(health_relayd); + sessiond_trace_chunk_registry_destroy(sessiond_trace_chunk_registry); exit_health_app_create: +exit_sessiond_trace_chunk_registry: exit_options: /* * Wait for all pending call_rcu work to complete before tearing diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.c index 42c29aeb0..4730d0512 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.c @@ -25,6 +25,7 @@ #include "ctf-trace.h" #include "session.h" #include "stream.h" +#include "sessiond-trace-chunks.h" /* Global session id used in the session creation. */ static uint64_t last_relay_session_id; @@ -37,8 +38,10 @@ static pthread_mutex_t last_relay_session_id_lock = PTHREAD_MUTEX_INITIALIZER; */ struct relay_session *session_create(const char *session_name, const char *hostname, uint32_t live_timer, - bool snapshot, uint32_t major, uint32_t minor) + bool snapshot, const lttng_uuid sessiond_uuid, + uint32_t major, uint32_t minor) { + int ret; struct relay_session *session; session = zmalloc(sizeof(*session)); @@ -73,6 +76,13 @@ struct relay_session *session_create(const char *session_name, session->live_timer = live_timer; session->snapshot = snapshot; + lttng_uuid_copy(session->sessiond_uuid, sessiond_uuid); + + ret = sessiond_trace_chunk_registry_session_created( + sessiond_trace_chunk_registry, sessiond_uuid); + if (ret) { + goto error; + } lttng_ht_add_unique_u64(sessions_ht, &session->session_n); return session; @@ -154,6 +164,9 @@ static void destroy_session(struct relay_session *session) ret = session_delete(session); assert(!ret); + ret = sessiond_trace_chunk_registry_session_destroyed( + sessiond_trace_chunk_registry, session->sessiond_uuid); + assert(!ret); call_rcu(&session->rcu_node, rcu_destroy_session); } diff --git a/src/bin/lttng-relayd/session.h b/src/bin/lttng-relayd/session.h index 2410fd483..5731310f0 100644 --- a/src/bin/lttng-relayd/session.h +++ b/src/bin/lttng-relayd/session.h @@ -28,6 +28,7 @@ #include #include +#include /* * Represents a session for the relay point of view @@ -39,6 +40,7 @@ struct relay_session { * It is used to match a set of streams to their session. */ uint64_t id; + lttng_uuid sessiond_uuid; char session_name[LTTNG_NAME_MAX]; char hostname[LTTNG_HOST_NAME_MAX]; uint32_t live_timer; @@ -110,7 +112,8 @@ struct relay_session { struct relay_session *session_create(const char *session_name, const char *hostname, uint32_t live_timer, - bool snapshot, uint32_t major, uint32_t minor); + bool snapshot, const lttng_uuid sessiond_uuid, + uint32_t major, uint32_t minor); struct relay_session *session_get_by_id(uint64_t id); bool session_get(struct relay_session *session); void session_put(struct relay_session *session); -- 2.34.1