lib/fault-inject.c
Source file repositories/reference/linux-study-clean/lib/fault-inject.c
File Facts
- System
- Linux kernel
- Corpus path
lib/fault-inject.c- Extension
.c- Size
- 12108 bytes
- Lines
- 463
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
linux/kernel.hlinux/init.hlinux/prandom.hlinux/debugfs.hlinux/sched.hlinux/stat.hlinux/types.hlinux/fs.hlinux/export.hlinux/interrupt.hlinux/stacktrace.hlinux/fault-inject.h
Detected Declarations
function fault_prandom_u32_below_100function setup_fault_attrfunction fail_dumpfunction fail_taskfunction fail_stacktracefunction fail_stacktracefunction should_fail_exfunction should_failfunction debugfs_ul_setfunction debugfs_ul_getfunction debugfs_create_ulfunction debugfs_stacktrace_depth_setfunction debugfs_create_stacktrace_depthfunction fault_uint_attr_showfunction fault_ulong_attr_showfunction fault_bool_attr_showfunction fault_atomic_t_attr_showfunction fault_uint_attr_storefunction fault_ulong_attr_storefunction fault_bool_attr_storefunction fault_atomic_t_attr_storefunction fault_stacktrace_depth_showfunction fault_stacktrace_depth_storefunction fault_xul_attr_showfunction fault_xul_attr_storefunction fault_config_initexport setup_fault_attrexport should_failexport fault_create_debugfs_attrexport fault_config_init
Annotated Snippet
if (fail_nth) {
if (!fail_stacktrace(attr))
return false;
stack_checked = true;
fail_nth--;
WRITE_ONCE(current->fail_nth, fail_nth);
if (!fail_nth)
goto fail;
return false;
}
}
/* No need to check any other properties if the probability is 0 */
if (attr->probability == 0)
return false;
if (attr->task_filter && !fail_task(attr, current))
return false;
if (atomic_read(&attr->times) == 0)
return false;
if (!stack_checked && !fail_stacktrace(attr))
return false;
if (atomic_read(&attr->space) > size) {
atomic_sub(size, &attr->space);
return false;
}
if (attr->interval > 1) {
attr->count++;
if (attr->count % attr->interval)
return false;
}
if (attr->probability <= fault_prandom_u32_below_100())
return false;
fail:
if (!(flags & FAULT_NOWARN))
fail_dump(attr);
if (atomic_read(&attr->times) != -1)
atomic_dec_not_zero(&attr->times);
return true;
}
bool should_fail(struct fault_attr *attr, ssize_t size)
{
return should_fail_ex(attr, size, 0);
}
EXPORT_SYMBOL_GPL(should_fail);
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
static int debugfs_ul_set(void *data, u64 val)
{
*(unsigned long *)data = val;
return 0;
}
static int debugfs_ul_get(void *data, u64 *val)
{
*val = *(unsigned long *)data;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
static void debugfs_create_ul(const char *name, umode_t mode,
struct dentry *parent, unsigned long *value)
{
debugfs_create_file(name, mode, parent, value, &fops_ul);
}
#ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
static int debugfs_stacktrace_depth_set(void *data, u64 val)
{
*(unsigned long *)data =
min_t(unsigned long, val, MAX_STACK_TRACE_DEPTH);
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_stacktrace_depth, debugfs_ul_get,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/prandom.h`, `linux/debugfs.h`, `linux/sched.h`, `linux/stat.h`, `linux/types.h`, `linux/fs.h`.
- Detected declarations: `function fault_prandom_u32_below_100`, `function setup_fault_attr`, `function fail_dump`, `function fail_task`, `function fail_stacktrace`, `function fail_stacktrace`, `function should_fail_ex`, `function should_fail`, `function debugfs_ul_set`, `function debugfs_ul_get`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration 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.