dm vdo: remove vdo_perform_once
authorMatthew Sakai <msakai@redhat.com>
Fri, 1 Mar 2024 23:29:05 +0000 (18:29 -0500)
committerMike Snitzer <snitzer@kernel.org>
Tue, 5 Mar 2024 04:11:11 +0000 (23:11 -0500)
Remove obsolete function vdo_perform_once. Instead, initialize
necessary module state when loading the module.

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

index b7b3eec39522e6d44ee4fe86c6e607e329d05123..9128e6cd084437588f1f688f12650657c25956de 100644 (file)
@@ -34,6 +34,7 @@
 #include "string-utils.h"
 #include "thread-device.h"
 #include "thread-registry.h"
+#include "thread-utils.h"
 #include "types.h"
 #include "vdo.h"
 #include "vio.h"
@@ -2872,6 +2873,7 @@ static int __init vdo_init(void)
 
        /* Memory tracking must be initialized first for accurate accounting. */
        vdo_memory_init();
+       vdo_initialize_threads_mutex();
        vdo_initialize_thread_device_registry();
        vdo_initialize_device_registry_once();
        vdo_log_info("loaded version %s", CURRENT_VERSION);
index 918e46e7121fa40268fdad4a0534ad18b8c149ad..d3493450b1696baaae5c048a67c380a2117fabab 100644 (file)
@@ -40,10 +40,11 @@ const struct error_info vdo_status_list[] = {
        { "VDO_INVALID_ADMIN_STATE", "Invalid operation for current state" },
 };
 
-static atomic_t vdo_status_codes_registered = ATOMIC_INIT(0);
-static int status_code_registration_result;
-
-static void do_status_code_registration(void)
+/**
+ * vdo_register_status_codes() - Register the VDO status codes.
+ * Return: A success or error code.
+ */
+int vdo_register_status_codes(void)
 {
        int result;
 
@@ -53,26 +54,7 @@ static void do_status_code_registration(void)
        result = uds_register_error_block("VDO Status", VDO_STATUS_CODE_BASE,
                                          VDO_STATUS_CODE_BLOCK_END, vdo_status_list,
                                          sizeof(vdo_status_list));
-       /*
-        * The following test handles cases where libvdo is statically linked against both the test
-        * modules and the test driver (because multiple instances of this module call their own
-        * copy of this function once each, resulting in multiple calls to register_error_block
-        * which is shared in libuds).
-        */
-       if (result == UDS_DUPLICATE_NAME)
-               result = UDS_SUCCESS;
-
-       status_code_registration_result = (result == UDS_SUCCESS) ? VDO_SUCCESS : result;
-}
-
-/**
- * vdo_register_status_codes() - Register the VDO status codes if needed.
- * Return: A success or error code.
- */
-int vdo_register_status_codes(void)
-{
-       vdo_perform_once(&vdo_status_codes_registered, do_status_code_registration);
-       return status_code_registration_result;
+       return (result == UDS_SUCCESS) ? VDO_SUCCESS : result;
 }
 
 /**
index bd620be61c1d1116c5caa757678ebfdca6670e50..ec08478dd01397cdc0e159fc3b49c9bf6a88e0a7 100644 (file)
@@ -17,7 +17,6 @@
 
 static struct hlist_head thread_list;
 static struct mutex thread_mutex;
-static atomic_t thread_once = ATOMIC_INIT(0);
 
 struct thread {
        void (*thread_function)(void *thread_data);
@@ -27,31 +26,7 @@ struct thread {
        struct completion thread_done;
 };
 
-#define ONCE_NOT_DONE 0
-#define ONCE_IN_PROGRESS 1
-#define ONCE_COMPLETE 2
-
-/* Run a function once only, and record that fact in the atomic value. */
-void vdo_perform_once(atomic_t *once, void (*function)(void))
-{
-       for (;;) {
-               switch (atomic_cmpxchg(once, ONCE_NOT_DONE, ONCE_IN_PROGRESS)) {
-               case ONCE_NOT_DONE:
-                       function();
-                       atomic_set_release(once, ONCE_COMPLETE);
-                       return;
-               case ONCE_IN_PROGRESS:
-                       cond_resched();
-                       break;
-               case ONCE_COMPLETE:
-                       return;
-               default:
-                       return;
-               }
-       }
-}
-
-static void thread_init(void)
+void vdo_initialize_threads_mutex(void)
 {
        mutex_init(&thread_mutex);
 }
@@ -62,7 +37,6 @@ static int thread_starter(void *arg)
        struct thread *thread = arg;
 
        thread->thread_task = current;
-       vdo_perform_once(&thread_once, thread_init);
        mutex_lock(&thread_mutex);
        hlist_add_head(&thread->thread_links, &thread_list);
        mutex_unlock(&thread_mutex);
index f3619a581c5e0ecb7eb09a50e3ba74a0aa28087d..687ab43e2cee45a600a1aab4c98f9b98e6d66dfc 100644 (file)
 
 struct thread;
 
-
+void vdo_initialize_threads_mutex(void);
 int __must_check vdo_create_thread(void (*thread_function)(void *), void *thread_data,
                                   const char *name, struct thread **new_thread);
 void vdo_join_threads(struct thread *thread);
 
-void vdo_perform_once(atomic_t *once_state, void (*function) (void));
-
 #endif /* UDS_THREADS_H */