Skip to content

Commit 7eb30fe

Browse files
lorelei-sakaiMike Snitzer
authored andcommitted
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 <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent d0464d8 commit 7eb30fe

File tree

4 files changed

+10
-54
lines changed

4 files changed

+10
-54
lines changed

drivers/md/dm-vdo/dm-vdo-target.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "string-utils.h"
3535
#include "thread-device.h"
3636
#include "thread-registry.h"
37+
#include "thread-utils.h"
3738
#include "types.h"
3839
#include "vdo.h"
3940
#include "vio.h"
@@ -2872,6 +2873,7 @@ static int __init vdo_init(void)
28722873

28732874
/* Memory tracking must be initialized first for accurate accounting. */
28742875
vdo_memory_init();
2876+
vdo_initialize_threads_mutex();
28752877
vdo_initialize_thread_device_registry();
28762878
vdo_initialize_device_registry_once();
28772879
vdo_log_info("loaded version %s", CURRENT_VERSION);

drivers/md/dm-vdo/status-codes.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ const struct error_info vdo_status_list[] = {
4040
{ "VDO_INVALID_ADMIN_STATE", "Invalid operation for current state" },
4141
};
4242

43-
static atomic_t vdo_status_codes_registered = ATOMIC_INIT(0);
44-
static int status_code_registration_result;
45-
46-
static void do_status_code_registration(void)
43+
/**
44+
* vdo_register_status_codes() - Register the VDO status codes.
45+
* Return: A success or error code.
46+
*/
47+
int vdo_register_status_codes(void)
4748
{
4849
int result;
4950

@@ -53,26 +54,7 @@ static void do_status_code_registration(void)
5354
result = uds_register_error_block("VDO Status", VDO_STATUS_CODE_BASE,
5455
VDO_STATUS_CODE_BLOCK_END, vdo_status_list,
5556
sizeof(vdo_status_list));
56-
/*
57-
* The following test handles cases where libvdo is statically linked against both the test
58-
* modules and the test driver (because multiple instances of this module call their own
59-
* copy of this function once each, resulting in multiple calls to register_error_block
60-
* which is shared in libuds).
61-
*/
62-
if (result == UDS_DUPLICATE_NAME)
63-
result = UDS_SUCCESS;
64-
65-
status_code_registration_result = (result == UDS_SUCCESS) ? VDO_SUCCESS : result;
66-
}
67-
68-
/**
69-
* vdo_register_status_codes() - Register the VDO status codes if needed.
70-
* Return: A success or error code.
71-
*/
72-
int vdo_register_status_codes(void)
73-
{
74-
vdo_perform_once(&vdo_status_codes_registered, do_status_code_registration);
75-
return status_code_registration_result;
57+
return (result == UDS_SUCCESS) ? VDO_SUCCESS : result;
7658
}
7759

7860
/**

drivers/md/dm-vdo/thread-utils.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
static struct hlist_head thread_list;
1919
static struct mutex thread_mutex;
20-
static atomic_t thread_once = ATOMIC_INIT(0);
2120

2221
struct thread {
2322
void (*thread_function)(void *thread_data);
@@ -27,31 +26,7 @@ struct thread {
2726
struct completion thread_done;
2827
};
2928

30-
#define ONCE_NOT_DONE 0
31-
#define ONCE_IN_PROGRESS 1
32-
#define ONCE_COMPLETE 2
33-
34-
/* Run a function once only, and record that fact in the atomic value. */
35-
void vdo_perform_once(atomic_t *once, void (*function)(void))
36-
{
37-
for (;;) {
38-
switch (atomic_cmpxchg(once, ONCE_NOT_DONE, ONCE_IN_PROGRESS)) {
39-
case ONCE_NOT_DONE:
40-
function();
41-
atomic_set_release(once, ONCE_COMPLETE);
42-
return;
43-
case ONCE_IN_PROGRESS:
44-
cond_resched();
45-
break;
46-
case ONCE_COMPLETE:
47-
return;
48-
default:
49-
return;
50-
}
51-
}
52-
}
53-
54-
static void thread_init(void)
29+
void vdo_initialize_threads_mutex(void)
5530
{
5631
mutex_init(&thread_mutex);
5732
}
@@ -62,7 +37,6 @@ static int thread_starter(void *arg)
6237
struct thread *thread = arg;
6338

6439
thread->thread_task = current;
65-
vdo_perform_once(&thread_once, thread_init);
6640
mutex_lock(&thread_mutex);
6741
hlist_add_head(&thread->thread_links, &thread_list);
6842
mutex_unlock(&thread_mutex);

drivers/md/dm-vdo/thread-utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212

1313
struct thread;
1414

15-
15+
void vdo_initialize_threads_mutex(void);
1616
int __must_check vdo_create_thread(void (*thread_function)(void *), void *thread_data,
1717
const char *name, struct thread **new_thread);
1818
void vdo_join_threads(struct thread *thread);
1919

20-
void vdo_perform_once(atomic_t *once_state, void (*function) (void));
21-
2220
#endif /* UDS_THREADS_H */

0 commit comments

Comments
 (0)