From: Julien Desfossez Date: Wed, 27 Mar 2013 17:59:08 +0000 (-0400) Subject: Adjust the relayd protocol on version check X-Git-Tag: v2.2.0-rc1~7 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=d4519fa365bd3a9ce4ea1720805a29a000fa042c Adjust the relayd protocol on version check 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 --- diff --git a/src/bin/lttng-relayd/lttng-relayd.h b/src/bin/lttng-relayd/lttng-relayd.h index edd32d6ab..e6ca5ebbb 100644 --- a/src/bin/lttng-relayd/lttng-relayd.h +++ b/src/bin/lttng-relayd/lttng-relayd.h @@ -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; }; /* diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 082eb7975..995714faf 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -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); diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 38ce83c7e..ca7e7dac1 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index fd23ab05e..a56473783 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -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 */ diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 9e10c83e0..da54939f9 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -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; diff --git a/src/common/relayd/relayd.h b/src/common/relayd/relayd.h index fd0acfb35..22bfce829 100644 --- a/src/common/relayd/relayd.h +++ b/src/common/relayd/relayd.h @@ -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,