#include "notification-thread-commands.h"
#include "rotate.h"
#include "rotation-thread.h"
+#include "sessiond-timer.h"
#include "cmd.h"
* an eventual session rotation call.
*/
if (!session->has_been_started) {
- session->session_start_ts = time(NULL);
- if (session->session_start_ts == (time_t) -1) {
+ session->current_chunk_start_ts = time(NULL);
+ if (session->current_chunk_start_ts == (time_t) -1) {
PERROR("Get start time");
ret = LTTNG_ERR_FATAL;
goto error;
session->has_been_started = 1;
session->active = 1;
+ if (session->rotate_timer_period) {
+ ret = sessiond_rotate_timer_start(session,
+ session->rotate_timer_period);
+ if (ret < 0) {
+ ERR("Failed to enable rotate timer");
+ ret = LTTNG_ERR_UNK;
+ goto error;
+ }
+ }
+
ret = LTTNG_OK;
error:
}
}
+ if (session->rotate_relay_pending_timer_enabled) {
+ sessiond_timer_rotate_pending_stop(session);
+ }
+
+ if (session->rotate_timer_enabled) {
+ sessiond_rotate_timer_stop(session);
+ }
+
/* Clean kernel session teardown */
kernel_destroy_session(ksess);
}
}
+ /*
+ * A rotation is still pending, we have to wait.
+ */
+ if (session->rotate_pending) {
+ ret = 1;
+ goto error;
+ }
+
if (ksess && ksess->consumer) {
ret = consumer_is_data_pending(ksess->id, ksess->consumer);
if (ret == 1) {
}
static
-int rename_first_chunk(struct ltt_session *session,
- struct consumer_output *consumer, char *datetime)
+const char *get_base_path(struct ltt_session *session,
+ struct consumer_output *consumer)
{
- int ret;
- char *tmppath = NULL, *tmppath2 = NULL;
-
- tmppath = zmalloc(PATH_MAX * sizeof(char));
- if (!tmppath) {
- ret = -LTTNG_ERR_NOMEM;
- goto error;
- }
- tmppath2 = zmalloc(PATH_MAX * sizeof(char));
- if (!tmppath2) {
- ret = -LTTNG_ERR_NOMEM;
- goto error;
- }
-
- /* Current domain path: <session>/kernel */
- snprintf(tmppath, PATH_MAX, "%s/%s",
- consumer->dst.session_root_path, consumer->subdir);
- /* New domain path: <session>/<start-date>-/kernel */
- snprintf(tmppath2, PATH_MAX, "%s/%s-/%s",
- consumer->dst.session_root_path, datetime,
- consumer->subdir);
- /*
- * Move the per-domain folder inside the first rotation
- * folder.
- */
- ret = session_rename_chunk(session, tmppath, tmppath2, 1);
- if (ret < 0) {
- PERROR("Rename first trace directory");
- ret = -LTTNG_ERR_ROTATE_NO_DATA;
- goto error;
+ if (session->net_handle > 0) {
+ return consumer->dst.net.base_dir;
+ } else {
+ return consumer->dst.session_root_path;
}
-
- ret = 0;
-
-error:
- free(tmppath);
- free(tmppath2);
-
- return ret;
}
/*
* Command LTTNG_ROTATE_SESSION from the lttng-ctl library.
*
* Ask the consumer to rotate the session output directory.
+ * The session lock must be held.
*
* Return 0 on success or else a LTTNG_ERR code.
*/
assert(session);
- *rotate_return = zmalloc(sizeof(struct lttng_rotate_session_return));
- if (!*rotate_return) {
- ret = -ENOMEM;
- goto end;
+ if (rotate_return) {
+ *rotate_return = zmalloc(sizeof(struct lttng_rotate_session_return));
+ if (!*rotate_return) {
+ ret = -ENOMEM;
+ goto end;
+ }
}
if (session->live_timer || session->snapshot_mode ||
goto error;
}
- if (session->rotate_pending) {
+ if (session->rotate_pending || session->rotate_pending_relay) {
ret = -LTTNG_ERR_ROTATE_PENDING;
goto error;
}
/* Special case for the first rotation. */
if (session->rotate_count == 0) {
- timeinfo = localtime(&session->session_start_ts);
- strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
+ const char *base_path = NULL;
+
/* Either one of the two sessions is enough to get the root path. */
if (session->kernel_session) {
- snprintf(session->rotation_chunk.current_rotate_path,
- PATH_MAX, "%s/%s-",
- session->kernel_session->consumer->dst.session_root_path,
- datetime);
+ base_path = get_base_path(session, session->kernel_session->consumer);
} else if (session->ust_session) {
- snprintf(session->rotation_chunk.current_rotate_path,
- PATH_MAX, "%s/%s-",
- session->ust_session->consumer->dst.session_root_path,
- datetime);
+ base_path = get_base_path(session, session->ust_session->consumer);
} else {
assert(0);
}
-
- /*
- * Create the first rotation folder to move the existing
- * kernel/ust folders into.
- */
- ret = run_as_mkdir_recursive(session->rotation_chunk.current_rotate_path,
- S_IRWXU | S_IRWXG, session->uid, session->gid);
- if (ret < 0) {
- if (errno != EEXIST) {
- ERR("Trace directory creation error");
- ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
- goto error;
- }
- }
- if (session->kernel_session) {
- ret = rename_first_chunk(session,
- session->kernel_session->consumer,
- datetime);
- if (ret < 0) {
- goto error;
- }
- }
- if (session->ust_session) {
- ret = rename_first_chunk(session,
- session->ust_session->consumer,
- datetime);
- if (ret < 0) {
- goto error;
- }
- }
+ assert(base_path);
+ snprintf(session->rotation_chunk.current_rotate_path,
+ PATH_MAX, "%s",
+ base_path);
} else {
/*
* The currently active tracing path is now the folder we
}
session->rotate_count++;
- session->rotate_pending = 1;
+ session->rotate_pending = true;
+ session->rotate_pending_relay_check_in_progress = false;
+ session->rotate_status = LTTNG_ROTATE_STARTED;
/*
* Create the path name for the next chunk.
ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
goto error;
}
+ session->last_chunk_start_ts = session->current_chunk_start_ts;
+ session->current_chunk_start_ts = now;
timeinfo = localtime(&now);
strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
if (session->kernel_session) {
- /* The active path for the next rotation/destroy. */
+ /*
+ * The active path for the next rotation/destroy.
+ * Ex: ~/lttng-traces/auto-20170922-111748/20170922-111754-42
+ */
snprintf(session->rotation_chunk.active_tracing_path,
- PATH_MAX, "%s/%s-",
- session->kernel_session->consumer->dst.session_root_path,
- datetime);
- /* The sub-directory for the consumer. */
+ PATH_MAX, "%s/%s-%" PRIu64,
+ get_base_path(session, session->kernel_session->consumer),
+ datetime, session->rotate_count + 1);
+ /*
+ * The sub-directory for the consumer
+ * Ex: /20170922-111754-42/kernel
+ */
snprintf(session->kernel_session->consumer->chunk_path,
- PATH_MAX, "/%s-/%s/", datetime,
+ PATH_MAX, "/%s-%" PRIu64 "%s", datetime,
+ session->rotate_count + 1,
session->kernel_session->consumer->subdir);
ret = kernel_rotate_session(session);
if (ret != LTTNG_OK) {
}
if (session->ust_session) {
snprintf(session->rotation_chunk.active_tracing_path,
- PATH_MAX, "%s/%s-",
- session->ust_session->consumer->dst.session_root_path,
- datetime);
+ PATH_MAX, "%s/%s-%" PRIu64,
+ get_base_path(session, session->ust_session->consumer),
+ datetime, session->rotate_count + 1);
snprintf(session->ust_session->consumer->chunk_path,
- PATH_MAX, "/%s-/", datetime);
+ PATH_MAX, "/%s-%" PRIu64, datetime,
+ session->rotate_count + 1);
ret = ust_app_rotate_session(session);
if (ret != LTTNG_OK) {
goto error;
}
}
- (*rotate_return)->rotate_id = session->rotate_count;
- (*rotate_return)->status = LTTNG_ROTATE_STARTED;
+ if (rotate_return) {
+ (*rotate_return)->rotate_id = session->rotate_count;
+ (*rotate_return)->status = LTTNG_ROTATE_STARTED;
+ }
DBG("Cmd rotate session %s, rotate_id %" PRIu64, session->name,
session->rotate_count);
goto end;
error:
- (*rotate_return)->status = LTTNG_ROTATE_ERROR;
+ if (rotate_return) {
+ (*rotate_return)->status = LTTNG_ROTATE_ERROR;
+ }
end:
return ret;
}
goto end;
}
- if (session->rotate_pending) {
+ if (session->rotate_status == LTTNG_ROTATE_ERROR) {
+ DBG("An error occurred during rotation");
+ (*pending_return)->status = LTTNG_ROTATE_ERROR;
+ } else if (session->rotate_status == LTTNG_ROTATE_EMPTY) {
+ DBG("Nothing to rotate");
+ (*pending_return)->status = LTTNG_ROTATE_EMPTY;
+ /* Rotate with a relay */
+ } else if (session->rotate_pending_relay) {
+ DBG("Session %s, rotate_id %" PRIu64 " still pending",
+ session->name, session->rotate_count);
+ (*pending_return)->status = LTTNG_ROTATE_STARTED;
+ } else if (session->rotate_pending) {
DBG("Session %s, rotate_id %" PRIu64 " still pending",
session->name, session->rotate_count);
(*pending_return)->status = LTTNG_ROTATE_STARTED;
return ret;
}
+/*
+ * Command LTTNG_ROTATE_SETUP from the lttng-ctl library.
+ *
+ * Configure the automatic rotation parameters.
+ *
+ * Return 0 on success or else a LTTNG_ERR code.
+ */
+int cmd_rotate_setup(struct ltt_session *session,
+ uint64_t timer_us, uint64_t size)
+{
+ int ret;
+
+ assert(session);
+
+ DBG("Cmd rotate setup session %s", session->name);
+
+ if (timer_us && session->rotate_timer_period) {
+ ret = LTTNG_ERR_ROTATE_TIMER_EXISTS;
+ goto end;
+ }
+
+ if (size && session->rotate_size) {
+ ret = LTTNG_ERR_ROTATE_SIZE_EXISTS;
+ goto end;
+ }
+
+ if (timer_us && !session->rotate_timer_period) {
+ session->rotate_timer_period = timer_us;
+ /*
+ * Only start the timer if the session is active, otherwise
+ * it will be started when the session starts.
+ */
+ if (session->active) {
+ ret = sessiond_rotate_timer_start(session, timer_us);
+ if (ret) {
+ ERR("Failed to enable rotate timer");
+ ret = LTTNG_ERR_UNK;
+ goto end;
+ }
+ }
+ } else if (timer_us == -1ULL && session->rotate_timer_period > 0) {
+ sessiond_rotate_timer_stop(session);
+ }
+ session->rotate_size = size;
+
+ ret = LTTNG_OK;
+
+ goto end;
+
+end:
+ return ret;
+}
+
/*
* Init command subsystem.
*/