1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FAULT_INJECT_H
3 #define _LINUX_FAULT_INJECT_H
5 #ifdef CONFIG_FAULT_INJECTION
7 #include <linux/types.h>
8 #include <linux/debugfs.h>
9 #include <linux/configfs.h>
10 #include <linux/ratelimit.h>
11 #include <linux/atomic.h>
14 * For explanation of the elements of this struct, see
15 * Documentation/fault-injection/fault-injection.rst
18 unsigned long probability;
19 unsigned long interval;
22 unsigned long verbose;
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;
31 struct ratelimit_state ratelimit_state;
36 FAULT_NOWARN = 1 << 0,
39 #define FAULT_ATTR_INITIALIZER { \
41 .times = ATOMIC_INIT(1), \
42 .require_end = ULONG_MAX, \
43 .stacktrace_depth = 32, \
44 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
49 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
50 int setup_fault_attr(struct fault_attr *attr, char *str);
51 bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
52 bool should_fail(struct fault_attr *attr, ssize_t size);
54 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
56 struct dentry *fault_create_debugfs_attr(const char *name,
57 struct dentry *parent, struct fault_attr *attr);
59 #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
61 static inline struct dentry *fault_create_debugfs_attr(const char *name,
62 struct dentry *parent, struct fault_attr *attr)
64 return ERR_PTR(-ENODEV);
67 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
69 #ifdef CONFIG_FAULT_INJECTION_CONFIGFS
72 struct fault_attr attr;
73 struct config_group group;
76 void fault_config_init(struct fault_config *config, const char *name);
78 #else /* CONFIG_FAULT_INJECTION_CONFIGFS */
83 static inline void fault_config_init(struct fault_config *config,
88 #endif /* CONFIG_FAULT_INJECTION_CONFIGFS */
90 #endif /* CONFIG_FAULT_INJECTION */
94 bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
96 #ifdef CONFIG_FAIL_PAGE_ALLOC
97 bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
99 static inline bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
103 #endif /* CONFIG_FAIL_PAGE_ALLOC */
105 int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
106 #ifdef CONFIG_FAILSLAB
107 extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
109 static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
113 #endif /* CONFIG_FAILSLAB */
115 #endif /* _LINUX_FAULT_INJECT_H */