fault-inject.h 1.8 KB
Newer Older
1 2 3 4 5 6 7
#ifndef _LINUX_FAULT_INJECT_H
#define _LINUX_FAULT_INJECT_H

#ifdef CONFIG_FAULT_INJECTION

#include <linux/types.h>
#include <linux/debugfs.h>
8
#include <linux/ratelimit.h>
A
Arun Sharma 已提交
9
#include <linux/atomic.h>
10 11 12 13 14 15 16 17 18 19 20

/*
 * For explanation of the elements of this struct, see
 * Documentation/fault-injection/fault-injection.txt
 */
struct fault_attr {
	unsigned long probability;
	unsigned long interval;
	atomic_t times;
	atomic_t space;
	unsigned long verbose;
21
	bool task_filter;
22 23 24 25 26
	unsigned long stacktrace_depth;
	unsigned long require_start;
	unsigned long require_end;
	unsigned long reject_start;
	unsigned long reject_end;
27 28

	unsigned long count;
29 30
	struct ratelimit_state ratelimit_state;
	struct dentry *dname;
31 32
};

33 34 35 36 37 38 39 40
#define FAULT_ATTR_INITIALIZER {					\
		.interval = 1,						\
		.times = ATOMIC_INIT(1),				\
		.require_end = ULONG_MAX,				\
		.stacktrace_depth = 32,					\
		.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,	\
		.verbose = 2,						\
		.dname = NULL,						\
41 42 43 44
	}

#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
int setup_fault_attr(struct fault_attr *attr, char *str);
45
bool should_fail(struct fault_attr *attr, ssize_t size);
46 47 48

#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS

49 50
struct dentry *fault_create_debugfs_attr(const char *name,
			struct dentry *parent, struct fault_attr *attr);
51 52 53

#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */

54 55
static inline struct dentry *fault_create_debugfs_attr(const char *name,
			struct dentry *parent, struct fault_attr *attr)
56
{
57
	return ERR_PTR(-ENODEV);
58 59 60 61 62 63
}

#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */

#endif /* CONFIG_FAULT_INJECTION */

64 65
struct kmem_cache;

A
Akinobu Mita 已提交
66
#ifdef CONFIG_FAILSLAB
67
extern bool should_failslab(struct kmem_cache *s, gfp_t gfpflags);
A
Akinobu Mita 已提交
68
#else
69
static inline bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
A
Akinobu Mita 已提交
70 71 72 73 74
{
	return false;
}
#endif /* CONFIG_FAILSLAB */

75
#endif /* _LINUX_FAULT_INJECT_H */