Send session creation time to relay daemon when supported
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 19 Jul 2019 22:54:10 +0000 (18:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Aug 2019 15:28:43 +0000 (11:28 -0400)
A recent commit changed the way the creation timestamp was added to a
session's output path; the session creation timestamp is now (2.11+)
sampled at creation time and formatted when the session's output
directory is created.

The 2.11+ version of the session and stream creation commands allow
the relay daemon to use all components of the path independently to
format an output path rather than relying on the session daemon peer
to format it ahead of time.

In order to maintain the timestamped session folder name created by
previous versions, the relay daemon now receives the session's
creation timestamp and formats it rather than relying on it being
"cooked" into the transmitted session name.

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/main.c
src/bin/lttng-relayd/session.c
src/bin/lttng-relayd/session.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng-sessiond/consumer.h
src/common/relayd/relayd.c
src/common/relayd/relayd.h
src/common/sessiond-comm/relayd.h

index 363e0f00022984a2b758eca59811017d80bb0e1c..7d90be9f9f014d1f87cd0b05aba7f74591b1b3f9 100644 (file)
@@ -33,7 +33,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                char *session_name, char *hostname,
                uint32_t *live_timer, bool *snapshot,
                uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
-               bool *has_current_chunk, uint64_t *current_chunk_id)
+               bool *has_current_chunk, uint64_t *current_chunk_id,
+               time_t *creation_time)
 {
        int ret;
        struct lttcomm_relayd_create_session_2_11 header;
@@ -56,6 +57,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
        header.live_timer = be32toh(header.live_timer);
        header.current_chunk_id.value = be64toh(header.current_chunk_id.value);
        header.current_chunk_id.is_set = !!header.current_chunk_id.is_set;
+       header.creation_time = be64toh(header.creation_time);
 
        lttng_uuid_copy(sessiond_uuid, header.sessiond_uuid);
 
@@ -108,6 +110,7 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
        *snapshot = !!header.snapshot;
        *current_chunk_id = header.current_chunk_id.value;
        *has_current_chunk = header.current_chunk_id.is_set;
+       *creation_time = (time_t) header.creation_time;
 
        ret = 0;
 
index 7961d91ffa6d7a78226c702773142dac0c1342a5..d2af458177a97498434f74c89ffa1ad83dbaddef 100644 (file)
@@ -25,7 +25,8 @@ int cmd_create_session_2_11(const struct lttng_buffer_view *payload,
                char *session_name, char *hostname,
                uint32_t *live_timer, bool *snapshot,
                uint64_t *id_sessiond, lttng_uuid sessiond_uuid,
-               bool *has_current_chunk, uint64_t *current_chunk_id);
+               bool *has_current_chunk, uint64_t *current_chunk_id,
+               time_t *creation_time);
 
 int cmd_recv_stream_2_11(const struct lttng_buffer_view *payload,
                char **ret_path_name, char **ret_channel_name,
index b5ae34ebf9c9989bbd9b72417cdcd427ad9d9546..c0e9d76dfd79550d920a021e3f2b3018cf387483 100644 (file)
@@ -1104,6 +1104,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
        lttng_uuid sessiond_uuid = {};
        LTTNG_OPTIONAL(uint64_t) id_sessiond = {};
        LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
+       LTTNG_OPTIONAL(time_t) creation_time = {};
 
        if (conn->minor < 4) {
                /* From 2.1 to 2.3 */
@@ -1114,21 +1115,27 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
                        hostname, &live_timer, &snapshot);
        } else {
                bool has_current_chunk;
+               uint64_t current_chunk_id_value;
+               time_t creation_time_value;
+               uint64_t id_sessiond_value;
 
                /* From 2.11 to ... */
-               ret = cmd_create_session_2_11(payload, session_name,
-                               hostname, &live_timer, &snapshot,
-                               &id_sessiond.value, sessiond_uuid,
-                               &has_current_chunk,
-                               &current_chunk_id.value);
+               ret = cmd_create_session_2_11(payload, session_name, hostname,
+                               &live_timer, &snapshot, &id_sessiond_value,
+                               sessiond_uuid, &has_current_chunk,
+                               &current_chunk_id_value, &creation_time_value);
                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;
                }
