blob: c6f996f2abb6c552345884760bfc5d5967d40bdb [file] [log] [blame]
Akinobu Mita6ff1cb32006-12-08 02:39:43 -08001#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>
Arun Sharma600634972011-07-26 16:09:06 -07008#include <linux/atomic.h>
Akinobu Mita6ff1cb32006-12-08 02:39:43 -08009
10/*
11 * For explanation of the elements of this struct, see
12 * Documentation/fault-injection/fault-injection.txt
13 */
14struct fault_attr {
15 unsigned long probability;
16 unsigned long interval;
17 atomic_t times;
18 atomic_t space;
19 unsigned long verbose;
Akinobu Mitaf4f154f2006-12-08 02:39:47 -080020 u32 task_filter;
Akinobu Mita329409a2006-12-08 02:39:48 -080021 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 Mita6ff1cb32006-12-08 02:39:43 -080026
27 unsigned long count;
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080028};
29
30#define FAULT_ATTR_INITIALIZER { \
31 .interval = 1, \
32 .times = ATOMIC_INIT(1), \
Akinobu Mita329409a2006-12-08 02:39:48 -080033 .require_end = ULONG_MAX, \
34 .stacktrace_depth = 32, \
Don Mullis6b1b60f2006-12-08 02:39:53 -080035 .verbose = 2, \
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080036 }
37
38#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
39int setup_fault_attr(struct fault_attr *attr, char *str);
Don Mullis08b3df22006-12-08 02:39:51 -080040bool should_fail(struct fault_attr *attr, ssize_t size);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080041
42#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
43
Akinobu Mitadd48c082011-08-03 16:21:01 -070044struct dentry *fault_create_debugfs_attr(const char *name,
45 struct dentry *parent, struct fault_attr *attr);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080046
47#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
48
Akinobu Mitadd48c082011-08-03 16:21:01 -070049static inline struct dentry *fault_create_debugfs_attr(const char *name,
50 struct dentry *parent, struct fault_attr *attr)
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080051{
Akinobu Mitadd48c082011-08-03 16:21:01 -070052 return ERR_PTR(-ENODEV);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080053}
54
55#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
56
57#endif /* CONFIG_FAULT_INJECTION */
58
Akinobu Mita773ff602008-12-23 19:37:01 +090059#ifdef CONFIG_FAILSLAB
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030060extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags);
Akinobu Mita773ff602008-12-23 19:37:01 +090061#else
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030062static inline bool should_failslab(size_t size, gfp_t gfpflags,
63 unsigned long flags)
Akinobu Mita773ff602008-12-23 19:37:01 +090064{
65 return false;
66}
67#endif /* CONFIG_FAILSLAB */
68
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080069#endif /* _LINUX_FAULT_INJECT_H */