Send domain with streams to the relay
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 7 Aug 2017 20:39:03 +0000 (16:39 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Wed, 6 Sep 2017 17:59:58 +0000 (13:59 -0400)
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 <jdesfossez@efficios.com>
13 files changed:
src/bin/lttng-relayd/Makefile.am
src/bin/lttng-relayd/cmd-2-11.c [new file with mode: 0644]
src/bin/lttng-relayd/cmd-2-11.h [new file with mode: 0644]
src/bin/lttng-relayd/cmd.h
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/session.h
src/common/consumer/consumer.c
src/common/consumer/consumer.h
src/common/kernel-consumer/kernel-consumer.c
src/common/relayd/relayd.c
src/common/relayd/relayd.h
src/common/sessiond-comm/relayd.h
src/common/ust-consumer/ust-consumer.c

index c7dd37e1ae5e356f7bcec2082665a4d1f21bacbb..45256c8e373e55812662af40861a7eae351221b4 100644 (file)
@@ -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 (file)
index 0000000..17371d8
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@efficios.com>
+ *               2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <assert.h>
+
+#include <common/common.h>
+#include <common/sessiond-comm/relayd.h>
+
+#include <common/compat/endian.h>
+#include <common/compat/string.h>
+#include <lttng/constant.h>
+
+#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 (file)
index 0000000..a3163bc
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef RELAYD_CMD_2_11_H
+#define RELAYD_CMD_2_11_H
+
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@efficios.com>
+ *               2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 */
index 88db09aedeba06cb355d83664d5fd34743ca2997..f0289a1ab04d25267aeaa0ab77d2fe8542b1b19b 100644 (file)
@@ -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 */
index 6a536d36d9fcc03f64b855a515875871f7dbb85b..c1b044f5786ae9c98f777c0420ab502bcb371b3e 100644 (file)
@@ -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;
index 2410fd483ad8ae74f82902c8aafac152573f506d..606574ea26b38c5ff8af1b93ec88d88b21601ea3 100644 (file)
@@ -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,
index d22f947e13df5e87e90ff2fd82b381295abd3e38..f187584f3913f21d6f8c20ae4af98722b0394b90 100644 (file)
@@ -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;
index bf79bcb97c28375fb540747c9b70b1d3bbd3d2ba..92552504eb796ebc03190a9d8b7d8ae6db7d1da0 100644 (file)
@@ -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);
index ffcdde035c81b515748464f2bbbc96de91b94773..bdca6708721947f3fec0d24781feeb68f853c82e 100644 (file)
@@ -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;
index 17edd6acf55c61b9c200a99b6cfcc795fd1b9329..dad845d5c95f08e8f323b496d169f55f710cf306 100644 (file)
@@ -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 */
index ba2faa46ca65b160f16a271cbdfcfb90d96b169e..4c5c2daf5cacc12e4d0b75385f321f2c1ef7fb6d 100644 (file)
@@ -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);
index 2f0a2c6cdf55a857cbfedb843f841bcb57b68eaa..bc754ee5caeb58650131396f1603bb533d5976f4 100644 (file)
@@ -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.
  */
index d467de4fb241de219d41555ac9235fbb9ac01b5b..3a67c7d5b593a4861946b5f73c2a827dcdd4a58a 100644 (file)
@@ -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;
                        }
This page took 0.036446 seconds and 5 git commands to generate.