X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Frotate.c;h=dac0f2a1fda8145cfa8f7fdbca724a2890257f87;hb=dbc478f3152cf3b4c695eb5c5c28930d03d78f69;hp=05e9bb08a48ca397710beb720c78ea5e59891df4;hpb=db66e57489e5014289dc1d831e1eac90ac4fc0da;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.c index 05e9bb08a..dac0f2a1f 100644 --- a/src/bin/lttng-sessiond/rotate.c +++ b/src/bin/lttng-sessiond/rotate.c @@ -32,6 +32,9 @@ #include #include +#include +#include + #include "session.h" #include "rotate.h" #include "rotation-thread.h" @@ -39,6 +42,7 @@ #include "health-sessiond.h" #include "cmd.h" #include "utils.h" +#include "notification-thread-commands.h" #include #include @@ -50,6 +54,38 @@ unsigned long hash_channel_key(struct rotation_channel_key *key) (void *) (unsigned long) key->domain, lttng_ht_seed); } +int rotate_add_channel_pending(uint64_t key, enum lttng_domain_type domain, + struct ltt_session *session) +{ + int ret; + struct rotation_channel_info *new_info; + struct rotation_channel_key channel_key = { .key = key, + .domain = domain }; + + new_info = zmalloc(sizeof(struct rotation_channel_info)); + if (!new_info) { + goto error; + } + + new_info->channel_key.key = key; + new_info->channel_key.domain = domain; + new_info->session_id = session->id; + cds_lfht_node_init(&new_info->rotate_channels_ht_node); + + session->nr_chan_rotate_pending++; + cds_lfht_add(channel_pending_rotate_ht, + hash_channel_key(&channel_key), + &new_info->rotate_channels_ht_node); + + ret = 0; + goto end; + +error: + ret = -1; +end: + return ret; +} + /* The session's lock must be held by the caller. */ static int session_rename_chunk(struct ltt_session *session, char *current_path, @@ -175,8 +211,8 @@ error: int rename_complete_chunk(struct ltt_session *session, time_t ts) { struct tm *timeinfo; - char datetime[16], start_datetime[16]; char new_path[LTTNG_PATH_MAX]; + char datetime[21], start_datetime[21]; int ret; size_t strf_ret; @@ -187,7 +223,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = -1; goto end; } - strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", + + strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%dT%H%M%S%z", timeinfo); if (strf_ret == 0) { ERR("Failed to format timestamp while renaming completed session chunk"); @@ -195,8 +232,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) goto end; } - if (session->rotate_count == 1) { - char start_time[16]; + if (session->current_archive_id == 1) { + char start_time[21]; timeinfo = localtime(&session->last_chunk_start_ts); if (!timeinfo) { @@ -206,7 +243,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) } strf_ret = strftime(start_time, sizeof(start_time), - "%Y%m%d-%H%M%S", timeinfo); + "%Y%m%dT%H%M%S%z", timeinfo); if (strf_ret == 0) { ERR("Failed to format timestamp while renaming completed session chunk"); ret = -1; @@ -221,7 +258,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64, session->rotation_chunk.current_rotate_path, start_time, - datetime, session->rotate_count); + datetime, session->current_archive_id); if (ret < 0 || ret >= sizeof(new_path)) { ERR("Failed to format new chunk path while renaming session \"%s\"'s first chunk", session->name); @@ -268,7 +305,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = -1; goto end; } - strf_ret = strftime(start_datetime, sizeof(start_datetime), "%Y%m%d-%H%M%S", timeinfo); + strf_ret = strftime(start_datetime, sizeof(start_datetime), + "%Y%m%dT%H%M%S%z", timeinfo); if (!strf_ret) { ERR("Failed to format timestamp while renaming completed session chunk"); ret = -1; @@ -277,7 +315,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64, session_get_base_path(session), start_datetime, - datetime, session->rotate_count); + datetime, session->current_archive_id); if (ret < 0 || ret >= sizeof(new_path)) { ERR("Failed to format new chunk path while renaming chunk of session \"%s\"", session->name); @@ -314,7 +352,152 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) goto end; error: - session->rotation_status = LTTNG_ROTATION_STATUS_ERROR; + session->rotation_state = LTTNG_ROTATION_STATE_ERROR; +end: + return ret; +} + +int relay_rotate_pending(struct ltt_session *session, uint64_t chunk_id) +{ + int ret; + struct consumer_socket *socket; + struct consumer_output *output; + struct lttng_ht_iter iter; + + /* + * Either one of the sessions is enough to find the consumer_output + * and uid/gid. + */ + if (session->kernel_session) { + output = session->kernel_session->consumer; + } else if (session->ust_session) { + output = session->ust_session->consumer; + } else { + assert(0); + } + + if (!output || !output->socks) { + ERR("No consumer output found"); + ret = -1; + goto end; + } + + ret = -1; + + rcu_read_lock(); + /* + * We have to iterate to find a socket, but we only need to send the + * rotate pending command to one consumer, so we break after the first + * one. + */ + cds_lfht_for_each_entry(output->socks->ht, &iter.iter, socket, + node.node) { + pthread_mutex_lock(socket->lock); + ret = consumer_rotate_pending_relay(socket, output, session->id, + chunk_id); + pthread_mutex_unlock(socket->lock); + break; + } + rcu_read_unlock(); + +end: + return ret; +} + +int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64_t size, + struct notification_thread_handle *notification_thread_handle) +{ + int ret; + enum lttng_condition_status condition_status; + enum lttng_notification_channel_status nc_status; + struct lttng_action *action; + + session->rotate_condition = lttng_condition_session_consumed_size_create(); + if (!session->rotate_condition) { + ERR("Failed to create session consumed size condition object"); + ret = -1; + goto end; + } + + condition_status = lttng_condition_session_consumed_size_set_threshold( + session->rotate_condition, size); + if (condition_status != LTTNG_CONDITION_STATUS_OK) { + ERR("Could not set session consumed size condition threshold (size = %" PRIu64 ")", + size); + ret = -1; + goto end; + } + + condition_status = + lttng_condition_session_consumed_size_set_session_name( + session->rotate_condition, session->name); + if (condition_status != LTTNG_CONDITION_STATUS_OK) { + ERR("Could not set session consumed size condition session name (name = %s)", + session->name); + ret = -1; + goto end; + } + + action = lttng_action_notify_create(); + if (!action) { + ERR("Could not create notify action"); + ret = -1; + goto end; + } + + session->rotate_trigger = lttng_trigger_create(session->rotate_condition, + action); + if (!session->rotate_trigger) { + ERR("Could not create size-based rotation trigger"); + ret = -1; + goto end; + } + + nc_status = lttng_notification_channel_subscribe( + rotate_notification_channel, session->rotate_condition); + if (nc_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { + ERR("Could not subscribe to session consumed size notification"); + ret = -1; + goto end; + } + + ret = notification_thread_command_register_trigger( + notification_thread_handle, session->rotate_trigger); + if (ret < 0 && ret != -LTTNG_ERR_TRIGGER_EXISTS) { + ERR("Register trigger, %s", lttng_strerror(ret)); + ret = -1; + goto end; + } + + ret = 0; + +end: + return ret; +} + +int unsubscribe_session_consumed_size_rotation(struct ltt_session *session, + struct notification_thread_handle *notification_thread_handle) +{ + int ret = 0; + enum lttng_notification_channel_status status; + + status = lttng_notification_channel_unsubscribe( + rotate_notification_channel, + session->rotate_condition); + if (status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { + ERR("Session unsubscribe error: %d", (int) status); + ret = -1; + goto end; + } + + ret = notification_thread_command_unregister_trigger( + notification_thread_handle, session->rotate_trigger); + if (ret != LTTNG_OK) { + ERR("Session unregister trigger error: %d", ret); + goto end; + } + + ret = 0; end: return ret; }