Refactor: split relayd socket creation and sending to consumer
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 28 Apr 2022 18:22:27 +0000 (14:22 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 19 Aug 2022 15:55:46 +0000 (11:55 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: I10b829873788d340ff8ce902f7a86e80458e91d0

src/bin/lttng-sessiond/cmd.cpp
src/common/relayd/relayd.cpp

index 158fb0d75a22a155a6442892c2aadc6318252b91..0022333b3b34caf8d357bf478bbc24f60645c741 100644 (file)
@@ -761,9 +761,8 @@ error:
  * On success, the relayd_sock pointer is set to the created socket.
  * Else, it remains untouched and an LTTng error code is returned.
  */
-static enum lttng_error_code create_connect_relayd(struct lttng_uri *uri,
-               struct lttcomm_relayd_sock **relayd_sock,
-               struct consumer_output *consumer)
+static lttng_error_code create_connect_relayd(
+               struct lttng_uri *uri, struct lttcomm_relayd_sock **relayd_sock)
 {
        int ret;
        enum lttng_error_code status = LTTNG_OK;
@@ -792,8 +791,6 @@ static enum lttng_error_code create_connect_relayd(struct lttng_uri *uri,
 
        /* Create socket for control stream. */
        if (uri->stype == LTTNG_STREAM_CONTROL) {
-               uint64_t result_flags;
-
                DBG3("Creating relayd stream socket from URI");
 
                /* Check relayd version */
@@ -806,18 +803,6 @@ static enum lttng_error_code create_connect_relayd(struct lttng_uri *uri,
                        status = LTTNG_ERR_RELAYD_CONNECT_FAIL;
                        goto close_sock;
                }
-               consumer->relay_major_version = rsock->major;
-               consumer->relay_minor_version = rsock->minor;
-               ret = relayd_get_configuration(rsock, 0,
-                               &result_flags);
-               if (ret < 0) {
-                       ERR("Unable to get relayd configuration");
-                       status = LTTNG_ERR_RELAYD_CONNECT_FAIL;
-                       goto close_sock;
-               }
-               if (result_flags & LTTCOMM_RELAYD_CONFIGURATION_FLAG_CLEAR_ALLOWED) {
-                       consumer->relay_allows_clear = true;
-               }
        } else if (uri->stype == LTTNG_STREAM_DATA) {
                DBG3("Creating relayd data socket from URI");
        } else {
@@ -847,27 +832,21 @@ error:
  *
  * Returns LTTNG_OK on success or an LTTng error code on failure.
  */
-static enum lttng_error_code send_consumer_relayd_socket(
-               unsigned int session_id,
+static enum lttng_error_code send_consumer_relayd_socket(unsigned int session_id,
                struct lttng_uri *relayd_uri,
                struct consumer_output *consumer,
                struct consumer_socket *consumer_sock,
-               const char *session_name, const char *hostname,
-               const char *base_path, int session_live_timer,
+               const char *session_name,
+               const char *hostname,
+               const char *base_path,
+               int session_live_timer,
                const uint64_t *current_chunk_id,
                time_t session_creation_time,
-               bool session_name_contains_creation_time)
+               bool session_name_contains_creation_time,
+               struct lttcomm_relayd_sock& rsock)
 {
        int ret;
-       struct lttcomm_relayd_sock *rsock = NULL;
-       enum lttng_error_code status;
-
-       /* Connect to relayd and make version check if uri is the control. */
-       status = create_connect_relayd(relayd_uri, &rsock, consumer);
-       if (status != LTTNG_OK) {
-               goto relayd_comm_error;
-       }
-       LTTNG_ASSERT(rsock);
+       enum lttng_error_code status = LTTNG_OK;
 
        /* Set the network sequence index if not set. */
        if (consumer->net_seq_index == (uint64_t) -1ULL) {
@@ -882,14 +861,13 @@ 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, base_path,
-                       session_live_timer, current_chunk_id,
-                       session_creation_time, session_name_contains_creation_time);
+       ret = consumer_send_relayd_socket(consumer_sock, &rsock, consumer, relayd_uri->stype,
+                       session_id, session_name, hostname, base_path, session_live_timer,
+                       current_chunk_id, session_creation_time,
+                       session_name_contains_creation_time);
        if (ret < 0) {
                status = LTTNG_ERR_ENABLE_CONSUMER_FAIL;
-               goto close_sock;
+               goto error;
        }
 
        /* Flag that the corresponding socket was sent. */
@@ -899,12 +877,7 @@ static enum lttng_error_code send_consumer_relayd_socket(
                consumer_sock->data_sock_sent = 1;
        }
 
-       /*
-        * Close socket which was dup on the consumer side. The session daemon does
-        * NOT keep track of the relayd socket(s) once transfer to the consumer.
-        */
-
-close_sock:
+error:
        if (status != LTTNG_OK) {
                /*
                 * The consumer output for this session should not be used anymore
@@ -913,10 +886,7 @@ close_sock:
                 */
                consumer->enabled = 0;
        }
-       (void) relayd_close(rsock);
-       free(rsock);
 
-relayd_comm_error:
        return status;
 }
 
@@ -937,17 +907,42 @@ static enum lttng_error_code send_consumer_relayd_sockets(
                bool session_name_contains_creation_time)
 {
        enum lttng_error_code status = LTTNG_OK;
+       struct lttcomm_relayd_sock *control_sock = nullptr;
+       struct lttcomm_relayd_sock *data_sock = nullptr;
 
        LTTNG_ASSERT(consumer);
        LTTNG_ASSERT(sock);
 
        /* Sending control relayd socket. */
        if (!sock->control_sock_sent) {
-               status = send_consumer_relayd_socket(session_id,
-                               &consumer->dst.net.control, consumer, sock,
-                               session_name, hostname, base_path, session_live_timer,
-                               current_chunk_id, session_creation_time,
-                               session_name_contains_creation_time);
+               int ret;
+               uint64_t result_flags = 0;
+               /* Connect to relayd and make version check if uri is the control. */
+               status = create_connect_relayd(&consumer->dst.net.control, &control_sock);
+               if (status != LTTNG_OK) {
+                       goto error;
+               }
+               LTTNG_ASSERT(control_sock);
+
+               consumer->relay_major_version = control_sock->major;
+               consumer->relay_minor_version = control_sock->minor;
+
+               ret = relayd_get_configuration(control_sock, 0, &result_flags);
+               if (ret < 0) {
+                       ERR("Unable to get relayd configuration");
+                       status = LTTNG_ERR_RELAYD_CONNECT_FAIL;
+                       goto error;
+               }
+
+               if (result_flags & LTTCOMM_RELAYD_CONFIGURATION_FLAG_CLEAR_ALLOWED) {
+                       consumer->relay_allows_clear = true;
+               }
+
+               status = send_consumer_relayd_socket(session_id, &consumer->dst.net.control,
+                               consumer, sock, session_name, hostname, base_path,
+                               session_live_timer, current_chunk_id, session_creation_time,
+                               session_name_contains_creation_time, *control_sock);
+
                if (status != LTTNG_OK) {
                        goto error;
                }
@@ -955,17 +950,34 @@ static enum lttng_error_code send_consumer_relayd_sockets(
 
        /* Sending data relayd socket. */
        if (!sock->data_sock_sent) {
-               status = send_consumer_relayd_socket(session_id,
-                               &consumer->dst.net.data, consumer, sock,
-                               session_name, hostname, base_path, session_live_timer,
+               /* Connect to relayd and make version check if uri is the control. */
+               status = create_connect_relayd(&consumer->dst.net.data, &data_sock);
+               if (status != LTTNG_OK) {
+                       goto error;
+               }
+               LTTNG_ASSERT(data_sock);
+
+               status = send_consumer_relayd_socket(session_id, &consumer->dst.net.data, consumer,
+                               sock, session_name, hostname, base_path, session_live_timer,
                                current_chunk_id, session_creation_time,
-                               session_name_contains_creation_time);
+                               session_name_contains_creation_time, *data_sock);
+
                if (status != LTTNG_OK) {
                        goto error;
                }
        }
 
 error:
+       if (control_sock != nullptr) {
+               relayd_close(control_sock);
+               free(control_sock);
+       }
+
+       if (data_sock != nullptr) {
+               relayd_close(data_sock);
+               free(data_sock);
+       }
+
        return status;
 }
 
@@ -988,7 +1000,7 @@ int cmd_setup_relayd(struct ltt_session *session)
        usess = session->ust_session;
        ksess = session->kernel_session;
 
-       DBG("Setting relayd for session %s", session->name);
+       ERR("Setting relayd for session %s", session->name);
 
        rcu_read_lock();
        if (session->current_trace_chunk) {
@@ -1289,18 +1301,20 @@ end:
 static enum lttng_error_code kernel_domain_check_trace_format_requirements(
                const lttng::trace_format_descriptor& descriptor)
 {
-       enum lttng_error_code ret_code;
+       enum lttng_error_code ret_code = LTTNG_OK;
        switch (descriptor.type()) {
        case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_1:
                /* Supported by all kernel tracer. */
-               ret_code = LTTNG_OK;
                break;
        case LTTNG_TRACE_FORMAT_DESCRIPTOR_TYPE_CTF_2:
                if (!kernel_supports_ctf2()) {
                        ret_code = LTTNG_ERR_TRACE_FORMAT_UNSUPPORTED_KERNEL_TRACER;
                }
+               break;
+       default:
+               abort();
        }
-       return LTTNG_OK;
+       return ret_code;
 }
 
 static enum lttng_error_code cmd_enable_channel_internal(
index 12658dc6856655320203e84e8e542d97130876c5..a422d8b5a57e681769f1933048be984e96a25644 100644 (file)
@@ -1549,10 +1549,6 @@ int relayd_get_configuration(struct lttcomm_relayd_sock *sock,
 
        if (!relayd_supports_get_configuration(sock)) {
                DBG("Refusing to get relayd configuration (unsupported by relayd)");
-               if (query_flags) {
-                       ret = -1;
-                       goto end;
-               }
                *result_flags = 0;
                goto end;
        }
This page took 0.032017 seconds and 5 git commands to generate.