-               id_sessiond.is_set = true;
-               current_chunk_id.is_set = has_current_chunk;
+               LTTNG_OPTIONAL_SET(&id_sessiond, id_sessiond_value);
+               LTTNG_OPTIONAL_SET(&creation_time, creation_time_value);
+               if (has_current_chunk) {
+                       LTTNG_OPTIONAL_SET(&current_chunk_id,
+                                       current_chunk_id_value);
+               }
        }
 
        if (ret < 0) {
@@ -1139,6 +1146,7 @@ static int relay_create_session(const struct lttcomm_relayd_hdr *recv_hdr,
                        snapshot, sessiond_uuid,
                        id_sessiond.is_set ? &id_sessiond.value : NULL,
                        current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                       creation_time.is_set ? &creation_time.value : NULL,
                        conn->major, conn->minor);
        if (!session) {
                ret = -1;
index e087b51c3b71ceece2d66d71faa6b3d62d905810..fa211fe02bf6633bb60ffbacebdb4b2c95352408 100644 (file)
@@ -74,10 +74,15 @@ end:
  * Return allocated session or else NULL.
  */
 struct relay_session *session_create(const char *session_name,
-               const char *hostname, uint32_t live_timer,
-               bool snapshot, const lttng_uuid sessiond_uuid,
-               uint64_t *id_sessiond, uint64_t *current_chunk_id,
-               uint32_t major, uint32_t minor)
+               const char *hostname,
+               uint32_t live_timer,
+               bool snapshot,
+               const lttng_uuid sessiond_uuid,
+               const uint64_t *id_sessiond,
+               const uint64_t *current_chunk_id,
+               const time_t *creation_time,
+               uint32_t major,
+               uint32_t minor)
 {
        int ret;
        struct relay_session *session;
@@ -156,6 +161,9 @@ struct relay_session *session_create(const char *session_name,
        }
 
        lttng_ht_add_unique_u64(sessions_ht, &session->session_n);
+       if (creation_time) {
+               LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time);
+       }
        return session;
 
 error:
index 8c679da9c975c858e2bd863a73e9ccc9aae9480f..8b8ae1f2118d33e31ae989b72488aa3c515b6f10 100644 (file)
@@ -52,6 +52,7 @@ struct relay_session {
         * the other cases.
         */
        lttng_uuid sessiond_uuid;
+       LTTNG_OPTIONAL(time_t) creation_time;
        char session_name[LTTNG_NAME_MAX];
        char hostname[LTTNG_HOST_NAME_MAX];
        uint32_t live_timer;
@@ -123,10 +124,15 @@ struct relay_session {
 };
 
 struct relay_session *session_create(const char *session_name,
-               const char *hostname, uint32_t live_timer,
-               bool snapshot, const lttng_uuid sessiond_uuid,
-               uint64_t *id_sessiond, uint64_t *current_chunk_id,
-               uint32_t major, uint32_t minor);
+               const char *hostname,
+               uint32_t live_timer,
+               bool snapshot,
+               const lttng_uuid sessiond_uuid,
+               const uint64_t *id_sessiond,
+               const uint64_t *current_chunk_id,
+               const time_t *creation_time,
+               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);
index 6e5128917b474cd4d970669ba6ec25d06ef4dba8..5e1a59a5032d72758c9216a553bb9208f5f733a5 100644 (file)
@@ -1039,7 +1039,8 @@ static enum lttng_error_code send_consumer_relayd_socket(
                struct consumer_socket *consumer_sock,
                const char *session_name, const char *hostname,
                int session_live_timer,
-               const uint64_t *current_chunk_id)
+               const uint64_t *current_chunk_id,
+               time_t session_creation_time)
 {
        int ret;
        struct lttcomm_relayd_sock *rsock = NULL;
@@ -1068,7 +1069,7 @@ static enum lttng_error_code send_consumer_relayd_socket(
        ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
                        relayd_uri->stype, session_id,
                        session_name, hostname, session_live_timer,
-                       current_chunk_id);
+                       current_chunk_id, session_creation_time);
        if (ret < 0) {
                status = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -1116,7 +1117,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                unsigned int session_id, struct consumer_output *consumer,
                struct consumer_socket *sock, const char *session_name,
                const char *hostname, int session_live_timer,
-               const uint64_t *current_chunk_id)
+               const uint64_t *current_chunk_id, time_t session_creation_time)
 {
        enum lttng_error_code status = LTTNG_OK;
 
@@ -1128,7 +1129,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.control, consumer, sock,
                                session_name, hostname, session_live_timer,
-                               current_chunk_id);
+                               current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1139,7 +1140,7 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.data, consumer, sock,
                                session_name, hostname, session_live_timer,
-                               current_chunk_id);
+                               current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1195,7 +1196,8 @@ int cmd_setup_relayd(struct ltt_session *session)
                                        usess->consumer, socket,
                                        session->name, session->hostname,
                                        session->live_timer,
-                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL);
+                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                                       session->creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -1218,7 +1220,8 @@ int cmd_setup_relayd(struct ltt_session *session)
                                        ksess->consumer, socket,
                                        session->name, session->hostname,
                                        session->live_timer,
