blob: 798fad9e420d656985d423ec5732605ad835f6d2 [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>
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -08008#include <linux/ratelimit.h>
Arun Sharma600634972011-07-26 16:09:06 -07009#include <linux/atomic.h>
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080010
11/*
12 * For explanation of the elements of this struct, see
13 * Documentation/fault-injection/fault-injection.txt
14 */
15struct fault_attr {
16 unsigned long probability;
17 unsigned long interval;
18 atomic_t times;
19 atomic_t space;
20 unsigned long verbose;
Akinobu Mitaf4f154f2006-12-08 02:39:47 -080021 u32 task_filter;
Akinobu Mita329409a2006-12-08 02:39:48 -080022 unsigned long stacktrace_depth;
23 unsigned long require_start;
24 unsigned long require_end;
25 unsigned long reject_start;
26 unsigned long reject_end;
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080027
28 unsigned long count;
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -080029 struct ratelimit_state ratelimit_state;
30 struct dentry *dname;
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080031};
32
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -080033#define FAULT_ATTR_INITIALIZER { \
34 .interval = 1, \
35 .times = ATOMIC_INIT(1), \
36 .require_end = ULONG_MAX, \
37 .stacktrace_depth = 32, \
38 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
39 .verbose = 2, \
40 .dname = NULL, \
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080041 }
42
43#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
44int setup_fault_attr(struct fault_attr *attr, char *str);
Don Mullis08b3df22006-12-08 02:39:51 -080045bool should_fail(struct fault_attr *attr, ssize_t size);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080046
47#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
48
Akinobu Mitadd48c082011-08-03 16:21:01 -070049struct dentry *fault_create_debugfs_attr(const char *name,
50 struct dentry *parent, struct fault_attr *attr);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080051
52#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
53
Akinobu Mitadd48c082011-08-03 16:21:01 -070054static inline struct dentry *fault_create_debugfs_attr(const char *name,
55 struct dentry *parent, struct fault_attr *attr)
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080056{
Akinobu Mitadd48c082011-08-03 16:21:01 -070057 return ERR_PTR(-ENODEV);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080058}
59
60#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
61
62#endif /* CONFIG_FAULT_INJECTION */
63
Akinobu Mita773ff602008-12-23 19:37:01 +090064#ifdef CONFIG_FAILSLAB
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030065extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags);
Akinobu Mita773ff602008-12-23 19:37:01 +090066#else
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030067static inline bool should_failslab(size_t size, gfp_t gfpflags,
68 unsigned long flags)
Akinobu Mita773ff602008-12-23 19:37:01 +090069{
70 return false;
71}
72#endif /* CONFIG_FAILSLAB */
73
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080074#endif /* _LINUX_FAULT_INJECT_H */