#include "trace-ust.h"
#include "timer.h"
+struct ltt_session_destroy_notifier_element {
+ ltt_session_destroy_notifier notifier;
+ void *user_data;
+};
+
/*
* NOTES:
*
* The caller must hold the session lock.
*/
struct lttng_trace_archive_location *session_get_trace_archive_location(
- struct ltt_session *session)
+ const struct ltt_session *session)
{
int ret;
struct lttng_trace_archive_location *location = NULL;
struct lttng_trace_chunk *current_trace_chunk;
uint64_t chunk_id;
enum lttng_trace_chunk_status chunk_status;
- const uint64_t relayd_id = session->consumer->net_seq_index;
- const bool is_local_trace = relayd_id == -1ULL;
rcu_read_lock();
/*
}
if (session->ust_session) {
+ const uint64_t relayd_id =
+ session->ust_session->consumer->net_seq_index;
+ const bool is_local_trace =
+ session->ust_session->consumer->type ==
+ CONSUMER_DST_LOCAL;
+
session->ust_session->current_trace_chunk = new_trace_chunk;
if (is_local_trace) {
enum lttng_error_code ret_error_code;
}
}
if (session->kernel_session) {
+ const uint64_t relayd_id =
+ session->kernel_session->consumer->net_seq_index;
+ const bool is_local_trace =
+ session->kernel_session->consumer->type ==
+ CONSUMER_DST_LOCAL;
+
session->kernel_session->current_trace_chunk = new_trace_chunk;
if (is_local_trace) {
enum lttng_error_code ret_error_code;
}
int session_close_trace_chunk(const struct ltt_session *session,
- struct lttng_trace_chunk *trace_chunk)
+ struct lttng_trace_chunk *trace_chunk,
+ const enum lttng_trace_chunk_command_type *close_command)
{
int ret = 0;
bool error_occurred = false;
enum lttng_trace_chunk_status chunk_status;
const time_t chunk_close_timestamp = time(NULL);
+ if (close_command) {
+ chunk_status = lttng_trace_chunk_set_close_command(
+ trace_chunk, *close_command);
+ if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+ }
+
if (chunk_close_timestamp == (time_t) -1) {
ERR("Failed to sample the close timestamp of the current trace chunk of session \"%s\"",
session->name);
current_trace_chunk);
}
+static
+void session_notify_destruction(const struct ltt_session *session)
+{
+ size_t i;
+ const size_t count = lttng_dynamic_array_get_count(
+ &session->destroy_notifiers);
+
+ for (i = 0; i < count; i++) {
+ const struct ltt_session_destroy_notifier_element *element =
+ lttng_dynamic_array_get_element(
+ &session->destroy_notifiers, i);
+
+ element->notifier(session, element->user_data);
+ }
+}
+
static
void session_release(struct urcu_ref *ref)
{
usess = session->ust_session;
ksess = session->kernel_session;
+
+ session_notify_destruction(session);
+ lttng_dynamic_array_reset(&session->destroy_notifiers);
if (session->current_trace_chunk) {
- ret = session_close_trace_chunk(session, session->current_trace_chunk);
+ ret = session_close_trace_chunk(session, session->current_trace_chunk, NULL);
if (ret) {
ERR("Failed to close the current trace chunk of session \"%s\" during its release",
session->name);
session_put(session);
}
+int session_add_destroy_notifier(struct ltt_session *session,
+ ltt_session_destroy_notifier notifier, void *user_data)
+{
+ const struct ltt_session_destroy_notifier_element element = {
+ .notifier = notifier,
+ .user_data = user_data
+ };
+
+ return lttng_dynamic_array_add_element(&session->destroy_notifiers,
+ &element);
+}
+
/*
* Return a ltt_session structure ptr that matches name. If no session found,
* NULL is returned. This must be called with the session list lock held using
goto error;
}
+ lttng_dynamic_array_init(&new_session->destroy_notifiers,
+ sizeof(struct ltt_session_destroy_notifier_element),
+ NULL);
urcu_ref_init(&new_session->ref);
pthread_mutex_init(&new_session->lock, NULL);