Merge tag 'xfs-6.2-merge-8' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-2.6-microblaze.git] / include / linux / fault-inject.h
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  */
16 struct 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         unsigned long stacktrace_depth;
24         unsigned long require_start;
25         unsigned long require_end;
26         unsigned long reject_start;
27         unsigned long reject_end;
28
29         unsigned long count;
30         struct ratelimit_state ratelimit_state;
31         struct dentry *dname;
32 };
33
34 enum fault_flags {
35         FAULT_NOWARN =  1 << 0,
36 };
37
38 #define FAULT_ATTR_INITIALIZER {                                        \
39                 .interval = 1,                                          \
40                 .times = ATOMIC_INIT(1),                                \
41                 .require_end = ULONG_MAX,                               \
42                 .stacktrace_depth = 32,                                 \
43                 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,       \
44                 .verbose = 2,                                           \
45                 .dname = NULL,                                          \
46         }
47
48 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
49 int setup_fault_attr(struct fault_attr *attr, char *str);
50 bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
51 bool should_fail(struct fault_attr *attr, ssize_t size);
52
53 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
54
55 struct dentry *fault_create_debugfs_attr(const char *name,
56                         struct dentry *parent, struct fault_attr *attr);
57
58 #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
59
60 static inline struct dentry *fault_create_debugfs_attr(const char *name,
61                         struct dentry *parent, struct fault_attr *attr)
62 {
63         return ERR_PTR(-ENODEV);
64 }
65
66 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
67
68 #endif /* CONFIG_FAULT_INJECTION */
69
70 struct kmem_cache;
71
72 bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
73
74 int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
75 #ifdef CONFIG_FAILSLAB
76 extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
77 #else
78 static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
79 {
80         return false;
81 }
82 #endif /* CONFIG_FAILSLAB */
83
84 #endif /* _LINUX_FAULT_INJECT_H */