X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Frotate.c;h=c3413a2cab7b2e0d89ae2853a9773447de87572c;hp=bd6dbddf95492492eb02a5dd87d138cfffe6c108;hb=3b33e9e731f2091e8aa13ea035c295ed6f101eac;hpb=90936dcf0968343f20b2f6fd365b9c015cdb9717 diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.c index bd6dbddf9..c3413a2ca 100644 --- a/src/bin/lttng-sessiond/rotate.c +++ b/src/bin/lttng-sessiond/rotate.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2017 - Julien Desfossez + * Copyright (C) 2018 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -48,44 +49,6 @@ #include #include -unsigned long hash_channel_key(struct rotation_channel_key *key) -{ - return hash_key_u64(&key->key, lttng_ht_seed) ^ hash_key_ulong( - (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, @@ -208,7 +171,7 @@ error: * * Returns 0 on success, a negative value on error. */ -int rename_complete_chunk(struct ltt_session *session, time_t ts) +int rename_completed_chunk(struct ltt_session *session, time_t ts) { struct tm *timeinfo; char new_path[LTTNG_PATH_MAX]; @@ -232,7 +195,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) goto end; } - if (session->rotate_count == 1) { + if (session->current_archive_id == 1) { char start_time[21]; timeinfo = localtime(&session->last_chunk_start_ts); @@ -255,10 +218,10 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) * session_root_path, so we need to create the chunk folder * and move the domain-specific folders inside it. */ - ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64, + ret = snprintf(new_path, sizeof(new_path), "%s/archives/%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); @@ -312,10 +275,10 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = -1; goto end; } - ret = snprintf(new_path, sizeof(new_path), "%s/%s-%s-%" PRIu64, + ret = snprintf(new_path, sizeof(new_path), "%s/archives/%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); @@ -357,50 +320,44 @@ end: return ret; } -int relay_rotate_pending(struct ltt_session *session, uint64_t chunk_id) +int rename_active_chunk(struct ltt_session *session) { int ret; - struct consumer_socket *socket; - struct consumer_output *output; - struct lttng_ht_iter iter; + + session->current_archive_id++; /* - * Either one of the sessions is enough to find the consumer_output - * and uid/gid. + * The currently active tracing path is now the folder we + * want to rename. */ - if (session->kernel_session) { - output = session->kernel_session->consumer; - } else if (session->ust_session) { - output = session->ust_session->consumer; - } else { - assert(0); + ret = lttng_strncpy(session->rotation_chunk.current_rotate_path, + session->rotation_chunk.active_tracing_path, + sizeof(session->rotation_chunk.current_rotate_path)); + if (ret) { + ERR("Failed to copy active tracing path"); + goto end; } - if (!output || !output->socks) { - ERR("No consumer output found"); - ret = -1; + ret = rename_completed_chunk(session, time(NULL)); + if (ret < 0) { + ERR("Failed to rename current rotation's path"); 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. + * We just renamed, the folder, we didn't do an actual rotation, so + * the active tracing path is now the renamed folder and we have to + * restore the rotate count. */ - 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; + ret = lttng_strncpy(session->rotation_chunk.active_tracing_path, + session->rotation_chunk.current_rotate_path, + sizeof(session->rotation_chunk.active_tracing_path)); + if (ret) { + ERR("Failed to rename active session chunk tracing path"); + goto end; } - rcu_read_unlock(); - end: + session->current_archive_id--; return ret; }