Send session creation time to relay daemon when supported
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 84d6fd9b389f7ada44caacbb5f7d3fd1ccb1589e..5e1a59a5032d72758c9216a553bb9208f5f733a5 100644 (file)
@@ -1038,7 +1038,9 @@ static enum lttng_error_code send_consumer_relayd_socket(
                struct consumer_output *consumer,
                struct consumer_socket *consumer_sock,
                const char *session_name, const char *hostname,
-               int session_live_timer)
+               int session_live_timer,
+               const uint64_t *current_chunk_id,
+               time_t session_creation_time)
 {
        int ret;
        struct lttcomm_relayd_sock *rsock = NULL;
@@ -1066,7 +1068,8 @@ static enum lttng_error_code send_consumer_relayd_socket(
        /* Send relayd socket to consumer. */
        ret = consumer_send_relayd_socket(consumer_sock, rsock, consumer,
                        relayd_uri->stype, session_id,
-                       session_name, hostname, session_live_timer);
+                       session_name, hostname, session_live_timer,
+                       current_chunk_id, session_creation_time);
        if (ret < 0) {
                status = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
                goto close_sock;
@@ -1113,7 +1116,8 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                enum lttng_domain_type domain,
                unsigned int session_id, struct consumer_output *consumer,
                struct consumer_socket *sock, const char *session_name,
-               const char *hostname, int session_live_timer)
+               const char *hostname, int session_live_timer,
+               const uint64_t *current_chunk_id, time_t session_creation_time)
 {
        enum lttng_error_code status = LTTNG_OK;
 
@@ -1124,7 +1128,8 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->control_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.control, consumer, sock,
-                               session_name, hostname, session_live_timer);
+                               session_name, hostname, session_live_timer,
+                               current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1134,7 +1139,8 @@ static enum lttng_error_code send_consumer_relayd_sockets(
        if (!sock->data_sock_sent) {
                status = send_consumer_relayd_socket(session_id,
                                &consumer->dst.net.data, consumer, sock,
-                               session_name, hostname, session_live_timer);
+                               session_name, hostname, session_live_timer,
+                               current_chunk_id, session_creation_time);
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -1156,14 +1162,28 @@ int cmd_setup_relayd(struct ltt_session *session)
        struct ltt_kernel_session *ksess;
        struct consumer_socket *socket;
        struct lttng_ht_iter iter;
+        LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
 
-       assert(session);
+        assert(session);
 
        usess = session->ust_session;
        ksess = session->kernel_session;
 
        DBG("Setting relayd for session %s", session->name);
 
+       if (session->current_trace_chunk) {
+               enum lttng_trace_chunk_status status = lttng_trace_chunk_get_id(
+                               session->current_trace_chunk, &current_chunk_id.value);
+
+               if (status == LTTNG_TRACE_CHUNK_STATUS_OK) {
+                       current_chunk_id.is_set = true;
+               } else {
+                       ERR("Failed to get current trace chunk id");
+                       ret = LTTNG_ERR_UNK;
+                       goto error;
+               }
+       }
+
        rcu_read_lock();
 
        if (usess && usess->consumer && usess->consumer->type == CONSUMER_DST_NET
@@ -1175,7 +1195,9 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id,
                                        usess->consumer, socket,
                                        session->name, session->hostname,
-                                       session->live_timer);
+                                       session->live_timer,
+                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                                       session->creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -1197,7 +1219,9 @@ int cmd_setup_relayd(struct ltt_session *session)
                        ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id,
                                        ksess->consumer, socket,
                                        session->name, session->hostname,
-                                       session->live_timer);
+                                       session->live_timer,
+                                       current_chunk_id.is_set ? &current_chunk_id.value : NULL,
+                                       session->creation_time);
                        pthread_mutex_unlock(socket->lock);
                        if (ret != LTTNG_OK) {
                                goto error;
@@ -4184,6 +4208,7 @@ static enum lttng_error_code set_relayd_for_snapshot(
        enum lttng_error_code status = LTTNG_OK;
        struct lttng_ht_iter iter;
        struct consumer_socket *socket;
+       LTTNG_OPTIONAL(uint64_t) current_chunk_id = {};
 
        assert(consumer);
        assert(snap_output);
@@ -4191,6 +4216,19 @@ static enum lttng_error_code set_relayd_for_snapshot(
 
        DBG2("Set relayd object from snapshot output");
 
+       if (session->current_trace_chunk) {
+               enum lttng_trace_chunk_status status = lttng_trace_chunk_get_id(
+                               session->current_trace_chunk, &current_chunk_id.value);
+
+               if (status == LTTNG_TRACE_CHUNK_STATUS_OK) {
+                       current_chunk_id.is_set = true;
+               } else {
+                       ERR("Failed to get current trace chunk id");
+                       status = LTTNG_ERR_UNK;
+                       goto error;
+               }
+       }
+
        /* Ignore if snapshot consumer output is not network. */
        if (snap_output->consumer->type != CONSUMER_DST_NET) {
                goto error;
@@ -4207,7 +4245,9 @@ static enum lttng_error_code set_relayd_for_snapshot(
                status = send_consumer_relayd_sockets(0, session->id,
                                snap_output->consumer, socket,
                                session->name, session->hostname,
-                               session->live_timer);
+                               session->live_timer,
+                               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();
@@ -4468,7 +4508,8 @@ enum lttng_error_code snapshot_record(struct ltt_session *session,
                }
        }
 
-       if (session_close_trace_chunk(session, session->current_trace_chunk)) {
+       if (session_close_trace_chunk(
+                           session, session->current_trace_chunk, NULL)) {
                /*
                 * Don't goto end; make sure the chunk is closed for the session
                 * to allow future snapshots.
@@ -4714,14 +4755,6 @@ int cmd_rotate_session(struct ltt_session *session,
                        &ongoing_rotation_chunk_id);
        assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK);
 
-       chunk_status = lttng_trace_chunk_set_close_command(
-                       chunk_being_archived,
-                       LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED);
-       if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
-               cmd_ret = LTTNG_ERR_FATAL;
-               goto error;
-       }
-
        if (session->kernel_session) {
                cmd_ret = kernel_rotate_session(session);
                if (cmd_ret != LTTNG_OK) {
@@ -4735,7 +4768,9 @@ int cmd_rotate_session(struct ltt_session *session,
                }
        }
 
-       ret = session_close_trace_chunk(session, chunk_being_archived);
+       ret = session_close_trace_chunk(session, chunk_being_archived,
+                       &((enum lttng_trace_chunk_command_type) {
+                                       LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED}));
        if (ret) {
                cmd_ret = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER;
                goto error;
This page took 0.02746 seconds and 4 git commands to generate.