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)
committerJulien Desfossez <jdesfossez@efficios.com>
Wed, 30 Aug 2017 18:10:05 +0000 (14:10 -0400)
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>
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 a295059fbf487ef237e97d31ffccbd9fb248fdd1..c5af9097ca14cee101ecdc061b8dd164190977b0 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);
-               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)
-                               >= sizeof(consumer->dst.trace_path)) {
+                               >= sizeof(consumer->dst.session_root_path)) {
                        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 */
-               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;
@@ -3082,7 +3082,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",
-                                       session->consumer->dst.trace_path);
+                                       session->consumer->dst.session_root_path);
                }
                if (ret < 0) {
                        PERROR("snprintf session path");
@@ -3319,7 +3319,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,
-                                       output->consumer->dst.trace_path,
+                                       output->consumer->dst.session_root_path,
                                        sizeof(list[idx].ctrl_url))) {
                                ret = -LTTNG_ERR_INVALID;
                                goto error;
index 33ccfe2248c91bd50fa0a4c94489790404e24264..c26b6b9d91d144051354c83ff92b05337e6dbc73 100644 (file)
@@ -1415,7 +1415,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),
-                               "%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) {
index b8d5630f472aed7b37e16a5ad9827fdb205bf0b0..8787122ae690f446866068725015036f4eae3499 100644 (file)
@@ -163,7 +163,8 @@ struct consumer_output {
        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];
 
@@ -178,9 +179,15 @@ struct consumer_output {
        unsigned int snapshot:1;
 
        union {
-               char trace_path[PATH_MAX];
+               char session_root_path[PATH_MAX];
                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,
index 0f59aa24f51decc781c760ddef1007399851355d..afbef8e38a5ed54353fb1a826fdae069ed991ee2 100644 (file)
@@ -44,8 +44,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 */
-               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;
index 03f695ec672006e896b462c12aef673c8b861594..06d808ba312d82d7557f422bf1af0030baf97096 100644 (file)
@@ -2995,9 +2995,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 &&
-                       strlen(session->kernel_session->consumer->dst.trace_path) > 0) {
+                       strlen(session->kernel_session->consumer->dst.session_root_path) > 0) {
                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) {
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,
-                       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;
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) {
-               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,
-                               sizeof(output->consumer->dst.trace_path))) {
+                               sizeof(output->consumer->dst.session_root_path))) {
                        ret = -LTTNG_ERR_INVALID;
                        goto error;
                }
index e79455b01fb055588c7473a913f583ae9e567ad3..c4d8e332e2963c0cdfeed96f3cd40b2076e7a178 100644 (file)
@@ -4417,9 +4417,20 @@ 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 &&
-                       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);
+                       strlen(usess->consumer->dst.session_root_path) > 0) {
+               char *tmp_path;
+
+               tmp_path = zmalloc(PATH_MAX * sizeof(char));
+               if (!tmp_path) {
+                       ERR("Alloc tmp_path");
+                       goto error_unlock;
+               }
+               snprintf(tmp_path, PATH_MAX, "%s%s",
+                               usess->consumer->dst.session_root_path,
+                               usess->consumer->chunk_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");
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 */
-               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;
This page took 0.034886 seconds and 5 git commands to generate.