Reference count ltt_session objects
[lttng-tools.git] / src / bin / lttng-sessiond / rotation-thread.c
index 59b7123575eca788add644885a3282acd2719ed3..a9f9967a3b49ee04d3fab5beba7b3d27c268c627 100644 (file)
@@ -72,7 +72,6 @@ struct rotation_thread_timer_queue {
 };
 
 struct rotation_thread_handle {
-       int quit_pipe;
        struct rotation_thread_timer_queue *rotation_timer_queue;
        /* Access to the notification thread cmd_queue */
        struct notification_thread_handle *notification_thread_handle;
@@ -169,7 +168,6 @@ void rotation_thread_handle_destroy(
 }
 
 struct rotation_thread_handle *rotation_thread_handle_create(
-               int quit_pipe,
                struct rotation_thread_timer_queue *rotation_timer_queue,
                struct notification_thread_handle *notification_thread_handle,
                sem_t *notification_thread_ready)
@@ -181,7 +179,6 @@ struct rotation_thread_handle *rotation_thread_handle_create(
                goto end;
        }
 
-       handle->quit_pipe = quit_pipe;
        handle->rotation_timer_queue = rotation_timer_queue;
        handle->notification_thread_handle = notification_thread_handle;
        handle->notification_thread_ready = notification_thread_ready;
@@ -276,15 +273,8 @@ int init_poll_set(struct lttng_poll_event *poll_set,
         *      - quit pipe,
         *      - rotation thread timer queue pipe,
         */
-       ret = lttng_poll_create(poll_set, 2, LTTNG_CLOEXEC);
-       if (ret < 0) {
-               goto end;
-       }
-
-       ret = lttng_poll_add(poll_set, handle->quit_pipe,
-                       LPOLLIN | LPOLLERR);
-       if (ret < 0) {
-               ERR("[rotation-thread] Failed to add quit_pipe fd to pollset");
+       ret = sessiond_set_thread_pollset(poll_set, 2);
+       if (ret) {
                goto error;
        }
        ret = lttng_poll_add(poll_set,
@@ -295,7 +285,6 @@ int init_poll_set(struct lttng_poll_event *poll_set,
                goto error;
        }
 
-end:
        return ret;
 error:
        lttng_poll_clean(poll_set);
@@ -442,7 +431,12 @@ end:
                session->rotation_pending_local = false;
        }
        if (ret) {
-               session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+               ret = session_reset_rotation_state(session,
+                               LTTNG_ROTATION_STATE_ERROR);
+               if (ret) {
+                       ERR("Failed to reset rotation state of session \"%s\"",
+                                       session->name);
+               }
        }
        return 0;
 }
@@ -502,14 +496,19 @@ int check_session_rotation_pending_relay(struct ltt_session *session)
                ERR("[rotation-thread] Encountered an error when checking if rotation of trace archive %" PRIu64 " of session \"%s\" is pending on the relay",
                                session->current_archive_id - 1,
                                session->name);
-               session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+               ret = session_reset_rotation_state(session,
+                               LTTNG_ROTATION_STATE_ERROR);
+               if (ret) {
+                       ERR("Failed to reset rotation state of session \"%s\"",
+                                       session->name);
+               }
                rotation_completed = false;
        }
 
        rcu_read_unlock();
 
        if (rotation_completed) {
-               DBG("[rotation-thread] Totation of trace archive %" PRIu64 " of session \"%s\" is complete on the relay",
+               DBG("[rotation-thread] Rotation of trace archive %" PRIu64 " of session \"%s\" is complete on the relay",
                                session->current_archive_id - 1,
                                session->name);
                session->rotation_pending_relay = false;
@@ -566,7 +565,12 @@ int check_session_rotation_pending(struct ltt_session *session,
        /* Rename the completed trace archive's location. */
        now = time(NULL);
        if (now == (time_t) -1) {
-               session->rotation_state = LTTNG_ROTATION_STATE_ERROR;
+               ret = session_reset_rotation_state(session,
+                               LTTNG_ROTATION_STATE_ERROR);
+               if (ret) {
+                       ERR("Failed to reset rotation state of session \"%s\"",
+                                       session->name);
+               }
                ret = LTTNG_ERR_UNK;
                goto end;
        }
@@ -653,7 +657,7 @@ end:
        return ret;
 }
 
-/* Call with the session lock held. */
+/* Call with the session and session_list locks held. */
 static
 int launch_session_rotation(struct ltt_session *session)
 {
@@ -702,7 +706,6 @@ int handle_job_queue(struct rotation_thread_handle *handle,
 {
        int ret = 0;
        int fd = lttng_pipe_get_readfd(queue->event_pipe);
-       struct ltt_session *session;
        char buf;
 
        ret = lttng_read(fd, &buf, 1);
@@ -713,6 +716,7 @@ int handle_job_queue(struct rotation_thread_handle *handle,
        }
 
        for (;;) {
+               struct ltt_session *session;
                struct rotation_thread_job *job;
 
                /* Take the queue lock only to pop an element from the list. */
@@ -743,14 +747,15 @@ int handle_job_queue(struct rotation_thread_handle *handle,
                         */
                        session_unlock_list();
                        free(job);
+                       session_put(session);
                        continue;
                }
 
                session_lock(session);
-               session_unlock_list();
-
                ret = run_job(job, session, handle->notification_thread_handle);
                session_unlock(session);
+               session_put(session);
+               session_unlock_list();
                free(job);
                if (ret) {
                        goto end;
@@ -815,7 +820,7 @@ int handle_condition(const struct lttng_condition *condition,
        ret = unsubscribe_session_consumed_size_rotation(session,
                        notification_thread_handle);
        if (ret) {
-               goto end;
+               goto end_unlock;
        }
 
        ret = cmd_rotate_session(session, NULL);
@@ -838,6 +843,7 @@ int handle_condition(const struct lttng_condition *condition,
 
 end_unlock:
        session_unlock(session);
+       session_put(session);
 end:
        return ret;
 }
@@ -857,7 +863,7 @@ int handle_notification_channel(int fd,
        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");
+               ERR("[rotation-thread ]Error occurred while checking for pending notification");
                ret = -1;
                goto end;
        }
@@ -922,7 +928,7 @@ void *thread_rotation(void *data)
 
        ret = init_thread_state(handle, &thread);
        if (ret) {
-               goto end;
+               goto error;
        }
 
        /* Ready to handle client connections. */
@@ -960,7 +966,7 @@ void *thread_rotation(void *data)
                                goto error;
                        }
 
-                       if (fd == handle->quit_pipe) {
+                       if (sessiond_check_thread_quit_pipe(fd, revents)) {
                                DBG("[rotation-thread] Quit pipe activity");
                                /* TODO flush the queue. */
                                goto exit;
@@ -975,7 +981,7 @@ void *thread_rotation(void *data)
                                ret = handle_notification_channel(fd, handle,
                                                &thread);
                                if (ret) {
-                                       ERR("[rotation-thread] Error occured while handling activity on notification channel socket");
+                                       ERR("[rotation-thread] Error occurred while handling activity on notification channel socket");
                                        goto error;
                                }
                        }
This page took 0.02649 seconds and 4 git commands to generate.