Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_FAULT_INJECT_H
3#define _LINUX_FAULT_INJECT_H
4
5#ifdef CONFIG_FAULT_INJECTION
6
7#include <linux/types.h>
8#include <linux/debugfs.h>
9#include <linux/ratelimit.h>
10#include <linux/atomic.h>
11
12/*
13 * For explanation of the elements of this struct, see
14 * Documentation/fault-injection/fault-injection.rst
15 */
16struct fault_attr {
17 unsigned long probability;
18 unsigned long interval;
19 atomic_t times;
20 atomic_t space;
21 unsigned long verbose;
22 bool task_filter;
23 bool no_warn;
24 unsigned long stacktrace_depth;
25 unsigned long require_start;
26 unsigned long require_end;
27 unsigned long reject_start;
28 unsigned long reject_end;
29
30 unsigned long count;
31 struct ratelimit_state ratelimit_state;
32 struct dentry *dname;
33};
34
35#define FAULT_ATTR_INITIALIZER { \
36 .interval = 1, \
37 .times = ATOMIC_INIT(1), \
38 .require_end = ULONG_MAX, \
39 .stacktrace_depth = 32, \
40 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
41 .verbose = 2, \
42 .dname = NULL, \
43 .no_warn = false, \
44 }
45
46#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
47int setup_fault_attr(struct fault_attr *attr, char *str);
48bool should_fail(struct fault_attr *attr, ssize_t size);
49
50#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
51
52struct dentry *fault_create_debugfs_attr(const char *name,
53 struct dentry *parent, struct fault_attr *attr);
54
55#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
56
57static inline struct dentry *fault_create_debugfs_attr(const char *name,
58 struct dentry *parent, struct fault_attr *attr)
59{
60 return ERR_PTR(-ENODEV);
61}
62
63#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
64
65#endif /* CONFIG_FAULT_INJECTION */
66
67struct kmem_cache;
68
69bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
70
71int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
72#ifdef CONFIG_FAILSLAB
73extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
74#else
75static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
76{
77 return false;
78}
79#endif /* CONFIG_FAILSLAB */
80
81#endif /* _LINUX_FAULT_INJECT_H */