dm vdo thread-utils: push uds_*_cond interface down to indexer
authorMike Snitzer <snitzer@kernel.org>
Fri, 9 Feb 2024 19:06:00 +0000 (13:06 -0600)
committerMike Snitzer <snitzer@kernel.org>
Fri, 1 Mar 2024 14:25:58 +0000 (09:25 -0500)
Only used by indexer components. Also return void from
uds_init_cond(), remove uds_destroy_cond(), and fix up
all callers.

Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Matthew Sakai <msakai@redhat.com>
drivers/md/dm-vdo/index-session.c
drivers/md/dm-vdo/index.c
drivers/md/dm-vdo/indexer.h
drivers/md/dm-vdo/thread-utils.c
drivers/md/dm-vdo/thread-utils.h
drivers/md/dm-vdo/volume.c

index 7afc197487121f72043d84a274d8f5e38cee3fa7..4837621c16dbc40c21fdf921f0450c4e156c5a41 100644 (file)
@@ -230,36 +230,21 @@ static int __must_check make_empty_index_session(struct uds_index_session **inde
                return result;
        }
 
-       result = uds_init_cond(&session->request_cond);
-       if (result != UDS_SUCCESS) {
-               uds_destroy_mutex(&session->request_mutex);
-               uds_free(session);
-               return result;
-       }
+       uds_init_cond(&session->request_cond);
 
        result = uds_init_mutex(&session->load_context.mutex);
        if (result != UDS_SUCCESS) {
-               uds_destroy_cond(&session->request_cond);
                uds_destroy_mutex(&session->request_mutex);
                uds_free(session);
                return result;
        }
 
