lib/test_kmod.c
Source file repositories/reference/linux-study-clean/lib/test_kmod.c
File Facts
- System
- Linux kernel
- Corpus path
lib/test_kmod.c- Extension
.c- Size
- 30378 bytes
- Lines
- 1232
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/kmod.hlinux/printk.hlinux/kthread.hlinux/sched.hlinux/fs.hlinux/miscdevice.hlinux/vmalloc.hlinux/slab.hlinux/device.h
Detected Declarations
struct test_configstruct kmod_test_devicestruct kmod_test_device_infostruct kmod_test_deviceenum kmod_test_casefunction kmod_test_done_checkfunction test_kmod_put_modulefunction run_requestfunction tally_work_testfunction tally_up_workfunction try_one_requestfunction test_dev_kmod_stop_testsfunction try_requestsfunction run_test_driverfunction run_test_fs_typefunction config_showfunction __trigger_config_runfunction trigger_config_runfunction trigger_config_storefunction kfree_constfunction config_copy_test_driver_namefunction config_copy_test_fsfunction __kmod_config_freefunction kmod_config_freefunction config_test_driver_storefunction sysfs_kf_seq_showfunction config_test_driver_showfunction config_test_fs_storefunction config_test_fs_showfunction trigger_config_run_typefunction free_test_dev_infofunction kmod_config_sync_infofunction kmod_init_test_thread_limitfunction kmod_init_test_thread_limitfunction __kmod_config_initfunction reset_storefunction test_dev_config_update_uint_syncfunction test_dev_config_update_uint_rangefunction test_dev_config_update_intfunction test_dev_config_show_intfunction test_dev_config_show_uintfunction test_result_storefunction config_num_threads_storefunction config_num_threads_showfunction config_test_case_storefunction config_test_case_showfunction test_result_showfunction kmod_config_init
Annotated Snippet
struct test_config {
char *test_driver;
char *test_fs;
unsigned int num_threads;
enum kmod_test_case test_case;
int test_result;
};
struct kmod_test_device;
/**
* struct kmod_test_device_info - thread info
*
* @ret_sync: return value if request_module() is used, sync request for
* @TEST_KMOD_DRIVER
* @fs_sync: return value of get_fs_type() for @TEST_KMOD_FS_TYPE
* @task_sync: kthread's task_struct or %NULL if not running
* @thread_idx: thread ID
* @test_dev: test device test is being performed under
* @need_mod_put: Some tests (get_fs_type() is one) requires putting the module
* (module_put(fs_sync->owner)) when done, otherwise you will not be able
* to unload the respective modules and re-test. We use this to keep
* accounting of when we need this and to help out in case we need to
* error out and deal with module_put() on error.
*/
struct kmod_test_device_info {
int ret_sync;
struct file_system_type *fs_sync;
struct task_struct *task_sync;
unsigned int thread_idx;
struct kmod_test_device *test_dev;
bool need_mod_put;
};
/**
* struct kmod_test_device - test device to help test kmod
*
* @dev_idx: unique ID for test device
* @config: configuration for the test
* @misc_dev: we use a misc device under the hood
* @dev: pointer to misc_dev's own struct device
* @config_mutex: protects configuration of test
* @trigger_mutex: the test trigger can only be fired once at a time
* @thread_mutex: protects @done count, and the @info per each thread
* @done: number of threads which have completed or failed
* @test_is_oom: when we run out of memory, use this to halt moving forward
* @kthreads_done: completion used to signal when all work is done
* @list: needed to be part of the reg_test_devs
* @info: array of info for each thread
*/
struct kmod_test_device {
int dev_idx;
struct test_config config;
struct miscdevice misc_dev;
struct device *dev;
struct mutex config_mutex;
struct mutex trigger_mutex;
struct mutex thread_mutex;
unsigned int done;
bool test_is_oom;
struct completion kthreads_done;
struct list_head list;
struct kmod_test_device_info *info;
};
static const char *test_case_str(enum kmod_test_case test_case)
{
switch (test_case) {
case TEST_KMOD_DRIVER:
return "TEST_KMOD_DRIVER";
case TEST_KMOD_FS_TYPE:
return "TEST_KMOD_FS_TYPE";
default:
return "invalid";
}
}
static struct miscdevice *dev_to_misc_dev(struct device *dev)
{
return dev_get_drvdata(dev);
}
static struct kmod_test_device *misc_dev_to_test_dev(struct miscdevice *misc_dev)
{
return container_of(misc_dev, struct kmod_test_device, misc_dev);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/kmod.h`, `linux/printk.h`, `linux/kthread.h`, `linux/sched.h`, `linux/fs.h`, `linux/miscdevice.h`.
- Detected declarations: `struct test_config`, `struct kmod_test_device`, `struct kmod_test_device_info`, `struct kmod_test_device`, `enum kmod_test_case`, `function kmod_test_done_check`, `function test_kmod_put_module`, `function run_request`, `function tally_work_test`, `function tally_up_work`.
- Atlas domain: Kernel Services / lib.
- 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.