#include "notification-thread-commands.h"
#include "rotate.h"
#include "rotation-thread.h"
+#include "sessiond-timer.h"
#include "cmd.h"
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) {
* 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;
}
snprintf(session->rotation_chunk.current_rotate_path,
PATH_MAX, "%s",
base_path);
- fprintf(stderr, "b: %s\n", base_path);
} else {
/*
* The currently active tracing path is now the folder we
session->rotate_count++;
session->rotate_pending = true;
+ session->rotate_pending_relay_check_in_progress = false;
session->rotate_status = LTTNG_ROTATE_STARTED;
/*
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-",
+ PATH_MAX, "%s/%s-%" PRIu64,
get_base_path(session, session->kernel_session->consumer),
- datetime);
- /* The sub-directory for the 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-",
+ PATH_MAX, "%s/%s-%" PRIu64,
get_base_path(session, session->ust_session->consumer),
- datetime);
+ 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;
}
(*pending_return)->status = LTTNG_ROTATE_EMPTY;
/* Rotate with a relay */
} else if (session->rotate_pending_relay) {
- /* The consumer has not finished the rotation. */
- if (session->rotate_pending) {
- DBG("Session %s, rotate_id %" PRIu64 " still pending",
- session->name, session->rotate_count);
- (*pending_return)->status = LTTNG_ROTATE_STARTED;
- } else {
- /*
- * The consumer finished the rotation, but we don't
- * know if the relay still has data pending. We need
- * to find one consumer_output to talk to the relay
- * and ask it.
- */
- ret = relay_rotate_pending(session);
- if (ret == 0) {
- DBG("Rotate completed on the relay for session %s"
- ", rotate_id %" PRIu64,
- session->name,
- session->rotate_count);
- (*pending_return)->status = LTTNG_ROTATE_COMPLETED;
- snprintf((*pending_return)->output_path, PATH_MAX, "%s",
- session->rotation_chunk.current_rotate_path);
- } else if (ret == 1) {
- DBG("Session %s, rotate_id %" PRIu64 " still pending "
- "on the relay",
- session->name, session->rotate_count);
- (*pending_return)->status = LTTNG_ROTATE_STARTED;
- } else {
- ERR("Failed to check rotate pending on the relay");
- (*pending_return)->status = LTTNG_ROTATE_ERROR;
- }
- }
+ 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);
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.
*/