-                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL);
+                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                                       session->creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -4243,7 +4246,8 @@ static enum lttng_error_code set_relayd_for_snapshot(
                                snap_output->consumer, socket,
                                session->name, session->hostname,
                                session->live_timer,
-                               current_chunk_id.is_set ? &current_chunk_id.value : NULL);
+                               current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                               session->creation_time);
                pthread_mutex_unlock(socket->lock);
                if (status != LTTNG_OK) {
                        rcu_read_unlock();
index 155f2b053aca8dfdfc3653c4c9bfdd7eb8f71ada..10152864e9940beb0e6b3d4423fdd4a7e6013fcd 100644 (file)
@@ -1079,7 +1079,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
                struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
                enum lttng_stream_type type, uint64_t session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer, const uint64_t *current_chunk_id)
+               int session_live_timer, const uint64_t *current_chunk_id,
+               time_t session_creation_time)
 {
        int ret;
        struct lttcomm_consumer_msg msg;
@@ -1101,7 +1102,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
                                &msg.u.relayd_sock.relayd_session_id,
                                session_name, hostname, session_live_timer,
                                consumer->snapshot, session_id,
-                               sessiond_uuid, current_chunk_id);
+                               sessiond_uuid, current_chunk_id,
+                               session_creation_time);
                if (ret < 0) {
                        /* Close the control socket. */
                        (void) relayd_close(rsock);
index 13ebcd0350a75d1b404244a40226e8ab0d4562ab..59585eda34ca17134ebd8a2c8e21582aa197436e 100644 (file)
@@ -219,7 +219,8 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock,
                struct lttcomm_relayd_sock *rsock, struct consumer_output *consumer,
                enum lttng_stream_type type, uint64_t session_id,
                const char *session_name, const char *hostname,
-               int session_live_timer, const uint64_t *current_chunk_id);
+               int session_live_timer, const uint64_t *current_chunk_id,
+               time_t session_creation_time);
 int consumer_send_channel_monitor_pipe(struct consumer_socket *consumer_sock,
                int pipe);
 int consumer_send_destroy_relayd(struct consumer_socket *sock,
index 830c7c263f89935f0ecf00cc91ca5d17cc9fa320..87782e99477af6b3321ca40d597ed7b5c521f9b0 100644 (file)
@@ -130,7 +130,8 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
                const char *session_name, const char *hostname,
                int session_live_timer, unsigned int snapshot,
                uint64_t sessiond_session_id, const lttng_uuid sessiond_uuid,
-               const uint64_t *current_chunk_id)
+               const uint64_t *current_chunk_id,
+               time_t creation_time)
 {
        int ret;
        struct lttcomm_relayd_create_session_2_11 *msg = NULL;
@@ -176,6 +177,8 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
                                htobe64(*current_chunk_id));
        }
 
+       msg->creation_time = htobe64((uint64_t) creation_time);
+
        /* Send command */
        ret = send_command(rsock, RELAYD_CREATE_SESSION, msg, msg_length, 0);
        if (ret < 0) {
@@ -248,7 +251,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
                const lttng_uuid sessiond_uuid,
-               const uint64_t *current_chunk_id)
+               const uint64_t *current_chunk_id,
+               time_t creation_time)
 {
        int ret;
        struct lttcomm_relayd_status_session reply;
@@ -270,7 +274,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                ret = relayd_create_session_2_11(rsock, session_name,
                                hostname, session_live_timer, snapshot,
                                sessiond_session_id, sessiond_uuid,
-                               current_chunk_id);
+                               current_chunk_id, creation_time);
        }
 
        if (ret < 0) {
index eb7782de050761618c07d8aeee3198209f79b879..033189bf14b6802075494c8329273f4faaca5335 100644 (file)
@@ -32,7 +32,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                int session_live_timer,
                unsigned int snapshot, uint64_t sessiond_session_id,
                const lttng_uuid sessiond_uuid,
-               const uint64_t *current_chunk_id);
+               const uint64_t *current_chunk_id,
+               time_t creation_time);
 int relayd_add_stream(struct lttcomm_relayd_sock *sock, const char *channel_name,
                const char *pathname, uint64_t *stream_id,
                uint64_t tracefile_size, uint64_t tracefile_count,
index 1568f51137a6042b1a921767e09c9793ed35b9cc..2ae94b3655ba262d57a71f9182f4f5ab2f64ceb5 100644 (file)
@@ -212,7 +212,9 @@ struct lttcomm_relayd_create_session_2_11 {
        lttng_uuid sessiond_uuid;
        /* Sessiond session id */
         uint64_t session_id;
-       LTTNG_OPTIONAL_COMM(uint64_t) current_chunk_id;
+       /* Session creation time, in seconds since UNIX Epoch. */
+       uint64_t creation_time;
+       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id;
        /* Contains the session_name and hostname */
        char names[];
 } LTTNG_PACKED;
This page took 0.035206 seconds and 4 git commands to generate.