1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FAULT_INJECT_H
3 #define _LINUX_FAULT_INJECT_H
6 #include <linux/types.h>
11 #ifdef CONFIG_FAULT_INJECTION
13 #include <linux/atomic.h>
14 #include <linux/configfs.h>
15 #include <linux/ratelimit.h>
18 * For explanation of the elements of this struct, see
19 * Documentation/fault-injection/fault-injection.rst
22 unsigned long probability;
23 unsigned long interval;
26 unsigned long verbose;
28 unsigned long stacktrace_depth;
29 unsigned long require_start;
30 unsigned long require_end;
31 unsigned long reject_start;
32 unsigned long reject_end;
35 struct ratelimit_state ratelimit_state;
40 FAULT_NOWARN = 1 << 0,
43 #define FAULT_ATTR_INITIALIZER { \
45 .times = ATOMIC_INIT(1), \
46 .require_end = ULONG_MAX, \
47 .stacktrace_depth = 32, \
48 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
53 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
54 int setup_fault_attr(struct fault_attr *attr, char *str);
55 bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
56 bool should_fail(struct fault_attr *attr, ssize_t size);
58 #else /* CONFIG_FAULT_INJECTION */
63 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = {}
65 static inline int setup_fault_attr(struct fault_attr *attr, char *str)
67 return 0; /* Note: 0 means error for __setup() handlers! */
69 static inline bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
73 static inline bool should_fail(struct fault_attr *attr, ssize_t size)
78 #endif /* CONFIG_FAULT_INJECTION */
80 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
82 struct dentry *fault_create_debugfs_attr(const char *name,
83 struct dentry *parent, struct fault_attr *attr);
85 #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
87 static inline struct dentry *fault_create_debugfs_attr(const char *name,
88 struct dentry *parent, struct fault_attr *attr)
90 return ERR_PTR(-ENODEV);
93 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
95 #ifdef CONFIG_FAULT_INJECTION_CONFIGFS
98 struct fault_attr attr;
99 struct config_group group;
102 void fault_config_init(struct fault_config *config, const char *name);
104 #else /* CONFIG_FAULT_INJECTION_CONFIGFS */
106 struct fault_config {
109 static inline void fault_config_init(struct fault_config *config,
114 #endif /* CONFIG_FAULT_INJECTION_CONFIGFS */
116 #ifdef CONFIG_FAIL_PAGE_ALLOC
117 bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
119 static inline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
123 #endif /* CONFIG_FAIL_PAGE_ALLOC */
125 #ifdef CONFIG_FAILSLAB
126 int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
128 static inline int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
132 #endif /* CONFIG_FAILSLAB */
134 #endif /* _LINUX_FAULT_INJECT_H */