Relayd add_stream command handle tracefile rotation
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 28 Mar 2013 17:25:08 +0000 (13:25 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 28 Mar 2013 19:14:37 +0000 (15:14 -0400)
Extend the relayd_add_stream structure to pass the tracefile_size and
tracefile_count parameters required to handle the tracefile rotation.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
19 files changed:
src/bin/lttng-consumerd/Makefile.am
src/bin/lttng-relayd/Makefile.am
src/bin/lttng-relayd/cmd-2-1.c [new file with mode: 0644]
src/bin/lttng-relayd/cmd-2-1.h [new file with mode: 0644]
src/bin/lttng-relayd/cmd-2-2.c [new file with mode: 0644]
src/bin/lttng-relayd/cmd-2-2.h [new file with mode: 0644]
src/bin/lttng-relayd/cmd-generic.c [new file with mode: 0644]
src/bin/lttng-relayd/cmd-generic.h [new file with mode: 0644]
src/bin/lttng-relayd/cmd.h [new file with mode: 0644]
src/bin/lttng-relayd/lttng-relayd.h
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/utils.c [new file with mode: 0644]
src/bin/lttng-relayd/utils.h [new file with mode: 0644]
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
src/common/utils.c

index a395c0b378033d21bb0d65747331e3435f235990..a418eb4ac541cd6f958aa9e2d35ca2ec1ec37643 100644 (file)
@@ -4,7 +4,7 @@ lttnglibexec_PROGRAMS = lttng-consumerd
 
 lttng_consumerd_SOURCES = lttng-consumerd.c lttng-consumerd.h
 
-lttng_consumerd_LDADD = \
+lttng_consumerd_LDADD = -lrt \
           $(top_builddir)/src/common/libconsumer.la \
           $(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la \
           $(top_builddir)/src/common/libcommon.la
index a04b910f61d76eb264b3b02fccd0eba7aec94742..57045463a7b688e477eff8a0d2cc48af7d6b508e 100644 (file)
@@ -6,7 +6,10 @@ AM_CFLAGS = -fno-strict-aliasing
 
 bin_PROGRAMS = lttng-relayd
 
-lttng_relayd_SOURCES = main.c lttng-relayd.h
+lttng_relayd_SOURCES = main.c lttng-relayd.h utils.h utils.c \
+                       cmd-generic.c cmd-generic.h \
+                       cmd-2-1.c cmd-2-1.h \
+                       cmd-2-2.c cmd-2-2.h
 
 # link on liblttngctl for check if relayd is already alive.
 lttng_relayd_LDADD = -lrt -lurcu-common -lurcu \
diff --git a/src/bin/lttng-relayd/cmd-2-1.c b/src/bin/lttng-relayd/cmd-2-1.c
new file mode 100644 (file)
index 0000000..1942dee
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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 _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+
+#include <common/common.h>
+#include <common/sessiond-comm/relayd.h>
+
+#include "cmd-generic.h"
+#include "cmd-2-1.h"
+#include "utils.h"
+
+int cmd_recv_stream_2_1(struct relay_command *cmd, struct relay_stream *stream)
+{
+       int ret;
+       struct lttcomm_relayd_add_stream stream_info;
+
+       assert(cmd);
+       assert(stream);
+
+       ret = cmd_recv(cmd->sock, &stream_info, sizeof(stream_info));
+       if (ret < 0) {
+               ERR("Unable to recv stream version 2.1");
+               goto error;
+       }
+
+       stream->path_name = create_output_path(stream_info.pathname);
+       if (stream->path_name == NULL) {
+               PERROR("Path name allocation");
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       stream->channel_name = strdup(stream_info.channel_name);
+       if (stream->channel_name == NULL) {
+               ret = -errno;
+               PERROR("Path name allocation");
+               goto error;
+       }
+       ret = 0;
+
+error:
+       return ret;
+}
diff --git a/src/bin/lttng-relayd/cmd-2-1.h b/src/bin/lttng-relayd/cmd-2-1.h
new file mode 100644 (file)
index 0000000..26bc0c1
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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.
+ */
+
+#ifndef RELAYD_CMD_2_1_H
+#define RELAYD_CMD_2_1_H
+
+#include "lttng-relayd.h"
+
+int cmd_recv_stream_2_1(struct relay_command *cmd, struct relay_stream *stream);
+
+#endif /* RELAYD_CMD_2_1_H */
diff --git a/src/bin/lttng-relayd/cmd-2-2.c b/src/bin/lttng-relayd/cmd-2-2.c
new file mode 100644 (file)
index 0000000..0450fbf
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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 _GNU_SOURCE
+#include <assert.h>
+#include <string.h>
+
+#include <common/common.h>
+#include <common/sessiond-comm/relayd.h>
+
+#include "cmd-generic.h"
+#include "cmd-2-1.h"
+#include "utils.h"
+
+int cmd_recv_stream_2_2(struct relay_command *cmd, struct relay_stream *stream)
+{
+       int ret;
+       struct lttcomm_relayd_add_stream_2_2 stream_info;
+
+       assert(cmd);
+       assert(stream);
+
+       ret = cmd_recv(cmd->sock, &stream_info, sizeof(stream_info));
+       if (ret < 0) {
+               ERR("Unable to recv stream version 2.2");
+               goto error;
+       }
+
+       stream->path_name = create_output_path(stream_info.pathname);
+       if (stream->path_name == NULL) {
+               PERROR("Path name allocation");
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       stream->channel_name = strdup(stream_info.channel_name);
+       if (stream->channel_name == NULL) {
+               ret = -errno;
+               PERROR("Path name allocation");
+               goto error;
+       }
+
+       stream->tracefile_size = be64toh(stream_info.tracefile_size);
+       stream->tracefile_count = be64toh(stream_info.tracefile_count);
+       ret = 0;
+
+error:
+       return ret;
+}
diff --git a/src/bin/lttng-relayd/cmd-2-2.h b/src/bin/lttng-relayd/cmd-2-2.h
new file mode 100644 (file)
index 0000000..9a63127
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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.
+ */
+
+#ifndef RELAYD_CMD_2_2_H
+#define RELAYD_CMD_2_2_H
+
+#include "lttng-relayd.h"
+
+int cmd_recv_stream_2_2(struct relay_command *cmd, struct relay_stream *stream);
+
+#endif /* RELAYD_CMD_2_2_H */
diff --git a/src/bin/lttng-relayd/cmd-generic.c b/src/bin/lttng-relayd/cmd-generic.c
new file mode 100644 (file)
index 0000000..1122bfe
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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 _GNU_SOURCE
+#include <assert.h>
+
+#include <common/common.h>
+
+#include "cmd-generic.h"
+
+int cmd_recv(struct lttcomm_sock *sock, void *buf, size_t len)
+{
+       int ret;
+
+       assert(sock);
+       assert(buf);
+
+       ret = sock->ops->recvmsg(sock, buf, len, 0);
+       if (ret < len) {
+               if (ret == 0) {
+                       /* Orderly shutdown. Not necessary to print an error. */
+                       DBG("Socket %d did an orderly shutdown", sock->fd);
+               } else {
+                       ERR("Relay didn't receive valid add_stream struct size. "
+                                       "Expected %lu, got %d", len, ret);
+               }
+               ret = -1;
+               goto error;
+       }
+
+error:
+       return ret;
+}
diff --git a/src/bin/lttng-relayd/cmd-generic.h b/src/bin/lttng-relayd/cmd-generic.h
new file mode 100644 (file)
index 0000000..30b96b4
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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.
+ */
+
+#ifndef RELAYD_CMD_GENERIC_H
+#define RELAYD_CMD_GENERIC_H
+
+#include <common/sessiond-comm/sessiond-comm.h>
+
+int cmd_recv(struct lttcomm_sock *sock, void *buf, size_t len);
+
+#endif /* RELAYD_CMD_GENERIC_H */
diff --git a/src/bin/lttng-relayd/cmd.h b/src/bin/lttng-relayd/cmd.h
new file mode 100644 (file)
index 0000000..1463495
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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.
+ */
+
+#ifndef RELAYD_CMD_H
+#define RELAYD_CMD_H
+
+#include "cmd-generic.h"
+#include "cmd-2-1.h"
+#include "cmd-2-2.h"
+
+#endif /* RELAYD_CMD_H */
index e6ca5ebbb2b7dcbfb9f9bdb9a4d302d70c2e3475..9bbafe1dd75745625a3518ac60ed13293220a7cd 100644 (file)
@@ -22,6 +22,7 @@
 #define _LGPL_SOURCE
 #include <urcu.h>
 #include <urcu/wfqueue.h>
+#include <common/hashtable/hashtable.h>
 
 /*
  * Queue used to enqueue relay requests
@@ -47,9 +48,6 @@ struct relay_session {
         */
        uint64_t id;
        struct lttcomm_sock *sock;
-       /* protocol version to use for this session */
-       uint32_t major;
-       uint32_t minor;
 };
 
 /*
@@ -63,6 +61,14 @@ struct relay_stream {
        struct rcu_head rcu_node;
        int fd;
 
+       char *path_name;
+       char *channel_name;
+       /* on-disk circular buffer of tracefiles */
+       uint64_t tracefile_size;
+       uint64_t tracefile_size_current;
+       uint64_t tracefile_count;
+       uint64_t tracefile_count_current;
+
        /* Information telling us when to close the stream  */
        unsigned int close_flag:1;
        uint64_t last_net_seq_num;
@@ -82,6 +88,11 @@ struct relay_command {
        struct rcu_head rcu_node;
        enum connection_type type;
        unsigned int version_check_done:1;
+       /* protocol version to use for this session */
+       uint32_t major;
+       uint32_t minor;
 };
 
+extern char *opt_output_path;
+
 #endif /* LTTNG_RELAYD_H */
index 5f6f9cfd8ed78a613972c5b3ed9b999c63c90ecc..9a2b3bda7c010e9c8da7ad7a7b0345c9e4697d03 100644 (file)
 #include <common/futex.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/sessiond-comm/inet.h>
-#include <common/hashtable/hashtable.h>
 #include <common/sessiond-comm/relayd.h>
 #include <common/uri.h>
 #include <common/utils.h>
 
+#include "cmd.h"
+#include "utils.h"
 #include "lttng-relayd.h"
 
 /* command line options */
+char *opt_output_path;
 static int opt_daemon;
-static char *opt_output_path;
 static struct lttng_uri *control_uri;
 static struct lttng_uri *data_uri;
 
@@ -685,82 +686,6 @@ error:
        return NULL;
 }
 
-/*
- *  config_get_default_path
- *
- *  Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
- */
-static
-char *config_get_default_path(void)
-{
-       return getenv("HOME");
-}
-
-static
-char *create_output_path_auto(char *path_name)
-{
-       int ret;
-       char *traces_path = NULL;
-       char *alloc_path = NULL;
-       char *default_path;
-
-       default_path = config_get_default_path();
-       if (default_path == NULL) {
-               ERR("Home path not found.\n \
-                               Please specify an output path using -o, --output PATH");
-               goto exit;
-       }
-       alloc_path = strdup(default_path);
-       if (alloc_path == NULL) {
-               PERROR("Path allocation");
-               goto exit;
-       }
-       ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
-                       "/%s", alloc_path, path_name);
-       if (ret < 0) {
-               PERROR("asprintf trace dir name");
-               goto exit;
-       }
-exit:
-       free(alloc_path);
-       return traces_path;
-}
-
-static
-char *create_output_path_noauto(char *path_name)
-{
-       int ret;
-       char *traces_path = NULL;
-       char *full_path;
-
-       full_path = utils_expand_path(opt_output_path);
-       if (!full_path) {
-               goto exit;
-       }
-
-       ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
-       if (ret < 0) {
-               PERROR("asprintf trace dir name");
-               goto exit;
-       }
-exit:
-       free(full_path);
-       return traces_path;
-}
-
-/*
- * create_output_path: create the output trace directory
- */
-static
-char *create_output_path(char *path_name)
-{
-       if (opt_output_path == NULL) {
-               return create_output_path_auto(path_name);
-       } else {
-               return create_output_path_noauto(path_name);
-       }
-}
-
 /*
  * Get stream from stream id.
  * Need to be called with RCU read-side lock held.
@@ -794,6 +719,8 @@ void deferred_free_stream(struct rcu_head *head)
 {
        struct relay_stream *stream =
                caa_container_of(head, struct relay_stream, rcu_node);
+       free(stream->path_name);
+       free(stream->channel_name);
        free(stream);
 }
 
@@ -895,10 +822,8 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
                struct relay_command *cmd, struct lttng_ht *streams_ht)
 {
        struct relay_session *session = cmd->session;
-       struct lttcomm_relayd_add_stream stream_info;
        struct relay_stream *stream = NULL;
        struct lttcomm_relayd_status_stream reply;
-       char *path = NULL, *root_path = NULL;
        int ret, send_ret;
 
        if (!session || cmd->version_check_done == 0) {
@@ -907,18 +832,6 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
                goto end_no_session;
        }
 
-       ret = cmd->sock->ops->recvmsg(cmd->sock, &stream_info,
-                       sizeof(struct lttcomm_relayd_add_stream), 0);
-       if (ret < sizeof(struct lttcomm_relayd_add_stream)) {
-               if (ret == 0) {
-                       /* Orderly shutdown. Not necessary to print an error. */
-                       DBG("Socket %d did an orderly shutdown", cmd->sock->fd);
-               } else {
-                       ERR("Relay didn't receive valid add_stream struct size : %d", ret);
-               }
-               ret = -1;
-               goto end_no_session;
-       }
        stream = zmalloc(sizeof(struct relay_stream));
        if (stream == NULL) {
                PERROR("relay stream zmalloc");
@@ -926,49 +839,51 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
                goto end_no_session;
        }
 
