Fix: streaming and snapshot backward compat for relayd < 2.11
[lttng-tools.git] / src / common / relayd / relayd.c
index 51de7b82f4a2216f780b15e13c2c9ec899a1b73e..8e6b71173052436103275898c4fe5ec02e02c2f5 100644 (file)
 
 #include "relayd.h"
 
+static
+bool relayd_supports_chunks(const struct lttcomm_relayd_sock *sock)
+{
+       if (sock->major > 2) {
+               return true;
+       } else if (sock->major == 2 && sock->minor >= 11) {
+               return true;
+       }
+       return false;
+}
+
 /*
  * Send command. Fill up the header and append the data.
  */
@@ -132,7 +143,7 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
                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)
+               time_t creation_time, bool session_name_contains_creation_time)
 {
        int ret;
        struct lttcomm_relayd_create_session_2_11 *msg = NULL;
@@ -142,7 +153,10 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
        size_t msg_length;
        char *dst;
 
-       /* The two names are sent with a '\0' delimiter between them. */
+       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 = base_path ? strlen(base_path) + 1 : 0;
@@ -185,7 +199,7 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
 
        lttng_uuid_copy(msg->sessiond_uuid, sessiond_uuid);
        msg->session_id = htobe64(sessiond_session_id);
-
+       msg->session_name_contains_creation_time = session_name_contains_creation_time;
        if (current_chunk_id) {
                LTTNG_OPTIONAL_SET(&msg->current_chunk_id,
                                htobe64(*current_chunk_id));
@@ -266,7 +280,7 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                unsigned int snapshot, uint64_t sessiond_session_id,
                const lttng_uuid sessiond_uuid,
                const uint64_t *current_chunk_id,
-               time_t creation_time)
+               time_t creation_time, bool session_name_contains_creation_time)
 {
        int ret;
        struct lttcomm_relayd_status_session reply;
@@ -288,7 +302,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock,
                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);
+                               current_chunk_id, creation_time,
+                               session_name_contains_creation_time);
        }
 
        if (ret < 0) {
@@ -438,6 +453,10 @@ error:
 /*
  * Add stream on the relayd and assign stream handle to the stream_id argument.
  *
+ * Chunks are not supported by relayd prior to 2.11, but are used to
+ * internally between session daemon and consumer daemon to keep track
+ * of the channel and stream output path.
+ *
  * On success return 0 else return ret_code negative value.
  */
 int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name,
@@ -452,25 +471,23 @@ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_nam
        assert(rsock);
        assert(channel_name);
        assert(pathname);
+       assert(trace_chunk);
 
        DBG("Relayd adding stream for channel name %s", channel_name);
 
        /* Compat with relayd 2.1 */
        if (rsock->minor == 1) {
                /* For 2.1 */
-               assert(!trace_chunk);
                ret = relayd_add_stream_2_1(rsock, channel_name, pathname);
        
        } else if (rsock->minor > 1 && rsock->minor < 11) {
                /* From 2.2 to 2.10 */
-               assert(!trace_chunk);
                ret = relayd_add_stream_2_2(rsock, channel_name, pathname,
                                tracefile_size, tracefile_count);
        } else {
                enum lttng_trace_chunk_status chunk_status;
                uint64_t chunk_id;
 
-               assert(trace_chunk);
                chunk_status = lttng_trace_chunk_get_id(trace_chunk,
                                &chunk_id);
                assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK);
@@ -1153,6 +1170,11 @@ int relayd_rotate_streams(struct lttcomm_relayd_sock *sock,
        char new_chunk_id_buf[MAX_INT_DEC_LEN(*new_chunk_id)] = {};
        const char *new_chunk_id_str;
 
+       if (!relayd_supports_chunks(sock)) {
+               DBG("Refusing to rotate remote streams: relayd does not support chunks");
+               return 0;
+       }
+
        lttng_dynamic_buffer_init(&payload);
 
        /* Code flow error. Safety net. */
@@ -1245,6 +1267,11 @@ int relayd_create_trace_chunk(struct lttcomm_relayd_sock *sock,
 
        lttng_dynamic_buffer_init(&payload);
 
+       if (!relayd_supports_chunks(sock)) {
+               DBG("Refusing to create remote trace chunk: relayd does not support chunks");
+               goto end;
+       }
+
        status = lttng_trace_chunk_get_id(chunk, &chunk_id);
        if (status != LTTNG_TRACE_CHUNK_STATUS_OK) {
                ret = -1;
@@ -1325,6 +1352,11 @@ int relayd_close_trace_chunk(struct lttcomm_relayd_sock *sock,
        time_t close_timestamp;
        LTTNG_OPTIONAL(enum lttng_trace_chunk_command_type) close_command = {};
 
+       if (!relayd_supports_chunks(sock)) {
+               DBG("Refusing to close remote trace chunk: relayd does not support chunks");
+               goto end;
+       }
+
        status = lttng_trace_chunk_get_id(chunk, &chunk_id);
        if (status != LTTNG_TRACE_CHUNK_STATUS_OK) {
                ERR("Failed to get trace chunk id");
@@ -1396,6 +1428,11 @@ int relayd_trace_chunk_exists(struct lttcomm_relayd_sock *sock,
        struct lttcomm_relayd_trace_chunk_exists msg = {};
        struct lttcomm_relayd_trace_chunk_exists_reply reply = {};
 
+       if (!relayd_supports_chunks(sock)) {
+               DBG("Refusing to check for trace chunk existence: relayd does not support chunks");
+               goto end;
+       }
+
        msg = (typeof(msg)){
                        .chunk_id = htobe64(chunk_id),
        };
This page took 0.042067 seconds and 5 git commands to generate.