Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_FAULT_INJECT_H |
| 2 | #define _LINUX_FAULT_INJECT_H |
| 3 | |
| 4 | #ifdef CONFIG_FAULT_INJECTION |
| 5 | |
| 6 | #include <linux/types.h> |
| 7 | #include <linux/debugfs.h> |
| 8 | #include <asm/atomic.h> |
| 9 | |
| 10 | /* |
| 11 | * For explanation of the elements of this struct, see |
| 12 | * Documentation/fault-injection/fault-injection.txt |
| 13 | */ |
| 14 | struct fault_attr { |
| 15 | unsigned long probability; |
| 16 | unsigned long interval; |
| 17 | atomic_t times; |
| 18 | atomic_t space; |
| 19 | unsigned long verbose; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 20 | u32 task_filter; |
Akinobu Mita | 329409a | 2006-12-08 02:39:48 -0800 | [diff] [blame] | 21 | unsigned long stacktrace_depth; |
| 22 | unsigned long require_start; |
| 23 | unsigned long require_end; |
| 24 | unsigned long reject_start; |
| 25 | unsigned long reject_end; |
Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 26 | |
| 27 | unsigned long count; |
| 28 | |
| 29 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
| 30 | |
| 31 | struct { |
| 32 | struct dentry *dir; |
| 33 | |
| 34 | struct dentry *probability_file; |
| 35 | struct dentry *interval_file; |
| 36 | struct dentry *times_file; |
| 37 | struct dentry *space_file; |
| 38 | struct dentry *verbose_file; |
Akinobu Mita | f4f154f | 2006-12-08 02:39:47 -0800 | [diff] [blame] | 39 | struct dentry *task_filter_file; |
Akinobu Mita | 329409a | 2006-12-08 02:39:48 -0800 | [diff] [blame] | 40 | struct dentry *stacktrace_depth_file; |
| 41 | struct dentry *require_start_file; |
| 42 | struct dentry *require_end_file; |
| 43 | struct dentry *reject_start_file; |
| 44 | struct dentry *reject_end_file; |
Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 45 | } dentries; |
| 46 | |
| 47 | #endif |
| 48 | }; |
| 49 | |
| 50 | #define FAULT_ATTR_INITIALIZER { \ |
| 51 | .interval = 1, \ |
| 52 | .times = ATOMIC_INIT(1), \ |
Akinobu Mita | 329409a | 2006-12-08 02:39:48 -0800 | [diff] [blame] | 53 | .require_end = ULONG_MAX, \ |
| 54 | .stacktrace_depth = 32, \ |
Don Mullis | 6b1b60f | 2006-12-08 02:39:53 -0800 | [diff] [blame] | 55 | .verbose = 2, \ |
Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER |
| 59 | int setup_fault_attr(struct fault_attr *attr, char *str); |
| 60 | void should_fail_srandom(unsigned long entropy); |
Don Mullis | 08b3df2 | 2006-12-08 02:39:51 -0800 | [diff] [blame] | 61 | bool should_fail(struct fault_attr *attr, ssize_t size); |
Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 62 | |
| 63 | #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS |
| 64 | |
| 65 | int init_fault_attr_dentries(struct fault_attr *attr, const char *name); |
| 66 | void cleanup_fault_attr_dentries(struct fault_attr *attr); |
| 67 | |
| 68 | #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |
| 69 | |
| 70 | static inline int init_fault_attr_dentries(struct fault_attr *attr, |
| 71 | const char *name) |
| 72 | { |
| 73 | return -ENODEV; |
| 74 | } |
| 75 | |
| 76 | static inline void cleanup_fault_attr_dentries(struct fault_attr *attr) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ |
| 81 | |
| 82 | #endif /* CONFIG_FAULT_INJECTION */ |
| 83 | |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 84 | #ifdef CONFIG_FAILSLAB |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 85 | extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags); |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 86 | #else |
Dmitry Monakhov | 4c13dd3 | 2010-02-26 09:36:12 +0300 | [diff] [blame] | 87 | static inline bool should_failslab(size_t size, gfp_t gfpflags, |
| 88 | unsigned long flags) |
Akinobu Mita | 773ff60 | 2008-12-23 19:37:01 +0900 | [diff] [blame] | 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | #endif /* CONFIG_FAILSLAB */ |
| 93 | |
Akinobu Mita | 6ff1cb3 | 2006-12-08 02:39:43 -0800 | [diff] [blame] | 94 | #endif /* _LINUX_FAULT_INJECT_H */ |