*/
uint64_t id;
struct lttcomm_sock *sock;
+ /* protocol version to use for this session */
+ uint32_t major;
+ uint32_t minor;
};
/*
*/
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;
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");
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;
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);
*/
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);
/* 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 {
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;
}
/* 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 */
/*
* 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;
* 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;
}
* 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;
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,