+       switch (cmd->minor) {
+       case 1: /* LTTng sessiond 2.1 */
+               ret = cmd_recv_stream_2_1(cmd, stream);
+               break;
+       case 2: /* LTTng sessiond 2.2 */
+       default:
+               ret = cmd_recv_stream_2_2(cmd, stream);
+               break;
+       }
+       if (ret < 0) {
+               goto err_free_stream;
+       }
+
        rcu_read_lock();
        stream->stream_handle = ++last_relay_stream_id;
        stream->prev_seq = -1ULL;
        stream->session = session;
 
-       root_path = create_output_path(stream_info.pathname);
-       if (!root_path) {
-               ret = -1;
-               goto end;
-       }
-       ret = utils_mkdir_recursive(root_path, S_IRWXU | S_IRWXG);
+       ret = utils_mkdir_recursive(stream->path_name, S_IRWXU | S_IRWXG);
        if (ret < 0) {
                ERR("relay creating output directory");
                goto end;
        }
 
-       ret = asprintf(&path, "%s/%s", root_path, stream_info.channel_name);
-       if (ret < 0) {
-               PERROR("asprintf stream path");
-               path = NULL;
-               goto end;
-       }
-
-       ret = open(path, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IRWXO);
+       ret = utils_create_stream_file(stream->path_name, stream->channel_name,
+                       stream->tracefile_size, 0, getuid(), getgid());
        if (ret < 0) {
-               PERROR("Relay creating trace file");
+               ERR("Create output file");
                goto end;
        }
