drivers/md/dm-vdo/thread-utils.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/thread-utils.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/thread-utils.c- Extension
.c- Size
- 2939 bytes
- Lines
- 109
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
thread-utils.hasm/current.hlinux/delay.hlinux/kthread.hlinux/mutex.hlinux/types.herrors.hlogger.hmemory-alloc.h
Detected Declarations
struct threadfunction vdo_initialize_threads_mutexfunction thread_starterfunction vdo_create_threadfunction tofunction vdo_join_threads
Annotated Snippet
struct thread {
void (*thread_function)(void *thread_data);
void *thread_data;
struct hlist_node thread_links;
struct task_struct *thread_task;
struct completion thread_done;
};
void vdo_initialize_threads_mutex(void)
{
mutex_init(&thread_mutex);
}
static int thread_starter(void *arg)
{
struct registered_thread allocating_thread;
struct thread *thread = arg;
thread->thread_task = current;
mutex_lock(&thread_mutex);
hlist_add_head(&thread->thread_links, &thread_list);
mutex_unlock(&thread_mutex);
vdo_register_allocating_thread(&allocating_thread, NULL);
thread->thread_function(thread->thread_data);
vdo_unregister_allocating_thread();
complete(&thread->thread_done);
return 0;
}
int vdo_create_thread(void (*thread_function)(void *), void *thread_data,
const char *name, struct thread **new_thread)
{
char *name_colon = strchr(name, ':');
char *my_name_colon = strchr(current->comm, ':');
struct task_struct *task;
struct thread *thread;
int result;
result = vdo_allocate(1, __func__, &thread);
if (result != VDO_SUCCESS) {
vdo_log_warning("Error allocating memory for %s", name);
return result;
}
thread->thread_function = thread_function;
thread->thread_data = thread_data;
init_completion(&thread->thread_done);
/*
* Start the thread, with an appropriate thread name.
*
* If the name supplied contains a colon character, use that name. This causes uds module
* threads to have names like "uds:callbackW" and the main test runner thread to be named
* "zub:runtest".
*
* Otherwise if the current thread has a name containing a colon character, prefix the name
* supplied with the name of the current thread up to (and including) the colon character.
* Thus when the "kvdo0:dedupeQ" thread opens an index session, all the threads associated
* with that index will have names like "kvdo0:foo".
*
* Otherwise just use the name supplied. This should be a rare occurrence.
*/
if ((name_colon == NULL) && (my_name_colon != NULL)) {
task = kthread_run(thread_starter, thread, "%.*s:%s",
(int) (my_name_colon - current->comm), current->comm,
name);
} else {
task = kthread_run(thread_starter, thread, "%s", name);
}
if (IS_ERR(task)) {
vdo_free(thread);
return PTR_ERR(task);
}
*new_thread = thread;
return VDO_SUCCESS;
}
void vdo_join_threads(struct thread *thread)
{
while (wait_for_completion_interruptible(&thread->thread_done))
fsleep(1000);
mutex_lock(&thread_mutex);
hlist_del(&thread->thread_links);
mutex_unlock(&thread_mutex);
vdo_free(thread);
}
Annotation
- Immediate include surface: `thread-utils.h`, `asm/current.h`, `linux/delay.h`, `linux/kthread.h`, `linux/mutex.h`, `linux/types.h`, `errors.h`, `logger.h`.
- Detected declarations: `struct thread`, `function vdo_initialize_threads_mutex`, `function thread_starter`, `function vdo_create_thread`, `function to`, `function vdo_join_threads`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.