Propagate trace format to relayd on session creation
[lttng-tools.git] / src / common / relayd / relayd.cpp
index 20a8aecba51a5dd49df149bd0e47c740201ccef9..1bebc4c6a4eae8c7316697720cbb4d5de1a69b2b 100644 (file)
@@ -21,6 +21,7 @@
 #include <common/sessiond-comm/relayd.hpp>
 #include <common/string-utils/format.hpp>
 #include <common/trace-chunk.hpp>
+#include <lttng/trace-format-descriptor-internal.hpp>
 
 #include "relayd.hpp"
 
@@ -144,6 +145,116 @@ error:
        return ret;
 }
 
+/*
+ * Starting from 2.15, the trace format for the session is sent to lttng-relayd
+ * on creation.
+ * */
+static int relayd_create_session_2_15(struct lttcomm_relayd_sock *rsock,
+               const char *session_name,
+               const char *hostname,
+               const char *base_path,
+               int session_live_timer,
+               unsigned int snapshot,
+               uint64_t sessiond_session_id,
+               const lttng_uuid& sessiond_uuid,
+               const uint64_t *current_chunk_id,
+               time_t creation_time,
+               bool session_name_contains_creation_time,
+               lttcomm_relayd_create_session_reply_2_15 *reply,
+               char *output_path,
+               const lttng::trace_format_descriptor& trace_format)
+{
+       int ret;
+       struct lttcomm_relayd_create_session_2_15 *msg = NULL;
+       size_t session_name_len;
+       size_t hostname_len;
+       size_t base_path_len;
+       size_t msg_length;
+       char *dst;
+
+       if (!base_path) {
+               base_path = "";
+       }
+       /* The three names are sent with a '\0' delimiter between them. */
+       session_name_len = strlen(session_name) + 1;
+       hostname_len = strlen(hostname) + 1;
+       base_path_len = strlen(base_path) + 1;
+
+       msg_length = sizeof(*msg) + session_name_len + hostname_len + base_path_len;
+       msg = zmalloc<lttcomm_relayd_create_session_2_15>(msg_length);
+       if (!msg) {
+               PERROR("zmalloc create_session_2_11 command message");
+               ret = -1;
+               goto error;
+       }
+
+       LTTNG_ASSERT(session_name_len <= UINT32_MAX);
+       msg->session_name_len = htobe32(session_name_len);
+
+       LTTNG_ASSERT(hostname_len <= UINT32_MAX);
+       msg->hostname_len = htobe32(hostname_len);
+
+       LTTNG_ASSERT(base_path_len <= UINT32_MAX);
+       msg->base_path_len = htobe32(base_path_len);
+
+       dst = msg->names;
+       if (lttng_strncpy(dst, session_name, session_name_len)) {
+               ret = -1;
+               goto error;
+       }
+       dst += session_name_len;
+       if (lttng_strncpy(dst, hostname, hostname_len)) {
+               ret = -1;
+               goto error;
+       }
+       dst += hostname_len;
+       if (lttng_strncpy(dst, base_path, base_path_len)) {
+               ret = -1;
+               goto error;
+       }
+
+       msg->live_timer = htobe32(session_live_timer);
+       msg->snapshot = !!snapshot;
+
+       std::copy(sessiond_uuid.begin(), sessiond_uuid.end(), msg->sessiond_uuid);
+       msg->session_id = htobe64(sessiond_session_id);
+       msg->session_name_contains_creation_time = session_name_contains_creation_time;
+       msg->trace_format = (uint8_t) trace_format.relayd_type();
+       if (current_chunk_id) {
+               LTTNG_OPTIONAL_SET(&msg->current_chunk_id, 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) {
+               goto error;
+       }
+       /* Receive response */
+       ret = recv_reply(rsock, reply, sizeof(*reply));
+       if (ret < 0) {
+               goto error;
+       }
+       reply->generic.session_id = be64toh(reply->generic.session_id);
+       reply->generic.ret_code = be32toh(reply->generic.ret_code);
+       reply->output_path_length = be32toh(reply->output_path_length);
+       if (reply->output_path_length >= LTTNG_PATH_MAX) {
+               ERR("Invalid session output path length in reply (%" PRIu32
+                   " bytes) exceeds maximal allowed length (%d bytes)",
+                               reply->output_path_length, LTTNG_PATH_MAX);
+               ret = -1;
+               goto error;
+       }
+       ret = recv_reply(rsock, output_path, reply->output_path_length);
+       if (ret < 0) {
+               goto error;
+       }
+error:
+       free(msg);
+       return ret;
+}
+
 /*
  * Starting from 2.11, RELAYD_CREATE_SESSION payload (session_name,
  * hostname, and base_path) have no length restriction on the sender side.
@@ -323,16 +434,21 @@ error:
  */
 int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                uint64_t *relayd_session_id,
-               const char *session_name, const char *hostname,
-               const char *base_path, int session_live_timer,
-               unsigned int snapshot, uint64_t sessiond_session_id,
+               const char *session_name,
+               const char *hostname,
+               const char *base_path,
+               int session_live_timer,
+               unsigned int snapshot,
+               uint64_t sessiond_session_id,
                const lttng_uuid& sessiond_uuid,
                const uint64_t *current_chunk_id,
-               time_t creation_time, bool session_name_contains_creation_time,
-               char *output_path)
+               time_t creation_time,
+               bool session_name_contains_creation_time,
+               char *output_path,
+               lttng::trace_format_descriptor& trace_format)
 {
        int ret;
-       struct lttcomm_relayd_create_session_reply_2_11 reply = {};
+       lttcomm_relayd_create_session_reply_2_15 reply = {};
 
        LTTNG_ASSERT(rsock);
        LTTNG_ASSERT(relayd_session_id);
@@ -344,17 +460,20 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                ret = relayd_create_session_2_1(rsock, &reply.generic);
        } else if (rsock->minor >= 4 && rsock->minor < 11) {
                /* From 2.4 to 2.10 */
-               ret = relayd_create_session_2_4(rsock, session_name,
-                               hostname, session_live_timer, snapshot,
-                               &reply.generic);
+               ret = relayd_create_session_2_4(rsock, session_name, hostname, session_live_timer,
+                               snapshot, &reply.generic);
+       } else if (rsock->minor < 15) {
+               /* From 2.11 to 2.14 */
+               ret = relayd_create_session_2_11(rsock, session_name, hostname, base_path,
+                               session_live_timer, snapshot, sessiond_session_id, sessiond_uuid,
+                               current_chunk_id, creation_time,
+                               session_name_contains_creation_time, &reply, output_path);
        } else {
-               /* From 2.11 to ... */
-               ret = relayd_create_session_2_11(rsock, session_name,
-                               hostname, base_path, session_live_timer, snapshot,
-                               sessiond_session_id, sessiond_uuid,
+               ret = relayd_create_session_2_15(rsock, session_name, hostname, base_path,
+                               session_live_timer, snapshot, sessiond_session_id, sessiond_uuid,
                                current_chunk_id, creation_time,
-                               session_name_contains_creation_time,
-                               &reply, output_path);
+                               session_name_contains_creation_time, &reply, output_path,
+                               trace_format);
        }
 
        if (ret < 0) {
This page took 0.030884 seconds and 5 git commands to generate.