-
        stream->fd = ret;
-       DBG("Tracefile %s created", path);
+       if (stream->tracefile_size) {
+               DBG("Tracefile %s/%s_0 created", stream->path_name, stream->channel_name);
+       } else {
+               DBG("Tracefile %s/%s created", stream->path_name, stream->channel_name);
+       }
 
        lttng_ht_node_init_ulong(&stream->stream_n,
                        (unsigned long) stream->stream_handle);
        lttng_ht_add_unique_ulong(streams_ht,
                        &stream->stream_n);
 
-       DBG("Relay new stream added %s", stream_info.channel_name);
+       DBG("Relay new stream added %s", stream->channel_name);
 
 end:
-       free(path);
-       free(root_path);
-
        reply.handle = htobe64(stream->stream_handle);
        /* send the session id to the client or a negative return code on error */
        if (ret < 0) {
@@ -989,6 +904,12 @@ end:
 
 end_no_session:
        return ret;
+
+err_free_stream:
+       free(stream->path_name);
+       free(stream->channel_name);
+       free(stream);
+       return ret;
 }
 
 /*
@@ -1278,6 +1199,14 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
                goto end;
        }
 
+       cmd->major = reply.major;
+       /* We adapt to the lowest compatible version */
+       if (reply.minor <= be32toh(msg.minor)) {
+               cmd->minor = reply.minor;
+       } else {
+               cmd->minor = be32toh(msg.minor);
+       }
+
        reply.major = htobe32(reply.major);
        reply.minor = htobe32(reply.minor);
        ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
