blob: e525f6957c49f5ae7af97042120c33e0fe7ff12e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Akinobu Mita6ff1cb32006-12-08 02:39:43 -08002#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>
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -08009#include <linux/ratelimit.h>
Arun Sharma600634972011-07-26 16:09:06 -070010#include <linux/atomic.h>
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080011
12/*
13 * For explanation of the elements of this struct, see
Mauro Carvalho Chehab10ffebb2019-06-12 14:52:44 -030014 * Documentation/fault-injection/fault-injection.rst
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080015 */
16struct fault_attr {
17 unsigned long probability;
18 unsigned long interval;
19 atomic_t times;
20 atomic_t space;
21 unsigned long verbose;
Viresh Kumar621a5f72015-09-26 15:04:07 -070022 bool task_filter;
Akinobu Mita329409a2006-12-08 02:39:48 -080023 unsigned long stacktrace_depth;
24 unsigned long require_start;
25 unsigned long require_end;
26 unsigned long reject_start;
27 unsigned long reject_end;
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080028
29 unsigned long count;
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -080030 struct ratelimit_state ratelimit_state;
31 struct dentry *dname;
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080032};
33
Dmitry Monakhov6adc4a22014-12-12 16:58:00 -080034#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, \
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080042 }
43
44#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
45int setup_fault_attr(struct fault_attr *attr, char *str);
Don Mullis08b3df22006-12-08 02:39:51 -080046bool should_fail(struct fault_attr *attr, ssize_t size);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080047
48#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
49
Akinobu Mitadd48c082011-08-03 16:21:01 -070050struct dentry *fault_create_debugfs_attr(const char *name,
51 struct dentry *parent, struct fault_attr *attr);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080052
53#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
54
Akinobu Mitadd48c082011-08-03 16:21:01 -070055static inline struct dentry *fault_create_debugfs_attr(const char *name,
56 struct dentry *parent, struct fault_attr *attr)
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080057{
Akinobu Mitadd48c082011-08-03 16:21:01 -070058 return ERR_PTR(-ENODEV);
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080059}
60
61#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
62
63#endif /* CONFIG_FAULT_INJECTION */
64
Ingo Molnarcc689c52017-02-01 16:36:40 +010065struct kmem_cache;
66
Howard McLauchlan4f6923fb2018-04-05 16:23:57 -070067int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
Akinobu Mita773ff602008-12-23 19:37:01 +090068#ifdef CONFIG_FAILSLAB
Howard McLauchlan4f6923fb2018-04-05 16:23:57 -070069extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
Akinobu Mita773ff602008-12-23 19:37:01 +090070#else
Howard McLauchlan4f6923fb2018-04-05 16:23:57 -070071static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
Akinobu Mita773ff602008-12-23 19:37:01 +090072{
73 return false;
74}
75#endif /* CONFIG_FAILSLAB */
76
Akinobu Mita6ff1cb32006-12-08 02:39:43 -080077#endif /* _LINUX_FAULT_INJECT_H */