From: Julien Desfossez Date: Mon, 7 Aug 2017 20:39:03 +0000 (-0400) Subject: Send domain with streams to the relay X-Git-Url: http://git.efficios.com/?p=deliverable%2Flttng-tools.git;a=commitdiff_plain;h=ccb5d350384349e7be8917b1b524789d8a44403c Send domain with streams to the relay For session rotation, the relay needs to know if the session contains kernel and/or ust channels, so we now send the domain with each stream and store it in the relay_session. Signed-off-by: Julien Desfossez --- diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index c7dd37e1a..45256c8e3 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -13,6 +13,7 @@ lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c cmd.h \ cmd-2-1.c cmd-2-1.h \ cmd-2-2.c cmd-2-2.h \ cmd-2-4.c cmd-2-4.h \ + cmd-2-11.c cmd-2-11.h \ health-relayd.c health-relayd.h \ lttng-viewer-abi.h testpoint.h \ viewer-stream.h viewer-stream.c \ diff --git a/src/bin/lttng-relayd/cmd-2-11.c b/src/bin/lttng-relayd/cmd-2-11.c new file mode 100644 index 000000000..17371d858 --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-11.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2013 - Julien Desfossez + * David Goulet + * 2015 - Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define _LGPL_SOURCE +#include + +#include +#include + +#include +#include +#include + +#include "cmd-generic.h" +#include "cmd-2-1.h" +#include "utils.h" + +/* + * cmd_recv_stream_2_11 allocates path_name and channel_name. + */ +int cmd_recv_stream_2_11(struct relay_connection *conn, + char **ret_path_name, char **ret_channel_name, + uint64_t *tracefile_size, uint64_t *tracefile_count, + struct relay_session *session) +{ + int ret; + struct lttcomm_relayd_add_stream_2_11 stream_info; + char *path_name = NULL; + char *channel_name = NULL; + size_t len; + + ret = cmd_recv(conn->sock, &stream_info, sizeof(stream_info)); + if (ret < 0) { + ERR("Unable to recv stream version 2.11"); + goto error; + } + + len = lttng_strnlen(stream_info.pathname, sizeof(stream_info.pathname)); + /* Ensure that NULL-terminated and fits in local filename length. */ + if (len == sizeof(stream_info.pathname) || len >= LTTNG_NAME_MAX) { + ret = -ENAMETOOLONG; + ERR("Path name too long"); + goto error; + } + path_name = create_output_path(stream_info.pathname); + if (!path_name) { + PERROR("Path name allocation"); + ret = -ENOMEM; + goto error; + } + len = lttng_strnlen(stream_info.channel_name, sizeof(stream_info.channel_name)); + if (len == sizeof(stream_info.channel_name) || len >= DEFAULT_STREAM_NAME_LEN) { + ret = -ENAMETOOLONG; + ERR("Channel name too long"); + goto error; + } + channel_name = strdup(stream_info.channel_name); + if (!channel_name) { + ret = -errno; + PERROR("Channel name allocation"); + goto error; + } + + *tracefile_size = be64toh(stream_info.tracefile_size); + *tracefile_count = be64toh(stream_info.tracefile_count); + *ret_path_name = path_name; + *ret_channel_name = channel_name; + + switch (be32toh(stream_info.domain)) { + case LTTNG_DOMAIN_KERNEL: + session->kernel_session = 1; + break; + case LTTNG_DOMAIN_UST: + session->ust_session = 1; + break; + default: + ERR("Unknown domain in add_stream"); + ret = -1; + goto error; + } + return 0; +error: + free(path_name); + free(channel_name); + return ret; +} diff --git a/src/bin/lttng-relayd/cmd-2-11.h b/src/bin/lttng-relayd/cmd-2-11.h new file mode 100644 index 000000000..a3163bcfc --- /dev/null +++ b/src/bin/lttng-relayd/cmd-2-11.h @@ -0,0 +1,30 @@ +#ifndef RELAYD_CMD_2_11_H +#define RELAYD_CMD_2_11_H + +/* + * Copyright (C) 2013 - Julien Desfossez + * David Goulet + * 2015 - Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "lttng-relayd.h" + +int cmd_recv_stream_2_11(struct relay_connection *conn, + char **path_name, char **channel_name, + uint64_t *tracefile_size, uint64_t *tracefile_count, + struct relay_session *session); + +#endif /* RELAYD_CMD_2_11_H */ diff --git a/src/bin/lttng-relayd/cmd.h b/src/bin/lttng-relayd/cmd.h index 88db09aed..f0289a1ab 100644 --- a/src/bin/lttng-relayd/cmd.h +++ b/src/bin/lttng-relayd/cmd.h @@ -24,5 +24,6 @@ #include "cmd-2-1.h" #include "cmd-2-2.h" #include "cmd-2-4.h" +#include "cmd-2-11.h" #endif /* RELAYD_CMD_H */ diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 6a536d36d..c1b044f57 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1189,10 +1189,23 @@ static int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr, &channel_name); break; case 2: /* LTTng sessiond 2.2. Allocates path_name and channel_name. */ - default: + case 3: /* LTTng sessiond 2.3. Allocates path_name and channel_name. */ + case 4: /* LTTng sessiond 2.4. Allocates path_name and channel_name. */ + case 5: /* LTTng sessiond 2.5. Allocates path_name and channel_name. */ + case 6: /* LTTng sessiond 2.6. Allocates path_name and channel_name. */ + case 7: /* LTTng sessiond 2.7. Allocates path_name and channel_name. */ + case 8: /* LTTng sessiond 2.8. Allocates path_name and channel_name. */ + case 9: /* LTTng sessiond 2.9. Allocates path_name and channel_name. */ + case 10: /* LTTng sessiond 2.10. Allocates path_name and channel_name. */ ret = cmd_recv_stream_2_2(conn, &path_name, &channel_name, &tracefile_size, &tracefile_count); break; + case 11: /* LTTng sessiond 2.11. Allocates path_name and channel_name. */ + default: + ret = cmd_recv_stream_2_11(conn, &path_name, + &channel_name, &tracefile_size, &tracefile_count, + session); + break; } if (ret < 0) { goto send_reply; diff --git a/src/bin/lttng-relayd/session.h b/src/bin/lttng-relayd/session.h index 2410fd483..606574ea2 100644 --- a/src/bin/lttng-relayd/session.h +++ b/src/bin/lttng-relayd/session.h @@ -106,6 +106,11 @@ struct relay_session { */ struct cds_list_head viewer_session_node; struct rcu_head rcu_node; /* For call_rcu teardown. */ + /* + * Domains in this session. + */ + unsigned int ust_session:1; + unsigned int kernel_session:1; }; struct relay_session *session_create(const char *session_name, diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index d22f947e1..f187584f3 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -789,7 +789,7 @@ error: * Returns 0 on success, < 0 on error */ int consumer_send_relayd_stream(struct lttng_consumer_stream *stream, - char *path) + char *path, enum lttng_domain_type domain) { int ret = 0; struct consumer_relayd_sock_pair *relayd; @@ -806,7 +806,8 @@ int consumer_send_relayd_stream(struct lttng_consumer_stream *stream, pthread_mutex_lock(&relayd->ctrl_sock_mutex); ret = relayd_add_stream(&relayd->control_sock, stream->name, path, &stream->relayd_stream_id, - stream->chan->tracefile_size, stream->chan->tracefile_count); + stream->chan->tracefile_size, stream->chan->tracefile_count, + domain); pthread_mutex_unlock(&relayd->ctrl_sock_mutex); if (ret < 0) { goto end; diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index bf79bcb97..92552504e 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -750,7 +750,8 @@ void consumer_del_channel(struct lttng_consumer_channel *channel); /* lttng-relayd consumer command */ struct consumer_relayd_sock_pair *consumer_find_relayd(uint64_t key); -int consumer_send_relayd_stream(struct lttng_consumer_stream *stream, char *path); +int consumer_send_relayd_stream(struct lttng_consumer_stream *stream, char *path, + enum lttng_domain_type domain); int consumer_send_relayd_streams_sent(uint64_t net_seq_idx); void close_relayd_stream(struct lttng_consumer_stream *stream); struct lttng_consumer_channel *consumer_find_channel(uint64_t key); diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index ffcdde035..bdca67087 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -170,7 +170,8 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path, stream->net_seq_idx = relayd_id; channel->relayd_id = relayd_id; if (relayd_id != (uint64_t) -1ULL) { - ret = consumer_send_relayd_stream(stream, path); + ret = consumer_send_relayd_stream(stream, path, + LTTNG_DOMAIN_KERNEL); if (ret < 0) { ERR("sending stream to relayd"); goto end_unlock; @@ -367,7 +368,8 @@ int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path, } if (use_relayd) { - ret = consumer_send_relayd_stream(metadata_stream, path); + ret = consumer_send_relayd_stream(metadata_stream, path, + LTTNG_DOMAIN_KERNEL); if (ret < 0) { goto error; } @@ -723,7 +725,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, /* Send stream to relayd if the stream has an ID. */ if (new_stream->net_seq_idx != (uint64_t) -1ULL) { ret = consumer_send_relayd_stream(new_stream, - new_stream->chan->pathname); + new_stream->chan->pathname, + LTTNG_DOMAIN_KERNEL); if (ret < 0) { consumer_stream_free(new_stream); goto end_nosignal; diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 17edd6acf..dad845d5c 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -237,11 +237,13 @@ error: */ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name, const char *pathname, uint64_t *stream_id, - uint64_t tracefile_size, uint64_t tracefile_count) + uint64_t tracefile_size, uint64_t tracefile_count, + enum lttng_domain_type domain) { int ret; struct lttcomm_relayd_add_stream msg; struct lttcomm_relayd_add_stream_2_2 msg_2_2; + struct lttcomm_relayd_add_stream_2_11 msg_2_11; struct lttcomm_relayd_status_stream reply; /* Code flow error. Safety net. */ @@ -252,7 +254,8 @@ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_nam DBG("Relayd adding stream for channel name %s", channel_name); /* Compat with relayd 2.1 */ - if (rsock->minor == 1) { + switch (rsock->minor) { + case 1: memset(&msg, 0, sizeof(msg)); if (lttng_strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name))) { @@ -270,7 +273,16 @@ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_nam if (ret < 0) { goto error; } - } else { + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: memset(&msg_2_2, 0, sizeof(msg_2_2)); /* Compat with relayd 2.2+ */ if (lttng_strncpy(msg_2_2.channel_name, channel_name, @@ -291,6 +303,31 @@ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_nam if (ret < 0) { goto error; } + break; + case 11: + default: + memset(&msg_2_11, 0, sizeof(msg_2_11)); + /* Compat with relayd 2.11+ */ + if (lttng_strncpy(msg_2_11.channel_name, channel_name, + sizeof(msg_2_11.channel_name))) { + ret = -1; + goto error; + } + if (lttng_strncpy(msg_2_11.pathname, pathname, + sizeof(msg_2_11.pathname))) { + ret = -1; + goto error; + } + msg_2_11.tracefile_size = htobe64(tracefile_size); + msg_2_11.tracefile_count = htobe64(tracefile_count); + msg_2_11.domain = htobe32(domain); + + /* Send command */ + ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg_2_11, sizeof(msg_2_11), 0); + if (ret < 0) { + goto error; + } + break; } /* Waiting for reply */ diff --git a/src/common/relayd/relayd.h b/src/common/relayd/relayd.h index ba2faa46c..4c5c2daf5 100644 --- a/src/common/relayd/relayd.h +++ b/src/common/relayd/relayd.h @@ -30,7 +30,8 @@ int relayd_create_session(struct lttcomm_relayd_sock *sock, uint64_t *session_id unsigned int snapshot); int relayd_add_stream(struct lttcomm_relayd_sock *sock, const char *channel_name, const char *pathname, uint64_t *stream_id, - uint64_t tracefile_size, uint64_t tracefile_count); + uint64_t tracefile_size, uint64_t tracefile_count, + enum lttng_domain_type domain); int relayd_streams_sent(struct lttcomm_relayd_sock *rsock); int relayd_send_close_stream(struct lttcomm_relayd_sock *sock, uint64_t stream_id, uint64_t last_net_seq_num); diff --git a/src/common/sessiond-comm/relayd.h b/src/common/sessiond-comm/relayd.h index 2f0a2c6cd..bc754ee5c 100644 --- a/src/common/sessiond-comm/relayd.h +++ b/src/common/sessiond-comm/relayd.h @@ -79,6 +79,18 @@ struct lttcomm_relayd_add_stream_2_2 { uint64_t tracefile_count; } LTTNG_PACKED; +/* + * Used to add a stream on the relay daemon. + * Protocol version 2.11 + */ +struct lttcomm_relayd_add_stream_2_11 { + char channel_name[DEFAULT_STREAM_NAME_LEN]; + char pathname[LTTNG_PATH_MAX]; + uint32_t domain; /* enum lttng_domain_type */ + uint64_t tracefile_size; + uint64_t tracefile_count; +} LTTNG_PACKED; + /* * Answer from an add stream command. */ diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index d467de4fb..3a67c7d5b 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -567,7 +567,8 @@ static int send_sessiond_channel(int sock, health_code_update(); /* Try to send the stream to the relayd if one is available. */ - ret = consumer_send_relayd_stream(stream, stream->chan->pathname); + ret = consumer_send_relayd_stream(stream, stream->chan->pathname, + LTTNG_DOMAIN_UST); if (ret < 0) { /* * Flag that the relayd was the problem here probably due to a @@ -905,7 +906,7 @@ static int setup_metadata(struct lttng_consumer_local_data *ctx, uint64_t key) /* Send metadata stream to relayd if needed. */ if (metadata->metadata_stream->net_seq_idx != (uint64_t) -1ULL) { ret = consumer_send_relayd_stream(metadata->metadata_stream, - metadata->pathname); + metadata->pathname, LTTNG_DOMAIN_UST); if (ret < 0) { ret = LTTCOMM_CONSUMERD_ERROR_METADATA; goto error; @@ -1004,7 +1005,8 @@ static int snapshot_metadata(uint64_t key, char *path, uint64_t relayd_id, if (relayd_id != (uint64_t) -1ULL) { metadata_stream->net_seq_idx = relayd_id; - ret = consumer_send_relayd_stream(metadata_stream, path); + ret = consumer_send_relayd_stream(metadata_stream, path, + LTTNG_DOMAIN_UST); if (ret < 0) { goto error_stream; } @@ -1083,7 +1085,8 @@ static int snapshot_channel(uint64_t key, char *path, uint64_t relayd_id, stream->net_seq_idx = relayd_id; if (use_relayd) { - ret = consumer_send_relayd_stream(stream, path); + ret = consumer_send_relayd_stream(stream, path, + LTTNG_DOMAIN_UST); if (ret < 0) { goto error_unlock; }