printf: Remove unused 'bprintf'
[drm/drm-misc.git] / include / linux / fault-inject.h
blob8c829d28dcf356976c6906a1837457d3d64513cd
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FAULT_INJECT_H
3 #define _LINUX_FAULT_INJECT_H
5 #include <linux/err.h>
6 #include <linux/types.h>
8 struct dentry;
9 struct kmem_cache;
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
21 struct fault_attr {
22 unsigned long probability;
23 unsigned long interval;
24 atomic_t times;
25 atomic_t space;
26 unsigned long verbose;
27 bool task_filter;
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;
34 unsigned long count;
35 struct ratelimit_state ratelimit_state;
36 struct dentry *dname;
39 enum fault_flags {
40 FAULT_NOWARN = 1 << 0,
43 #define FAULT_ATTR_INITIALIZER { \
44 .interval = 1, \
45 .times = ATOMIC_INIT(1), \
46 .require_end = ULONG_MAX, \
47 .stacktrace_depth = 32, \
48 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
49 .verbose = 2, \
50 .dname = NULL, \
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 */
60 struct fault_attr {
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)
71 return false;
73 static inline bool should_fail(struct fault_attr *attr, ssize_t size)
75 return false;
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
97 struct fault_config {
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,
110 const char *name)
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);
118 #else
119 static inline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
121 return false;
123 #endif /* CONFIG_FAIL_PAGE_ALLOC */
125 #ifdef CONFIG_FAILSLAB
126 int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
127 #else
128 static inline int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
130 return false;
132 #endif /* CONFIG_FAILSLAB */
134 #endif /* _LINUX_FAULT_INJECT_H */