From: Julien Desfossez Date: Mon, 24 Jul 2017 20:01:30 +0000 (-0400) Subject: Change trace_path to session_root_path and chunk_path X-Git-Tag: v2.11.0-rc1~372 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=366a9222abc182bf77de1b806256aa9a9dc8832a;p=lttng-tools.git Change trace_path to session_root_path and chunk_path 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 Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 2c1ae3f51..803a88090 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; @@ -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", - session->consumer->dst.trace_path); + session->consumer->dst.session_root_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, - output->consumer->dst.trace_path, + output->consumer->dst.session_root_path, sizeof(list[idx].ctrl_url))) { ret = -LTTNG_ERR_INVALID; goto error; diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 5cbd42f63..dc21e24ca 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -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), - "%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) { diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index 99990714a..9186d2f2b 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -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, diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.c index 89bf4596b..20a7efb40 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.c +++ b/src/bin/lttng-sessiond/kernel-consumer.c @@ -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 */ - 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; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 2923664ed..114e9c21d 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -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 && - 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) { diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 3c6b5b8a0..af01654cd 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -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; diff --git a/src/bin/lttng-sessiond/snapshot.c b/src/bin/lttng-sessiond/snapshot.c index d2016a165..447806bf4 100644 --- a/src/bin/lttng-sessiond/snapshot.c +++ b/src/bin/lttng-sessiond/snapshot.c @@ -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; } diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 60ff1be03..9112cd14e 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -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 && - 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"); diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index 82fd0ea07..a431a19f0 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -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;