Cleanup: unused assignation on rotation already pending
[lttng-tools.git] / src / bin / lttng-sessiond / rotation-thread.c
index 2fed39fc75a5051fb1b72d006ac95db528075ad8..01a963c25d45c026119a2300d78780ac82772736 100644 (file)
@@ -42,6 +42,7 @@
 #include "cmd.h"
 #include "session.h"
 #include "sessiond-timer.h"
+#include "notification-thread-commands.h"
 
 #include <urcu.h>
 #include <urcu/list.h>
@@ -261,8 +262,11 @@ error:
 static
 void fini_thread_state(struct rotation_thread_state *state)
 {
+       int ret;
+
        lttng_poll_clean(&state->events);
-       cds_lfht_destroy(channel_pending_rotate_ht, NULL);
+       ret = cds_lfht_destroy(channel_pending_rotate_ht, NULL);
+       assert(!ret);
        if (rotate_notification_channel) {
                lttng_notification_channel_destroy(rotate_notification_channel);
        }
@@ -406,7 +410,23 @@ int handle_channel_rotation_pipe(int fd, uint32_t revents,
                                goto end_unlock_session;
                        }
                } else {
+                       struct lttng_trace_archive_location *location;
+
                        session->rotation_state = LTTNG_ROTATION_STATE_COMPLETED;
+                       /* Ownership of location is transferred. */
+                       location = session_get_trace_archive_location(session);
+                       ret = notification_thread_command_session_rotation_completed(
+                                       notification_thread_handle,
+                                       session->name,
+                                       session->uid,
+                                       session->gid,
+                                       session->current_archive_id,
+                                       location);
+                       if (ret != LTTNG_OK) {
+                               ERR("Failed to notify notification thread that rotation is complete for session %s",
+                                               session->name);
+                       }
+
                }
                DBG("Rotation completed for session %s", session->name);
        }
@@ -433,12 +453,14 @@ int rotate_pending_relay_timer(struct ltt_session *session)
 
        DBG("[rotation-thread] Check rotate pending on session %" PRIu64,
                        session->id);
-       ret = relay_rotate_pending(session, session->rotate_count - 1);
+       ret = relay_rotate_pending(session, session->current_archive_id - 1);
        if (ret < 0) {
                ERR("[rotation-thread] Check relay rotate pending");
                goto end;
        }
        if (ret == 0) {
+               struct lttng_trace_archive_location *location;
+
                DBG("[rotation-thread] Rotation completed on the relay for "
                                "session %" PRIu64, session->id);
                /*
@@ -447,6 +469,21 @@ int rotate_pending_relay_timer(struct ltt_session *session)
                 */
                session->rotate_pending_relay = false;
                session->rotation_state = LTTNG_ROTATION_STATE_COMPLETED;
+
+               session->rotation_state = LTTNG_ROTATION_STATE_COMPLETED;
+               /* Ownership of location is transferred. */
+               location = session_get_trace_archive_location(session);
+               ret = notification_thread_command_session_rotation_completed(
+                               notification_thread_handle,
+                               session->name,
+                               session->uid,
+                               session->gid,
+                               session->current_archive_id,
+                               location);
+               if (ret != LTTNG_OK) {
+                       ERR("Failed to notify notification thread that rotation is complete for session %s",
+                                       session->name);
+               }
        } else if (ret == 1) {
                DBG("[rotation-thread] Rotation still pending on the relay for "
                                "session %" PRIu64, session->id);
@@ -654,7 +691,6 @@ int handle_condition(
        ret = cmd_rotate_session(session, NULL);
        if (ret == -LTTNG_ERR_ROTATION_PENDING) {
                DBG("Rotate already pending, subscribe to the next threshold value");
-               ret = 0;
        } else if (ret != LTTNG_OK) {
                ERR("[rotation-thread] Failed to rotate on size notification with error: %s",
                                lttng_strerror(ret));
@@ -682,11 +718,25 @@ int handle_notification_channel(int fd, uint32_t revents,
                struct rotation_thread_state *state)
 {
        int ret;
-       struct lttng_notification *notification;
+       bool notification_pending;
+       struct lttng_notification *notification = NULL;
        enum lttng_notification_channel_status status;
        const struct lttng_evaluation *notification_evaluation;
        const struct lttng_condition *notification_condition;
 
+       status = lttng_notification_channel_has_pending_notification(
+                       rotate_notification_channel, &notification_pending);
+       if (status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) {
+               ERR("[rotation-thread ]Error occured while checking for pending notification");
+               ret = -1;
+               goto end;
+       }
+
+       if (!notification_pending) {
+               ret = 0;
+               goto end;
+       }
+
        /* Receive the next notification. */
        status = lttng_notification_channel_get_next_notification(
                        rotate_notification_channel,
@@ -718,11 +768,6 @@ int handle_notification_channel(int fd, uint32_t revents,
 
 end:
        lttng_notification_destroy(notification);
-       if (ret != 0) {
-               goto end;
-       }
-
-
        return ret;
 }
 
This page took 0.02576 seconds and 5 git commands to generate.