@@ -1286,18 +1215,8 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr,
                ERR("Relay sending version");
        }
 
-#if 0
-       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);
-#endif
+       DBG("Version check done using protocol %u.%u", cmd->major,
+                       cmd->minor);
 
 end:
        return ret;
@@ -1701,6 +1620,20 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht)
                goto end_unlock;
        }
 
+       if (stream->tracefile_size > 0 &&
+                       (stream->tracefile_size_current + data_size) >
+                       stream->tracefile_size) {
+               ret = utils_rotate_stream_file(stream->path_name,
+                               stream->channel_name, stream->tracefile_size,
+                               stream->tracefile_count, getuid(), getgid(),
+                               stream->fd, &(stream->tracefile_count_current));
+               if (ret < 0) {
+                       ERR("Rotating output file");
+                       goto end;
+               }
+               stream->fd = ret;
+       }
+       stream->tracefile_size_current += data_size;
        do {
                ret = write(stream->fd, data_buffer, data_size);
        } while (ret < 0 && errno == EINTR);
diff --git a/src/bin/lttng-relayd/utils.c b/src/bin/lttng-relayd/utils.c
new file mode 100644 (file)
index 0000000..ad13d32
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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 _GNU_SOURCE
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <common/common.h>
+#include <common/defaults.h>
+#include <common/utils.h>
+
+#include "lttng-relayd.h"
+#include "utils.h"
+
+/*
+ * Returns the HOME directory path. Caller MUST NOT free(3) the return pointer.
+ */
+static char *get_default_path(void)
+{
+       return getenv("HOME");
+}
+
+static char *create_output_path_auto(char *path_name)
+{
+       int ret;
+       char *traces_path = NULL;
+       char *alloc_path = NULL;
+       char *default_path;
+
+       default_path = get_default_path();
+       if (default_path == NULL) {
+               ERR("Home path not found.\n \
+                               Please specify an output path using -o, --output PATH");
+               goto exit;
+       }
+       alloc_path = strdup(default_path);
+       if (alloc_path == NULL) {
+               PERROR("Path allocation");
+               goto exit;
+       }
+       ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
+                       "/%s", alloc_path, path_name);
+       if (ret < 0) {
+               PERROR("asprintf trace dir name");
+               goto exit;
+       }
+exit:
+       free(alloc_path);
+       return traces_path;
+}
+
+static char *create_output_path_noauto(char *path_name)
+{
+       int ret;
+       char *traces_path = NULL;
+       char *full_path;
+
+       full_path = utils_expand_path(opt_output_path);
+       if (!full_path) {
+               goto exit;
+       }
+
+       ret = asprintf(&traces_path, "%s/%s", full_path, path_name);
+       if (ret < 0) {
+               PERROR("asprintf trace dir name");
+               goto exit;
+       }
+exit:
+       free(full_path);
+       return traces_path;
+}
+
+/*
+ * Create the output trace directory path name string.
+ *
+ * Return the allocated string containing the path name or else NULL.
+ */
+char *create_output_path(char *path_name)
+{
+       assert(path_name);
+
+       if (opt_output_path == NULL) {
+               return create_output_path_auto(path_name);
+       } else {
+               return create_output_path_noauto(path_name);
+       }
+}
diff --git a/src/bin/lttng-relayd/utils.h b/src/bin/lttng-relayd/utils.h
new file mode 100644 (file)
index 0000000..de1521d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 - Julien Desfossez <jdesfossez@efficios.com>
+ *                      David Goulet <dgoulet@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.
+ */
+
+#ifndef RELAYD_UTILS_H
+#define RELAYD_UTILS_H
+
+char *create_output_path(char *path_name);
+
+#endif /* RELAYD_UTILS_H */
index bc3ddc930cf1cb8a10d0cd03b9150a4385c15bed..2cf9ac1a894bfe7d35f31b038fa44e3343ce8e4a 100644 (file)
@@ -262,7 +262,9 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                        pthread_mutex_lock(&relayd->ctrl_sock_mutex);
                        ret = relayd_add_stream(&relayd->control_sock,
                                        new_stream->name, new_stream->chan->pathname,
-                                       &new_stream->relayd_stream_id);
+                                       &new_stream->relayd_stream_id,
+                                       new_stream->chan->tracefile_size,
+                                       new_stream->chan->tracefile_count);
                        pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
                        if (ret < 0) {
                                consumer_del_stream(new_stream, NULL);
index bed0933d1102ae4d13454ba3d152fd86d831f377..82bcf5ff6103275a23f22a8d0c47de20195f70c0 100644 (file)
@@ -161,10 +161,12 @@ error:
  * On success return 0 else return ret_code negative value.
  */
 int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_name,
-               const char *pathname, uint64_t *stream_id)
+               const char *pathname, uint64_t *stream_id,
+               uint64_t tracefile_size, uint64_t tracefile_count)
 {
        int ret;
        struct lttcomm_relayd_add_stream msg;
+       struct lttcomm_relayd_add_stream_2_2 msg_2_2;
        struct lttcomm_relayd_status_stream reply;
 
        /* Code flow error. Safety net. */
@@ -174,13 +176,28 @@ int relayd_add_stream(struct lttcomm_relayd_sock *rsock, const char *channel_nam
 
        DBG("Relayd adding stream for channel name %s", channel_name);
 
-       strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name));
-       strncpy(msg.pathname, pathname, sizeof(msg.pathname));
+       /* Compat with relayd 2.1 */
+       if (rsock->minor == 1) {
+               strncpy(msg.channel_name, channel_name, sizeof(msg.channel_name));
+               strncpy(msg.pathname, pathname, sizeof(msg.pathname));
 
-       /* Send command */
-       ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0);
-       if (ret < 0) {
-               goto error;
+               /* Send command */
+               ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg, sizeof(msg), 0);
+               if (ret < 0) {
+                       goto error;
+               }
+       } else {
+               /* Compat with relayd 2.2+ */
+               strncpy(msg_2_2.channel_name, channel_name, sizeof(msg_2_2.channel_name));
+               strncpy(msg_2_2.pathname, pathname, sizeof(msg_2_2.pathname));
+               msg_2_2.tracefile_size = htobe64(tracefile_size);
+               msg_2_2.tracefile_count = htobe64(tracefile_count);
+
+               /* Send command */
+               ret = send_command(rsock, RELAYD_ADD_STREAM, (void *) &msg_2_2, sizeof(msg_2_2), 0);
+               if (ret < 0) {
+                       goto error;
+               }
        }
 
        /* Waiting for reply */
