Implement the relayd live features
[lttng-tools.git] / src / common / relayd / relayd.c
index 2283865cf0d86be6c905baa287fd5809f17af8f2..a4c8a9261c29a9e58fc96e3023a68d8da8c44d68 100644 (file)
@@ -26,6 +26,7 @@
 #include <common/common.h>
 #include <common/defaults.h>
 #include <common/sessiond-comm/relayd.h>
+#include <common/index/lttng-index.h>
 
 #include "relayd.h"
 
@@ -115,6 +116,49 @@ error:
        return ret;
 }
 
+/*
+ * Starting at 2.4, RELAYD_CREATE_SESSION takes additional parameters to
+ * support the live reading capability.
+ */
+static int relayd_create_session_2_4(struct lttcomm_relayd_sock *rsock,
+               uint64_t *session_id, char *session_name, char *hostname,
+               int session_live_timer)
+{
+       int ret;
+       struct lttcomm_relayd_create_session_2_4 msg;
+
+       strncpy(msg.session_name, session_name, sizeof(msg.session_name));
+       strncpy(msg.hostname, hostname, sizeof(msg.hostname));
+       msg.live_timer = htobe32(session_live_timer);
+
+       /* Send command */
+       ret = send_command(rsock, RELAYD_CREATE_SESSION, &msg, sizeof(msg), 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
+/*
+ * RELAYD_CREATE_SESSION from 2.1 to 2.3.
+ */
+static int relayd_create_session_2_1(struct lttcomm_relayd_sock *rsock,
+               uint64_t *session_id)
+{
+       int ret;
+
+       /* Send command */
+       ret = send_command(rsock, RELAYD_CREATE_SESSION, NULL, 0, 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+error:
+       return ret;
+}
+
 /*
  * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and
  * set session_id of the relayd if we have a successful reply from the relayd.
@@ -122,7 +166,8 @@ error:
  * On success, return 0 else a negative value which is either an errno error or
  * a lttng error code from the relayd.
  */
-int relayd_create_session(struct lttcomm_relayd_sock *rsock, uint64_t *session_id)
+int relayd_create_session(struct lttcomm_relayd_sock *rsock, uint64_t *session_id,
+               char *session_name, char *hostname, int session_live_timer)
 {
        int ret;
        struct lttcomm_relayd_status_session reply;
@@ -132,8 +177,18 @@ int relayd_create_session(struct lttcomm_relayd_sock *rsock, uint64_t *session_i
 
        DBG("Relayd create session");
 
-       /* Send command */
-       ret = send_command(rsock, RELAYD_CREATE_SESSION, NULL, 0, 0);
+       switch(rsock->minor) {
+               case 1:
+               case 2:
+               case 3:
+                       ret = relayd_create_session_2_1(rsock, session_id);
+               case 4:
+               default:
+                       ret = relayd_create_session_2_4(rsock, session_id,
+                                       session_name, hostname,
+                                       session_live_timer);
+       }
+
        if (ret < 0) {
                goto error;
        }
@@ -671,3 +726,63 @@ int relayd_end_data_pending(struct lttcomm_relayd_sock *rsock, uint64_t id,
 error:
        return ret;
 }
+
+/*
+ * Send index to the relayd.
+ */
+int relayd_send_index(struct lttcomm_relayd_sock *rsock,
+               struct lttng_packet_index *index, uint64_t relay_stream_id,
+               uint64_t net_seq_num)
+{
+       int ret;
+       struct lttcomm_relayd_index msg;
+       struct lttcomm_relayd_generic_reply reply;
+
+       /* Code flow error. Safety net. */
+       assert(rsock);
+
+       if (rsock->minor < 4) {
+               DBG("Not sending indexes before protocol 2.4");
+               ret = 0;
+               goto error;
+       }
+
+       DBG("Relayd sending index for stream ID %" PRIu64, relay_stream_id);
+
+       msg.relay_stream_id = htobe64(relay_stream_id);
+       msg.net_seq_num = htobe64(net_seq_num);
+
+       /* The index is already in big endian. */
+       msg.packet_size = index->packet_size;
+       msg.content_size = index->content_size;
+       msg.timestamp_begin = index->timestamp_begin;
+       msg.timestamp_end = index->timestamp_end;
+       msg.events_discarded = index->events_discarded;
+       msg.stream_id = index->stream_id;
+
+       /* Send command */
+       ret = send_command(rsock, RELAYD_SEND_INDEX, &msg, sizeof(msg), 0);
+       if (ret < 0) {
+               goto error;
+       }
+
+       /* Receive response */
+       ret = recv_reply(rsock, (void *) &reply, sizeof(reply));
+       if (ret < 0) {
+               goto error;
+       }
+
+       reply.ret_code = be32toh(reply.ret_code);
+
+       /* Return session id or negative ret code. */
+       if (reply.ret_code != LTTNG_OK) {
+               ret = -1;
+               ERR("Relayd send index replied error %d", reply.ret_code);
+       } else {
+               /* Success */
+               ret = 0;
+       }
+
+error:
+       return ret;
+}
This page took 0.027726 seconds and 5 git commands to generate.