-       result = uds_init_cond(&session->load_context.cond);
-       if (result != UDS_SUCCESS) {
-               uds_destroy_mutex(&session->load_context.mutex);
-               uds_destroy_cond(&session->request_cond);
-               uds_destroy_mutex(&session->request_mutex);
-               uds_free(session);
-               return result;
-       }
+       uds_init_cond(&session->load_context.cond);
 
        result = uds_make_request_queue("callbackW", &handle_callbacks,
                                        &session->callback_queue);
        if (result != UDS_SUCCESS) {
-               uds_destroy_cond(&session->load_context.cond);
                uds_destroy_mutex(&session->load_context.mutex);
-               uds_destroy_cond(&session->request_cond);
                uds_destroy_mutex(&session->request_mutex);
                uds_free(session);
                return result;
@@ -700,9 +685,7 @@ int uds_destroy_index_session(struct uds_index_session *index_session)
        result = save_and_free_index(index_session);
        uds_request_queue_finish(index_session->callback_queue);
        index_session->callback_queue = NULL;
-       uds_destroy_cond(&index_session->load_context.cond);
        uds_destroy_mutex(&index_session->load_context.mutex);
-       uds_destroy_cond(&index_session->request_cond);
        uds_destroy_mutex(&index_session->request_mutex);
        uds_log_debug("Destroyed index session");
        uds_free(index_session);
@@ -758,3 +741,14 @@ int uds_get_index_session_stats(struct uds_index_session *index_session,
 
        return UDS_SUCCESS;
 }
+
+void uds_wait_cond(struct cond_var *cv, struct mutex *mutex)
+{
+       DEFINE_WAIT(__wait);
+
+       prepare_to_wait(&cv->wait_queue, &__wait, TASK_IDLE);
+       uds_unlock_mutex(mutex);
+       schedule();
+       finish_wait(&cv->wait_queue, &__wait);
+       uds_lock_mutex(mutex);
+}
index 1596f6ba43a5a2706d0718d49986f774c77fc39e..edd81f03c2b5978c2441963653581ad960628d05 100644 (file)
@@ -754,7 +754,6 @@ static void free_chapter_writer(struct chapter_writer *writer)
 
        stop_chapter_writer(writer);
        uds_destroy_mutex(&writer->mutex);
-       uds_destroy_cond(&writer->cond);
        uds_free_open_chapter_index(writer->open_chapter_index);
        uds_free(writer->collated_records);
        uds_free(writer);
@@ -781,12 +780,7 @@ static int make_chapter_writer(struct uds_index *index,
                return result;
        }
 
-       result = uds_init_cond(&writer->cond);
-       if (result != UDS_SUCCESS) {
-               uds_destroy_mutex(&writer->mutex);
-               uds_free(writer);
-               return result;
-       }
+       uds_init_cond(&writer->cond);
 
        result = uds_allocate_cache_aligned(collated_records_size, "collated records",
                                            &writer->collated_records);
index 59e6a5ca2acb3d54ccbf0bd218df6f6f6eb1c7f8..3744aaf625b05108e6a85cd4c32191c69509ebff 100644 (file)
@@ -6,7 +6,10 @@
 #ifndef INDEXER_H
 #define INDEXER_H
 
+#include <linux/mutex.h>
+#include <linux/sched.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 
 #include "funnel-queue.h"
 
@@ -326,4 +329,25 @@ int __must_check uds_get_index_session_stats(struct uds_index_session *session,
 /* This function will fail if any required field of the request is not set. */
 int __must_check uds_launch_request(struct uds_request *request);
 
+struct cond_var {
+       wait_queue_head_t wait_queue;
+};
+
+static inline void uds_init_cond(struct cond_var *cv)
+{
+       init_waitqueue_head(&cv->wait_queue);
+}
+
+static inline void uds_signal_cond(struct cond_var *cv)
+{
+       wake_up(&cv->wait_queue);
+}
+
+static inline void uds_broadcast_cond(struct cond_var *cv)
+{
+       wake_up_all(&cv->wait_queue);
+}
+
+void uds_wait_cond(struct cond_var *cv, struct mutex *mutex);
+
 #endif /* INDEXER_H */
index 5d371bfba8ff4e73193e31c5b67390a614fd2338..30760b1c4d30e74558636b8b060f8848a873dcc1 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/kthread.h>
-#include <linux/sched.h>
 
 #include "errors.h"
 #include "logger.h"
@@ -135,14 +134,3 @@ int uds_join_threads(struct thread *thread)
        uds_free(thread);
        return UDS_SUCCESS;
 }
-
-void uds_wait_cond(struct cond_var *cv, struct mutex *mutex)
-{
-       DEFINE_WAIT(__wait);
-
-       prepare_to_wait(&cv->wait_queue, &__wait, TASK_IDLE);
-       uds_unlock_mutex(mutex);
-       schedule();
-       finish_wait(&cv->wait_queue, &__wait);
-       uds_lock_mutex(mutex);
-}
index c7a5d2d948a4f6303ac3868d362c4fef2a5dd8e0..fb71f8f1b46e8b4a2a773ff36f39489af8acc78a 100644 (file)
 #include <linux/jiffies.h>
 #include <linux/mutex.h>
 #include <linux/semaphore.h>
-#include <linux/wait.h>
 
 #include "errors.h"
 
 /* Thread and synchronization utilities for UDS */
 
-struct cond_var {
-       wait_queue_head_t wait_queue;
-};
-
 struct thread;
 
 
@@ -31,30 +26,8 @@ void uds_perform_once(atomic_t *once_state, void (*function) (void));
 
 int uds_join_threads(struct thread *thread);
 
-static inline int __must_check uds_init_cond(struct cond_var *cv)
-{
-       init_waitqueue_head(&cv->wait_queue);
-       return UDS_SUCCESS;
-}
-
-static inline void uds_signal_cond(struct cond_var *cv)
-{
-       wake_up(&cv->wait_queue);
-}
-
-static inline void uds_broadcast_cond(struct cond_var *cv)
-{
-       wake_up_all(&cv->wait_queue);
-}
-
-void uds_wait_cond(struct cond_var *cv, struct mutex *mutex);
-
 /* FIXME: all below wrappers should be removed! */
 
-static inline void uds_destroy_cond(struct cond_var *cv)
-{
-}
-
 static inline int __must_check uds_init_mutex(struct mutex *mutex)
 {
        mutex_init(mutex);
@@ -76,5 +49,4 @@ static inline void uds_unlock_mutex(struct mutex *mutex)
        mutex_unlock(mutex);
 }
 
-
 #endif /* UDS_THREADS_H */
index 5b3cb5d89e47ec7b40c458c59ac8eb28aa6546ee..3b256a78fb0228a82d8601e3c46ed658db542e9d 100644 (file)
@@ -1627,17 +1627,8 @@ int uds_make_volume(const struct uds_configuration *config, struct index_layout
                return result;
        }
 
-       result = uds_init_cond(&volume->read_threads_read_done_cond);
-       if (result != UDS_SUCCESS) {
-               uds_free_volume(volume);
-               return result;
-       }
-
-       result = uds_init_cond(&volume->read_threads_cond);
-       if (result != UDS_SUCCESS) {
-               uds_free_volume(volume);
-               return result;
-       }
+       uds_init_cond(&volume->read_threads_read_done_cond);
+       uds_init_cond(&volume->read_threads_cond);
 
        result = uds_allocate(config->read_threads, struct thread *, "reader threads",
                              &volume->reader_threads);
@@ -1700,8 +1691,6 @@ void uds_free_volume(struct volume *volume)
        if (volume->client != NULL)
                dm_bufio_client_destroy(uds_forget(volume->client));
 
-       uds_destroy_cond(&volume->read_threads_cond);
-       uds_destroy_cond(&volume->read_threads_read_done_cond);
        uds_destroy_mutex(&volume->read_threads_mutex);
        uds_free_index_page_map(volume->index_page_map);
        uds_free_radix_sorter(volume->radix_sorter);