index bbb6f9385e72b962d107ab272585827ce4179bb3..dd435e905dd1d2be3136c230c2697615369be7b5 100644 (file)
@@ -27,7 +27,8 @@ int relayd_connect(struct lttcomm_relayd_sock *sock);
 int relayd_close(struct lttcomm_relayd_sock *sock);
 int relayd_create_session(struct lttcomm_relayd_sock *sock, uint64_t *session_id);
 int relayd_add_stream(struct lttcomm_relayd_sock *sock, const char *channel_name,
-               const char *pathname, uint64_t *stream_id);
+               const char *pathname, uint64_t *stream_id,
+               uint64_t tracefile_size, uint64_t tracefile_count);
 int relayd_send_close_stream(struct lttcomm_relayd_sock *sock, uint64_t stream_id,
                uint64_t last_net_seq_num);
 int relayd_version_check(struct lttcomm_relayd_sock *sock);
index 0a8f53b4ac7d40c46215637403edda5daa5c1551..624d1b27d9cd779e5fac2628409401c3b2898241 100644 (file)
@@ -69,6 +69,17 @@ struct lttcomm_relayd_add_stream {
        char pathname[PATH_MAX];
 } LTTNG_PACKED;
 
+/*
+ * Used to add a stream on the relay daemon.
+ * Protocol version 2.2
+ */
+struct lttcomm_relayd_add_stream_2_2 {
+       char channel_name[DEFAULT_STREAM_NAME_LEN];
+       char pathname[PATH_MAX];
+       uint64_t tracefile_size;
+       uint64_t tracefile_count;
+} LTTNG_PACKED;
+
 /*
  * Answer from an add stream command.
  */
