From 2d3b51af269ff833a225de75de8eb6fe72422cdf Mon Sep 17 00:00:00 2001 From: Matthew Sakai Date: Fri, 1 Mar 2024 18:29:05 -0500 Subject: [PATCH 1/3] dm vdo: remove vdo_perform_once Remove obsolete function vdo_perform_once. Instead, initialize necessary module state when loading the module. Signed-off-by: Matthew Sakai --- drivers/md/dm-vdo/dm-vdo-target.c | 2 ++ drivers/md/dm-vdo/status-codes.c | 30 ++++++------------------------ drivers/md/dm-vdo/thread-utils.c | 28 +--------------------------- drivers/md/dm-vdo/thread-utils.h | 4 +--- 4 files changed, 10 insertions(+), 54 deletions(-) diff --git a/drivers/md/dm-vdo/dm-vdo-target.c b/drivers/md/dm-vdo/dm-vdo-target.c index b7b3eec39522e..9128e6cd08443 100644 --- a/drivers/md/dm-vdo/dm-vdo-target.c +++ b/drivers/md/dm-vdo/dm-vdo-target.c @@ -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); diff --git a/drivers/md/dm-vdo/status-codes.c b/drivers/md/dm-vdo/status-codes.c index 918e46e7121fa..d3493450b1696 100644 --- a/drivers/md/dm-vdo/status-codes.c +++ b/drivers/md/dm-vdo/status-codes.c @@ -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; } /** diff --git a/drivers/md/dm-vdo/thread-utils.c b/drivers/md/dm-vdo/thread-utils.c index bd620be61c1d1..ec08478dd0139 100644 --- a/drivers/md/dm-vdo/thread-utils.c +++ b/drivers/md/dm-vdo/thread-utils.c @@ -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); diff --git a/drivers/md/dm-vdo/thread-utils.h b/drivers/md/dm-vdo/thread-utils.h index f3619a581c5e0..687ab43e2cee4 100644 --- a/drivers/md/dm-vdo/thread-utils.h +++ b/drivers/md/dm-vdo/thread-utils.h @@ -12,11 +12,9 @@ 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 */ From fefa53570975cfec742aefa656717ca569342ef1 Mon Sep 17 00:00:00 2001 From: Matthew Sakai Date: Fri, 1 Mar 2024 18:19:40 -0500 Subject: [PATCH 2/3] dm vdo: remove meaningless version number constant Also remove related log messages. Signed-off-by: Matthew Sakai --- drivers/md/dm-vdo/dm-vdo-target.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/md/dm-vdo/dm-vdo-target.c b/drivers/md/dm-vdo/dm-vdo-target.c index 9128e6cd08443..5a4b0a927f560 100644 --- a/drivers/md/dm-vdo/dm-vdo-target.c +++ b/drivers/md/dm-vdo/dm-vdo-target.c @@ -39,8 +39,6 @@ #include "vdo.h" #include "vio.h" -#define CURRENT_VERSION "8.3.0.65" - enum admin_phases { GROW_LOGICAL_PHASE_START, GROW_LOGICAL_PHASE_GROW_BLOCK_MAP, @@ -2863,8 +2861,6 @@ static void vdo_module_destroy(void) instances.count); vdo_free(instances.words); memset(&instances, 0, sizeof(struct instance_tracker)); - - vdo_log_info("unloaded version %s", CURRENT_VERSION); } static int __init vdo_init(void) @@ -2876,7 +2872,6 @@ static int __init vdo_init(void) vdo_initialize_threads_mutex(); vdo_initialize_thread_device_registry(); vdo_initialize_device_registry_once(); - vdo_log_info("loaded version %s", CURRENT_VERSION); /* Add VDO errors to the set of errors registered by the indexer. */ result = vdo_register_status_codes(); From bc2150af989df68fd862e338006810c5f6be4715 Mon Sep 17 00:00:00 2001 From: Yang Li Date: Fri, 1 Mar 2024 16:54:40 +0800 Subject: [PATCH 3/3] dm vdo: remove unneeded semicolon Remove the unnecessary semicolon at the end of the for statement which cleans up the code and ensures consistency with the rest of the kernel coding style. Signed-off-by: Yang Li Signed-off-by: Matthew Sakai --- drivers/md/dm-vdo/block-map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-vdo/block-map.c b/drivers/md/dm-vdo/block-map.c index e79156dc7cc9a..a0a7c1bd634e8 100644 --- a/drivers/md/dm-vdo/block-map.c +++ b/drivers/md/dm-vdo/block-map.c @@ -2705,7 +2705,7 @@ void vdo_traverse_forest(struct block_map *map, vdo_entry_callback_fn callback, cursor->waiter.callback = launch_cursor; acquire_vio_from_pool(cursors->pool, &cursor->waiter); - }; + } } /**