Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
6ff1cb35 AM |
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> | |
6adc4a22 | 9 | #include <linux/ratelimit.h> |
60063497 | 10 | #include <linux/atomic.h> |
6ff1cb35 AM |
11 | |
12 | /* | |
13 | * For explanation of the elements of this struct, see | |
10ffebbe | 14 | * Documentation/fault-injection/fault-injection.rst |
6ff1cb35 AM |
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; | |
621a5f7a | 22 | bool task_filter; |
329409ae AM |
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; | |
6ff1cb35 AM |
28 | |
29 | unsigned long count; | |
6adc4a22 DM |
30 | struct ratelimit_state ratelimit_state; |
31 | struct dentry *dname; | |
6ff1cb35 AM |
32 | }; |
33 | ||
6adc4a22 DM |
34 | #define FAULT_ATTR_INITIALIZER { \ |
35 | .interval = 1, \ | |
36 | .times = ATOMIC_INIT(1), \ | |
37 | .require_end = ULONG_MAX, \ | |
38 | .stacktrace_depth = 32, \ | |
39 | .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \ | |
40 | .verbose = 2, \ | |
41 | .dname = NULL, \ | |
6ff1cb35 AM |
42 | } |
43 | ||
44 | #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER | |
45 | int setup_fault_attr(struct fault_attr *attr, char *str); | |
08b3df2d | 46 | bool should_fail(struct fault_attr *attr, ssize_t size); |
6ff1cb35 AM |
47 | |
48 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS | |
49 | ||
dd48c085 AM |
50 | struct dentry *fault_create_debugfs_attr(const char *name, |
51 | struct dentry *parent, struct fault_attr *attr); | |
6ff1cb35 AM |
52 | |
53 | #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */ | |
54 | ||
dd48c085 AM |
55 | static inline struct dentry *fault_create_debugfs_attr(const char *name, |
56 | struct dentry *parent, struct fault_attr *attr) | |
6ff1cb35 | 57 | { |
dd48c085 | 58 | return ERR_PTR(-ENODEV); |
6ff1cb35 AM |
59 | } |
60 | ||
61 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ | |
62 | ||
63 | #endif /* CONFIG_FAULT_INJECTION */ | |
64 | ||
cc689c5b IM |
65 | struct kmem_cache; |
66 | ||
4f6923fb | 67 | int should_failslab(struct kmem_cache *s, gfp_t gfpflags); |
773ff60e | 68 | #ifdef CONFIG_FAILSLAB |
4f6923fb | 69 | extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags); |
773ff60e | 70 | #else |
4f6923fb | 71 | static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
773ff60e AM |
72 | { |
73 | return false; | |
74 | } | |
75 | #endif /* CONFIG_FAILSLAB */ | |
76 | ||
6ff1cb35 | 77 | #endif /* _LINUX_FAULT_INJECT_H */ |