index bc0f585385814f1ba25be632f2a21fbd04232de9..5581dce191dc760e324a966c331e14b88bc7fc45 100644 (file)
@@ -223,7 +223,9 @@ static int send_stream_to_relayd(struct lttng_consumer_stream *stream)
                pthread_mutex_lock(&relayd->ctrl_sock_mutex);
                /* Add stream on the relayd */
                ret = relayd_add_stream(&relayd->control_sock, stream->name,
-                               stream->chan->pathname, &stream->relayd_stream_id);
+                               stream->chan->pathname, &stream->relayd_stream_id,
+                               stream->chan->tracefile_size,
+                               stream->chan->tracefile_count);
                pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
                if (ret < 0) {
                        goto error;
index 9f3a8f942b1176867fc7e0d55253cbae321f6130..b16cdc97c2738ad70c23624fc91295c3317b1a66 100644 (file)
@@ -340,8 +340,9 @@ int utils_create_stream_file(char *path_name, char *file_name, uint64_t size,
                path = full_path;
        }
 
+       /* Open with 660 mode */
        out_fd = run_as_open(path, O_WRONLY | O_CREAT | O_TRUNC,
-                       S_IRWXU | S_IRWXG | S_IRWXO, uid, gid);
+                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, uid, gid);
        if (out_fd < 0) {
                PERROR("open stream path %s", path);
                goto error_open;
This page took 0.039061 seconds and 4 git commands to generate.