Change trace_path to session_root_path and chunk_path
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 24 Jul 2017 20:01:30 +0000 (16:01 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Feb 2018 20:22:29 +0000 (15:22 -0500)
Prepare for the trace rotation feature where we need to store the root
path of the session and create a subdirectory for each chunk of trace.
For now, the chunk_path is \0, so the behaviour does not change.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng-sessiond/consumer.h
src/bin/lttng-sessiond/kernel-consumer.c
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/save.c
src/bin/lttng-sessiond/snapshot.c
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-consumer.c

index 2c1ae3f5132ea3e8a0031dfe6525af733926c535..803a88090c95d28a733f7e04614238c830980055 100644 (file)
@@ -784,17 +784,17 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
                break;
        case LTTNG_DST_PATH:
                DBG2("Setting trace directory path from URI to %s", uri->dst.path);
                break;
        case LTTNG_DST_PATH:
                DBG2("Setting trace directory path from URI to %s", uri->dst.path);
-               memset(consumer->dst.trace_path, 0,
-                               sizeof(consumer->dst.trace_path));
+               memset(consumer->dst.session_root_path, 0,
+                               sizeof(consumer->dst.session_root_path));
                /* Explicit length checks for strcpy and strcat. */
                if (strlen(uri->dst.path) + strlen(default_trace_dir)
                /* Explicit length checks for strcpy and strcat. */
                if (strlen(uri->dst.path) + strlen(default_trace_dir)
-                               >= sizeof(consumer->dst.trace_path)) {
+                               >= sizeof(consumer->dst.session_root_path)) {
                        ret = LTTNG_ERR_FATAL;
                        goto error;
                }
                        ret = LTTNG_ERR_FATAL;
                        goto error;
                }
-               strcpy(consumer->dst.trace_path, uri->dst.path);
+               strcpy(consumer->dst.session_root_path, uri->dst.path);
                /* Append default trace dir */
                /* Append default trace dir */
-               strcat(consumer->dst.trace_path, default_trace_dir);
+               strcat(consumer->dst.session_root_path, default_trace_dir);
                /* Flag consumer as local. */
                consumer->type = CONSUMER_DST_LOCAL;
                break;
                /* Flag consumer as local. */
                consumer->type = CONSUMER_DST_LOCAL;
                break;
@@ -3099,7 +3099,7 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid,
                                        sizeof(sessions[i].path), session);
                } else {
                        ret = snprintf(sessions[i].path, sizeof(sessions[i].path), "%s",
                                        sizeof(sessions[i].path), session);
                } else {
                        ret = snprintf(sessions[i].path, sizeof(sessions[i].path), "%s",
-                                       session->consumer->dst.trace_path);
+                                       session->consumer->dst.session_root_path);
                }
                if (ret < 0) {
                        PERROR("snprintf session path");
                }
                if (ret < 0) {
                        PERROR("snprintf session path");
@@ -3336,7 +3336,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                }
                if (output->consumer->type == CONSUMER_DST_LOCAL) {
                        if (lttng_strncpy(list[idx].ctrl_url,
                }
                if (output->consumer->type == CONSUMER_DST_LOCAL) {
                        if (lttng_strncpy(list[idx].ctrl_url,
-                                       output->consumer->dst.trace_path,
+                                       output->consumer->dst.session_root_path,
                                        sizeof(list[idx].ctrl_url))) {
                                ret = -LTTNG_ERR_INVALID;
                                goto error;
                                        sizeof(list[idx].ctrl_url))) {
                                ret = -LTTNG_ERR_INVALID;
                                goto error;
index 5cbd42f6301d327abefdb159541dc7f651983e9d..dc21e24ca0a5c01e4c2e8d3b24082492685944bf 100644 (file)
@@ -1427,7 +1427,7 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key,
        } else {
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
        } else {
                ret = snprintf(msg.u.snapshot_channel.pathname,
                                sizeof(msg.u.snapshot_channel.pathname),
-                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.trace_path,
+                               "%s/%s-%s-%" PRIu64 "%s", output->consumer->dst.session_root_path,
                                output->name, output->datetime, output->nb_snapshot,
                                session_path);
                if (ret < 0) {
                                output->name, output->datetime, output->nb_snapshot,
                                session_path);
                if (ret < 0) {
index 99990714ac61e80039a80e77ba04953d55c2a495..9186d2f2be19a1ac325a8789734db218947a0cae 100644 (file)
@@ -163,7 +163,8 @@ struct consumer_output {
        uint32_t relay_minor_version;
 
        /*
        uint32_t relay_minor_version;
 
        /*
-        * Subdirectory path name used for both local and network consumer.
+        * Subdirectory path name used for both local and network
+        * consumer (/kernel or /ust).
         */
        char subdir[PATH_MAX];
 
         */
        char subdir[PATH_MAX];
 
@@ -178,9 +179,15 @@ struct consumer_output {
        unsigned int snapshot:1;
 
        union {
        unsigned int snapshot:1;
 
        union {
-               char trace_path[PATH_MAX];
+               char session_root_path[PATH_MAX];
                struct consumer_net net;
        } dst;
                struct consumer_net net;
        } dst;
+
+       /*
+        * Sub-directory below the session_root_path where the next chunk of
+        * trace will be stored (\0 before the first session rotation).
+        */
+       char chunk_path[PATH_MAX];
 };
 
 struct consumer_socket *consumer_find_socket(int key,
 };
 
 struct consumer_socket *consumer_find_socket(int key,
index 89bf4596b54969ebd556d2d27faec3a66e011a98..20a7efb402a2314a9fcc006dbf4c84439e5a099f 100644 (file)
@@ -45,8 +45,10 @@ static char *create_channel_path(struct consumer_output *consumer,
        /* Get the right path name destination */
        if (consumer->type == CONSUMER_DST_LOCAL) {
                /* Set application path to the destination path */
        /* Get the right path name destination */
        if (consumer->type == CONSUMER_DST_LOCAL) {
                /* Set application path to the destination path */
-               ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s",
-                               consumer->dst.trace_path, consumer->subdir);
+               ret = snprintf(tmp_path, sizeof(tmp_path), "%s%s%s",
+                               consumer->dst.session_root_path,
+                               consumer->chunk_path,
+                               consumer->subdir);
                if (ret < 0) {
                        PERROR("snprintf kernel channel path");
                        goto error;
                if (ret < 0) {
                        PERROR("snprintf kernel channel path");
                        goto error;
index 2923664edc7e20d4b7c67b6ec0be621dcab942a9..114e9c21d7a10432613ea480aef7ba0bc6d2c3e4 100644 (file)
@@ -2834,9 +2834,9 @@ static int create_kernel_session(struct ltt_session *session)
 
        /* Create directory(ies) on local filesystem. */
        if (session->kernel_session->consumer->type == CONSUMER_DST_LOCAL &&
 
        /* Create directory(ies) on local filesystem. */
        if (session->kernel_session->consumer->type == CONSUMER_DST_LOCAL &&
-                       strlen(session->kernel_session->consumer->dst.trace_path) > 0) {
+                       strlen(session->kernel_session->consumer->dst.session_root_path) > 0) {
                ret = run_as_mkdir_recursive(
                ret = run_as_mkdir_recursive(
-                               session->kernel_session->consumer->dst.trace_path,
+                               session->kernel_session->consumer->dst.session_root_path,
                                S_IRWXU | S_IRWXG, session->uid, session->gid);
                if (ret < 0) {
                        if (errno != EEXIST) {
                                S_IRWXU | S_IRWXG, session->uid, session->gid);
                if (ret < 0) {
                        if (errno != EEXIST) {
index 3c6b5b8a01931540cbd050a9600f969e0076b471..af01654cd450f4aa54c46bd9d0914982a22b62d1 100644 (file)
@@ -1673,7 +1673,7 @@ int save_consumer_output(struct config_writer *writer,
        switch (output->type) {
        case CONSUMER_DST_LOCAL:
                ret = config_writer_write_element_string(writer,
        switch (output->type) {
        case CONSUMER_DST_LOCAL:
                ret = config_writer_write_element_string(writer,
-                       config_element_path, output->dst.trace_path);
+                       config_element_path, output->dst.session_root_path);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
index d2016a1656bae9b9ed0fede367534d05bd9d4b34..447806bf4428fd4d8de87b411818b00b5fd5c372 100644 (file)
@@ -94,11 +94,11 @@ static int output_init(uint64_t max_size, const char *name,
        }
 
        if (uris[0].dtype == LTTNG_DST_PATH) {
        }
 
        if (uris[0].dtype == LTTNG_DST_PATH) {
-               memset(output->consumer->dst.trace_path, 0,
-                               sizeof(output->consumer->dst.trace_path));
-               if (lttng_strncpy(output->consumer->dst.trace_path,
+               memset(output->consumer->dst.session_root_path, 0,
+                               sizeof(output->consumer->dst.session_root_path));
+               if (lttng_strncpy(output->consumer->dst.session_root_path,
                                uris[0].dst.path,
                                uris[0].dst.path,
-                               sizeof(output->consumer->dst.trace_path))) {
+                               sizeof(output->consumer->dst.session_root_path))) {
                        ret = -LTTNG_ERR_INVALID;
                        goto error;
                }
                        ret = -LTTNG_ERR_INVALID;
                        goto error;
                }
index 60ff1be03b194eee686aa391e73615039988b3ab..9112cd14e39cf37cafb1d904d3bada5042cfe00b 100644 (file)
@@ -4417,9 +4417,32 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
 
        /* Create directories if consumer is LOCAL and has a path defined. */
        if (usess->consumer->type == CONSUMER_DST_LOCAL &&
 
        /* Create directories if consumer is LOCAL and has a path defined. */
        if (usess->consumer->type == CONSUMER_DST_LOCAL &&
-                       strlen(usess->consumer->dst.trace_path) > 0) {
-               ret = run_as_mkdir_recursive(usess->consumer->dst.trace_path,
-                               S_IRWXU | S_IRWXG, ua_sess->euid, ua_sess->egid);
+                       usess->consumer->dst.session_root_path[0] != '\0') {
+               char *tmp_path;
+
+               tmp_path = zmalloc(PATH_MAX * sizeof(char));
+               if (!tmp_path) {
+                       ERR("Alloc tmp_path");
+                       goto error_unlock;
+               }
+               ret = snprintf(tmp_path, PATH_MAX, "%s%s%s",
+                               usess->consumer->dst.session_root_path,
+                               usess->consumer->chunk_path,
+                               usess->consumer->subdir);
+               if (ret >= PATH_MAX) {
+                       ERR("Local destination path exceeds the maximal allowed length of %i bytes (needs %i bytes) with path = \"%s%s%s\"",
+                                       PATH_MAX, ret,
+                                       usess->consumer->dst.session_root_path,
+                                       usess->consumer->chunk_path,
+                                       usess->consumer->subdir);
+                       goto error_unlock;
+               }
+
+               DBG("Creating directory path for local tracing: \"%s\"",
+                               tmp_path);
+               ret = run_as_mkdir_recursive(tmp_path, S_IRWXU | S_IRWXG,
+                               ua_sess->euid, ua_sess->egid);
+               free(tmp_path);
                if (ret < 0) {
                        if (errno != EEXIST) {
                                ERR("Trace directory creation error");
                if (ret < 0) {
                        if (errno != EEXIST) {
                                ERR("Trace directory creation error");
index 82fd0ea074e0519c2c6bac47c146295e6c861053..a431a19f01ac8e9706caf5201529f0559586f4d9 100644 (file)
@@ -62,8 +62,10 @@ static char *setup_trace_path(struct consumer_output *consumer,
        /* Get correct path name destination */
        if (consumer->type == CONSUMER_DST_LOCAL) {
                /* Set application path to the destination path */
        /* Get correct path name destination */
        if (consumer->type == CONSUMER_DST_LOCAL) {
                /* Set application path to the destination path */
-               ret = snprintf(pathname, PATH_MAX, "%s%s%s",
-                               consumer->dst.trace_path, consumer->subdir, ua_sess->path);
+               ret = snprintf(pathname, PATH_MAX, "%s%s%s%s",
+                               consumer->dst.session_root_path,
+                               consumer->chunk_path,
+                               consumer->subdir, ua_sess->path);
                if (ret < 0) {
                        PERROR("snprintf channel path");
                        goto error;
                if (ret < 0) {
                        PERROR("snprintf channel path");
                        goto error;
This page took 0.033983 seconds and 4 git commands to generate.