X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Frotation-thread.c;h=ac149c845b79c9436674908ee9c5b942db79c0d2;hb=d37406195ec30adfb1bd903e3ee8dfdda79700ef;hp=cb06413b64c371e1dd9dc7fc384872530092501e;hpb=be2956e7f73ef08fa3182ae636ba6cd7725fdaaf;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/rotation-thread.c b/src/bin/lttng-sessiond/rotation-thread.c index cb06413b6..ac149c845 100644 --- a/src/bin/lttng-sessiond/rotation-thread.c +++ b/src/bin/lttng-sessiond/rotation-thread.c @@ -1,19 +1,9 @@ /* - * Copyright (C) 2017 - Julien Desfossez - * Copyright (C) 2018 - Jérémie Galarneau + * 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 - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _LGPL_SOURCE @@ -26,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +24,7 @@ #include #include #include +#include #include "rotation-thread.h" #include "lttng-sessiond.h" @@ -111,33 +101,6 @@ end: return queue; } -void log_job_destruction(const struct rotation_thread_job *job) -{ - enum lttng_error_level log_level; - const char *job_type_str = get_job_type_str(job->type); - - switch (job->type) { - case ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION: - /* - * Not a problem, the scheduled rotation is racing with the teardown - * of the daemon. In this case, the rotation will not happen, which - * is not a problem (or at least, not important enough to delay - * the shutdown of the session daemon). - */ - log_level = PRINT_DBG; - break; - case ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION: - /* This is not expected to happen; warn the user. */ - log_level = PRINT_WARN; - break; - default: - abort(); - } - - LOG(log_level, "Rotation thread timer queue still contains job of type %s targeting session \"%s\" on destruction", - job_type_str, job->session->name); -} - void rotation_thread_timer_queue_destroy( struct rotation_thread_timer_queue *queue) { @@ -290,7 +253,7 @@ int init_poll_set(struct lttng_poll_event *poll_set, lttng_pipe_get_readfd(handle->quit_pipe), LPOLLIN | LPOLLERR); if (ret < 0) { - ERR("[rotation-thread] Failed to add quit pipe read fd to poll set"); + ERR("Failed to add quit pipe read fd to poll set"); goto error; } @@ -298,7 +261,7 @@ int init_poll_set(struct lttng_poll_event *poll_set, lttng_pipe_get_readfd(handle->rotation_timer_queue->event_pipe), LPOLLIN | LPOLLERR); if (ret < 0) { - ERR("[rotation-thread] Failed to add rotate_pending fd to poll set"); + ERR("Failed to add rotate_pending fd to poll set"); goto error; } @@ -328,21 +291,21 @@ int init_thread_state(struct rotation_thread_handle *handle, ret = init_poll_set(&state->events, handle); if (ret) { - ERR("[rotation-thread] Failed to initialize rotation thread poll set"); + ERR("Failed to initialize rotation thread poll set"); goto end; } rotate_notification_channel = lttng_notification_channel_create( lttng_session_daemon_notification_endpoint); if (!rotate_notification_channel) { - ERR("[rotation-thread] Could not create notification channel"); + ERR("Could not create notification channel"); ret = -1; goto end; } ret = lttng_poll_add(&state->events, rotate_notification_channel->socket, LPOLLIN | LPOLLERR); if (ret < 0) { - ERR("[rotation-thread] Failed to add notification fd to pollset"); + ERR("Failed to add notification fd to pollset"); goto end; } @@ -385,17 +348,17 @@ void check_session_rotation_pending_on_consumers(struct ltt_session *session, &exists_status); if (ret) { pthread_mutex_unlock(socket->lock); - ERR("Error occured while checking rotation status on consumer daemon"); + ERR("Error occurred while checking rotation status on consumer daemon"); goto end; } - if (exists_status != CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK) { + if (exists_status != CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK) { pthread_mutex_unlock(socket->lock); chunk_exists_on_peer = true; goto end; - } + } pthread_mutex_unlock(socket->lock); - } + } skip_ust: if (!session->kernel_session) { @@ -414,15 +377,15 @@ skip_ust: &exists_status); if (ret) { pthread_mutex_unlock(socket->lock); - ERR("Error occured while checking rotation status on consumer daemon"); + ERR("Error occurred while checking rotation status on consumer daemon"); goto end; } - if (exists_status != CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK) { + if (exists_status != CONSUMER_TRACE_CHUNK_EXISTS_STATUS_UNKNOWN_CHUNK) { pthread_mutex_unlock(socket->lock); chunk_exists_on_peer = true; goto end; - } + } pthread_mutex_unlock(socket->lock); } skip_kernel: @@ -436,7 +399,7 @@ end: session->chunk_being_archived, &chunk_being_archived_id); assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); - DBG("[rotation-thread] Rotation of trace archive %" PRIu64 " of session \"%s\" is complete on all consumers", + DBG("Rotation of trace archive %" PRIu64 " of session \"%s\" is complete on all consumers", chunk_being_archived_id, session->name); } @@ -467,18 +430,18 @@ int check_session_rotation_pending(struct ltt_session *session, const char *archived_chunk_name; uint64_t chunk_being_archived_id; + if (!session->chunk_being_archived) { + ret = 0; + goto end; + } + chunk_status = lttng_trace_chunk_get_id(session->chunk_being_archived, &chunk_being_archived_id); assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); - DBG("[rotation-thread] Checking for pending rotation on session \"%s\", trace archive %" PRIu64, + DBG("Checking for pending rotation on session \"%s\", trace archive %" PRIu64, session->name, chunk_being_archived_id); - if (!session->chunk_being_archived) { - ret = 0; - goto end; - } - /* * The rotation-pending check timer of a session is launched in * one-shot mode. If the rotation is incomplete, the rotation @@ -489,15 +452,14 @@ int check_session_rotation_pending(struct ltt_session *session, */ ret = timer_session_rotation_pending_check_stop(session); if (ret) { - goto end; + goto check_ongoing_rotation; } check_session_rotation_pending_on_consumers(session, &rotation_completed); - if (!rotation_completed || session->rotation_state == LTTNG_ROTATION_STATE_ERROR) { - goto end; + goto check_ongoing_rotation; } /* @@ -514,63 +476,31 @@ int check_session_rotation_pending(struct ltt_session *session, } session_reset_rotation_state(session, LTTNG_ROTATION_STATE_COMPLETED); - location = session_get_trace_archive_location(session); - /* Ownership of location is transferred. */ - ret = notification_thread_command_session_rotation_completed( - notification_thread_handle, - session->name, - session->uid, - session->gid, - session->last_archived_chunk_id.value, - location); - if (ret != LTTNG_OK) { - ERR("[rotation-thread] Failed to notify notification thread of completed rotation for session %s", - session->name); - } - - if (!session->active) { - /* - * A stop command was issued during the rotation, it is - * up to the rotation completion check to perform the - * renaming of the last chunk that was produced. - */ - ret = notification_thread_command_session_rotation_ongoing( - notification_thread_handle, - session->name, - session->uid, - session->gid, - session->most_recent_chunk_id.value); - if (ret != LTTNG_OK) { - ERR("[rotation-thread] Failed to notify notification thread of completed rotation for session %s", - session->name); - } - - /* Ownership of location is transferred. */ + if (!session->quiet_rotation) { location = session_get_trace_archive_location(session); ret = notification_thread_command_session_rotation_completed( notification_thread_handle, session->name, session->uid, session->gid, - session->most_recent_chunk_id.value, + session->last_archived_chunk_id.value, location); + lttng_trace_archive_location_put(location); if (ret != LTTNG_OK) { - ERR("[rotation-thread] Failed to notify notification thread of completed rotation for session %s", + ERR("Failed to notify notification thread of completed rotation for session %s", session->name); } } ret = 0; -end: +check_ongoing_rotation: if (session->rotation_state == LTTNG_ROTATION_STATE_ONGOING) { - uint64_t chunk_being_archived_id; - chunk_status = lttng_trace_chunk_get_id( session->chunk_being_archived, &chunk_being_archived_id); assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK); - DBG("[rotation-thread] Rotation of trace archive %" PRIu64 " is still pending for session %s", + DBG("Rotation of trace archive %" PRIu64 " is still pending for session %s", chunk_being_archived_id, session->name); ret = timer_session_rotation_pending_check_start(session, DEFAULT_ROTATE_PENDING_TIMER); @@ -581,6 +511,7 @@ end: } } +end: return ret; } @@ -591,16 +522,17 @@ int launch_session_rotation(struct ltt_session *session) int ret; struct lttng_rotate_session_return rotation_return; - DBG("[rotation-thread] Launching scheduled time-based rotation on session \"%s\"", + DBG("Launching scheduled time-based rotation on session \"%s\"", session->name); - ret = cmd_rotate_session(session, &rotation_return); + ret = cmd_rotate_session(session, &rotation_return, false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); if (ret == LTTNG_OK) { - DBG("[rotation-thread] Scheduled time-based rotation successfully launched on session \"%s\"", + DBG("Scheduled time-based rotation successfully launched on session \"%s\"", session->name); } else { /* Don't consider errors as fatal. */ - DBG("[rotation-thread] Scheduled time-based rotation aborted for session %s: %s", + DBG("Scheduled time-based rotation aborted for session %s: %s", session->name, lttng_strerror(ret)); } return 0; @@ -614,7 +546,7 @@ int run_job(struct rotation_thread_job *job, struct ltt_session *session, switch (job->type) { case ROTATION_THREAD_JOB_TYPE_SCHEDULED_ROTATION: - ret = launch_session_rotation(session); + ret = launch_session_rotation(session); break; case ROTATION_THREAD_JOB_TYPE_CHECK_PENDING_ROTATION: ret = check_session_rotation_pending(session, @@ -651,7 +583,7 @@ int handle_job_queue(struct rotation_thread_handle *handle, session_lock_list(); session = job->session; if (!session) { - DBG("[rotation-thread] Session \"%s\" not found", + DBG("Session \"%s\" not found", session->name); /* * This is a non-fatal error, and we cannot report it to @@ -670,7 +602,7 @@ int handle_job_queue(struct rotation_thread_handle *handle, } session_lock(session); - ret = run_job(job, session, handle->notification_thread_handle); + ret = run_job(job, session, handle->notification_thread_handle); session_unlock(session); /* Release reference held by the job. */ session_put(session); @@ -704,7 +636,7 @@ int handle_condition(const struct lttng_condition *condition, if (condition_type != LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE) { ret = -1; - ERR("[rotation-thread] Condition type and session usage type are not the same"); + ERR("Condition type and session usage type are not the same"); goto end; } @@ -712,14 +644,14 @@ int handle_condition(const struct lttng_condition *condition, condition_status = lttng_condition_session_consumed_size_get_session_name( condition, &condition_session_name); if (condition_status != LTTNG_CONDITION_STATUS_OK) { - ERR("[rotation-thread] Session name could not be fetched"); + ERR("Session name could not be fetched"); ret = -1; goto end; } evaluation_status = lttng_evaluation_session_consumed_size_get_consumed_size(evaluation, &consumed); if (evaluation_status != LTTNG_EVALUATION_STATUS_OK) { - ERR("[rotation-thread] Failed to get evaluation"); + ERR("Failed to get evaluation"); ret = -1; goto end; } @@ -729,7 +661,7 @@ int handle_condition(const struct lttng_condition *condition, if (!session) { ret = -1; session_unlock_list(); - ERR("[rotation-thread] Session \"%s\" not found", + ERR("Session \"%s\" not found", condition_session_name); goto end; } @@ -741,11 +673,12 @@ int handle_condition(const struct lttng_condition *condition, goto end_unlock; } - ret = cmd_rotate_session(session, NULL); + ret = cmd_rotate_session(session, NULL, false, + LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED); if (ret == -LTTNG_ERR_ROTATION_PENDING) { DBG("Rotate already pending, subscribe to the next threshold value"); } else if (ret != LTTNG_OK) { - ERR("[rotation-thread] Failed to rotate on size notification with error: %s", + ERR("Failed to rotate on size notification with error: %s", lttng_strerror(ret)); ret = -1; goto end_unlock; @@ -754,7 +687,7 @@ int handle_condition(const struct lttng_condition *condition, consumed + session->rotate_size, notification_thread_handle); if (ret) { - ERR("[rotation-thread] Failed to subscribe to session consumed size condition"); + ERR("Failed to subscribe to session consumed size condition"); goto end_unlock; } ret = 0; @@ -782,7 +715,7 @@ int handle_notification_channel(int fd, status = lttng_notification_channel_has_pending_notification( rotate_notification_channel, ¬ification_pending); if (status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { - ERR("[rotation-thread ]Error occurred while checking for pending notification"); + ERR("Error occurred while checking for pending notification"); ret = -1; goto end; } @@ -826,26 +759,28 @@ end: return ret; } +static void *thread_rotation(void *data) { int ret; struct rotation_thread_handle *handle = data; struct rotation_thread thread; - const int queue_pipe_fd = lttng_pipe_get_readfd( - handle->rotation_timer_queue->event_pipe); + int queue_pipe_fd; - DBG("[rotation-thread] Started rotation thread"); + DBG("Started rotation thread"); + rcu_register_thread(); + rcu_thread_online(); + health_register(the_health_sessiond, HEALTH_SESSIOND_TYPE_ROTATION); + health_code_update(); if (!handle) { - ERR("[rotation-thread] Invalid thread context provided"); + ERR("Invalid thread context provided"); goto end; } - rcu_register_thread(); - rcu_thread_online(); + queue_pipe_fd = lttng_pipe_get_readfd( + handle->rotation_timer_queue->event_pipe); - health_register(health_sessiond, HEALTH_SESSIOND_TYPE_ROTATION); - health_code_update(); ret = init_thread_state(handle, &thread); if (ret) { @@ -856,9 +791,9 @@ void *thread_rotation(void *data) int fd_count, i; health_poll_entry(); - DBG("[rotation-thread] Entering poll wait"); + DBG("Entering poll wait"); ret = lttng_poll_wait(&thread.events, -1); - DBG("[rotation-thread] Poll wait returned (%i)", ret); + DBG("Poll wait returned (%i)", ret); health_poll_exit(); if (ret < 0) { /* @@ -867,7 +802,7 @@ void *thread_rotation(void *data) if (errno == EINTR) { continue; } - ERR("[rotation-thread] Error encountered during lttng_poll_wait (%i)", ret); + ERR("Error encountered during lttng_poll_wait (%i)", ret); goto error; } @@ -876,11 +811,11 @@ void *thread_rotation(void *data) int fd = LTTNG_POLL_GETFD(&thread.events, i); uint32_t revents = LTTNG_POLL_GETEV(&thread.events, i); - DBG("[rotation-thread] Handling fd (%i) activity (%u)", + DBG("Handling fd (%i) activity (%u)", fd, revents); if (revents & LPOLLERR) { - ERR("[rotation-thread] Polling returned an error on fd %i", fd); + ERR("Polling returned an error on fd %i", fd); goto error; } @@ -888,7 +823,7 @@ void *thread_rotation(void *data) ret = handle_notification_channel(fd, handle, &thread); if (ret) { - ERR("[rotation-thread] Error occurred while handling activity on notification channel socket"); + ERR("Error occurred while handling activity on notification channel socket"); goto error; } } else { @@ -903,7 +838,7 @@ void *thread_rotation(void *data) ret = handle_job_queue(handle, &thread, handle->rotation_timer_queue); if (ret) { - ERR("[rotation-thread] Failed to handle rotation timer pipe event"); + ERR("Failed to handle rotation timer pipe event"); goto error; } @@ -912,12 +847,11 @@ void *thread_rotation(void *data) ret = lttng_read(fd, &buf, 1); if (ret != 1) { - ERR("[rotation-thread] Failed to read from wakeup pipe (fd = %i)", fd); - ret = -1; + ERR("Failed to read from wakeup pipe (fd = %i)", fd); goto error; } } else { - DBG("[rotation-thread] Quit pipe activity"); + DBG("Quit pipe activity"); goto exit; } } @@ -925,12 +859,12 @@ void *thread_rotation(void *data) } exit: error: - DBG("[rotation-thread] Exit"); + DBG("Thread exit"); fini_thread_state(&thread); - health_unregister(health_sessiond); +end: + health_unregister(the_health_sessiond); rcu_thread_offline(); rcu_unregister_thread(); -end: return NULL; }