relayd: create sessiond trace chunk registry on session creation
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 12 Mar 2019 21:20:34 +0000 (17:20 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Jul 2019 19:51:46 +0000 (15:51 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/cmd-2-11.c
src/bin/lttng-relayd/cmd-2-11.h
src/bin/lttng-relayd/lttng-relayd.h
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/session.c
src/bin/lttng-relayd/session.h

index e2d71a0d1351f848a1df2493b6554e737b303278..857f3594299ebe7f17ae90ecb703d73321484202 100644 (file)
@@ -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",
index a50872bd360773a44a5bb48e977809c3e10bd624..54f6f409f1fe9308448dd1b3403e66f4a53c8126 100644 (file)
 
 #include "lttng-relayd.h"
 #include <common/buffer-view.h>
+#include <common/compat/uuid.h>
 
 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,
index e4e29e781e3ed8233cfdb6c82ddbe7ee32618038..40fecd603d5ea5c06994fed66affa81f1ad95016 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <common/hashtable/hashtable.h>
 
+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;
index 0ee27efce03af5a5dfa7d6f07c8899c001626f10..c7760cca45b67feaac6f7e50b0edb03d7d74e72d 100644 (file)
@@ -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
index 42c29aeb0b4816f5d83437f14aa6a4f3631762aa..4730d0512e5bdb88e6a29275f18e5faeb5d5d4ce 100644 (file)
@@ -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);
 }
 
index 2410fd483ad8ae74f82902c8aafac152573f506d..5731310f09f6ac7b7e611f648012578072f19a6c 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <lttng/constant.h>
 #include <common/hashtable/hashtable.h>
+#include <common/compat/uuid.h>
 
 /*
  * 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);
This page took 0.029585 seconds and 4 git commands to generate.