Adjust the relayd protocol on version check
authorJulien Desfossez <jdesfossez@efficios.com>
Wed, 27 Mar 2013 17:59:08 +0000 (13:59 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 28 Mar 2013 16:55:25 +0000 (12:55 -0400)
If the relayd and sessiond are compatible (same major number), we store
in the session the protocol version to use for the rest of the
communication (the lowest minor number).

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
src/bin/lttng-relayd/lttng-relayd.h
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/session.h
src/common/relayd/relayd.c
src/common/relayd/relayd.h

index edd32d6aba3770fb23cc4d720506eabde4062c5c..e6ca5ebbb2b7dcbfb9f9bdb9a4d302d70c2e3475 100644 (file)
@@ -47,6 +47,9 @@ struct relay_session {
         */
        uint64_t id;
        struct lttcomm_sock *sock;
+       /* protocol version to use for this session */
+       uint32_t major;
+       uint32_t minor;
 };
 
 /*
index 082eb7975efd0adb1c41bfbfee65c621dd34abeb..995714faf40b6f6d34b6ed31319834baf99e2b6d 100644 (file)
@@ -1240,7 +1240,7 @@ end:
  */
 static
 int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
-               struct relay_command *cmd)
+               struct relay_command *cmd, struct lttng_ht *streams_ht)
 {
        int ret;
        struct lttcomm_relayd_version reply, msg;
@@ -1262,13 +1262,6 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
-       /*
-        * For now, we just ignore the received version but after 2.1 stable
-        * release, a check must be done to see if we either adapt to the other
-        * side version (which MUST be lower than us) or keep the latest data
-        * structure considering that the other side will adapt.
-        */
-
        ret = sscanf(VERSION, "%10u.%10u", &reply.major, &reply.minor);
        if (ret < 2) {
                ERR("Error in scanning version");
@@ -1282,8 +1275,25 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
        if (ret < 0) {
                ERR("Relay sending version");
        }
-       DBG("Version check done (%u.%u)", be32toh(reply.major),
-                       be32toh(reply.minor));
+
+       /* Major versions must be the same */
+       if (reply.major != be32toh(msg.major)) {
+               DBG("Incompatible major versions, deleting session");
+               relay_delete_session(cmd, streams_ht);
+               ret = 0;
+               goto end;
+       }
+
+       cmd->session->major = reply.major;
+       /* We adapt to the lowest compatible version */
+       if (reply.minor <= be32toh(msg.minor)) {
+               cmd->session->minor = reply.minor;
+       } else {
+               cmd->session->minor = be32toh(msg.minor);
+       }
+
+       DBG("Version check done using protocol %u.%u", cmd->session->major,
+                       cmd->session->minor);
 
 end:
        return ret;
@@ -1593,7 +1603,7 @@ int relay_process_control(struct lttcomm_relayd_hdr *recv_hdr,
                ret = relay_recv_metadata(recv_hdr, cmd, streams_ht);
                break;
        case RELAYD_VERSION:
-               ret = relay_send_version(recv_hdr, cmd);
+               ret = relay_send_version(recv_hdr, cmd, streams_ht);
                break;
        case RELAYD_CLOSE_STREAM:
                ret = relay_close_stream(recv_hdr, cmd, streams_ht);
index 38ce83c7eefd308cc8b6e2f1b50abddbc5bedf9c..ca7e7dac17cb4e0e52e275e043b51c749d552096 100644 (file)
@@ -480,10 +480,12 @@ error:
  */
 static int create_connect_relayd(struct consumer_output *output,
                const char *session_name, struct lttng_uri *uri,
-               struct lttcomm_sock **relayd_sock)
+               struct lttcomm_sock **relayd_sock,
+               struct ltt_session *session)
 {
        int ret;
        struct lttcomm_sock *sock;
+       uint32_t minor;
 
        /* Create socket object from URI */
        sock = lttcomm_alloc_sock_from_uri(uri);
@@ -518,11 +520,13 @@ static int create_connect_relayd(struct consumer_output *output,
 
                /* Check relayd version */
                ret = relayd_version_check(sock, RELAYD_VERSION_COMM_MAJOR,
-                               RELAYD_VERSION_COMM_MINOR);
+                               RELAYD_VERSION_COMM_MINOR, &minor);
                if (ret < 0) {
                        ret = LTTNG_ERR_RELAYD_VERSION_FAIL;
                        goto close_sock;
                }
+               session->major = RELAYD_VERSION_COMM_MAJOR;
+               session->minor = minor;
        } else if (uri->stype == LTTNG_STREAM_DATA) {
                DBG3("Creating relayd data socket from URI");
        } else {
@@ -559,7 +563,8 @@ static int send_consumer_relayd_socket(int domain, struct ltt_session *session,
        struct lttcomm_sock *sock = NULL;
 
        /* Connect to relayd and make version check if uri is the control. */
-       ret = create_connect_relayd(consumer, session->name, relayd_uri, &sock);
+       ret = create_connect_relayd(consumer, session->name, relayd_uri,
+                       &sock, session);
        if (ret != LTTNG_OK) {
                goto close_sock;
        }
index fd23ab05ed90bb422779446d7dd3961bc862f1da..a56473783fb7d5f8f93ef11f50a40f628eaf35e5 100644 (file)
@@ -86,6 +86,9 @@ struct ltt_session {
 
        /* Did a start command occured before the kern/ust session creation? */
        unsigned int started;
+       /* Procotol version to use with the relayd */
+       uint32_t major;
+       uint32_t minor;
 };
 
 /* Prototypes */
index 9e10c83e02f7ec583bff72cd5b6d70b42870dca1..da54939f9a28153e4ae343d281ec1352e07b8ef9 100644 (file)
@@ -212,11 +212,13 @@ error:
 
 /*
  * Check version numbers on the relayd.
+ * If major versions are compatible, we assign minor_to_use to the
+ * minor version of the procotol we are going to use for this session.
  *
  * Return 0 if compatible else negative value.
  */
 int relayd_version_check(struct lttcomm_sock *sock, uint32_t major,
-               uint32_t minor)
+               uint32_t minor, uint32_t *minor_to_use)
 {
        int ret;
        struct lttcomm_relayd_version msg;
@@ -251,15 +253,12 @@ int relayd_version_check(struct lttcomm_sock *sock, uint32_t major,
         * communication is not possible. Only major version equal can talk to each
         * other. If the minor version differs, the lowest version is used by both
         * sides.
-        *
-        * For now, before 2.1.0 stable release, we don't have to check the minor
-        * because this new mechanism with the relayd will only be available with
-        * 2.1 and NOT 2.0.x.
         */
-       if (msg.major == major) {
-               /* Compatible */
-               ret = 0;
-               DBG2("Relayd version is compatible");
+       if (msg.major != major) {
+               /* Not compatible */
+               ret = -1;
+               DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)",
+                               msg.major, major);
                goto error;
        }
 
@@ -270,11 +269,16 @@ int relayd_version_check(struct lttcomm_sock *sock, uint32_t major,
         * version is higher, it will adapt to our version so we can continue to
         * use the latest relayd communication data structure.
         */
+       if (minor <= msg.minor) {
+               *minor_to_use = minor;
+       } else {
+               *minor_to_use = msg.minor;
+       }
 
-       /* Version number not compatible */
-       DBG2("Relayd version is NOT compatible. Relayd version %u != %u (us)",
-                       msg.major, major);
-       ret = -1;
+       /* Version number compatible */
+       DBG2("Relayd version is compatible, using protocol version %u.%u",
+                       major, *minor_to_use);
+       ret = 0;
 
 error:
        return ret;
index fd0acfb3583d1c4b10b80f0e45649ca00271a7b3..22bfce82901d3956fa53c55c8a228fbc09d8ff1c 100644 (file)
@@ -31,7 +31,7 @@ int relayd_add_stream(struct lttcomm_sock *sock, const char *channel_name,
 int relayd_send_close_stream(struct lttcomm_sock *sock, uint64_t stream_id,
                uint64_t last_net_seq_num);
 int relayd_version_check(struct lttcomm_sock *sock, uint32_t major,
-               uint32_t minor);
+               uint32_t minor, uint32_t *minor_to_use);
 int relayd_start_data(struct lttcomm_sock *sock);
 int relayd_send_metadata(struct lttcomm_sock *sock, size_t len);
 int relayd_send_data_hdr(struct lttcomm_sock *sock,
This page took 0.03188 seconds and 5 git commands to generate.