Merge tag 'perf-tools-for-v6.4-3-2023-05-06' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / linux / fault-inject.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6ff1cb35
AM
2#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>
4668c7a2 9#include <linux/configfs.h>
6adc4a22 10#include <linux/ratelimit.h>
60063497 11#include <linux/atomic.h>
6ff1cb35
AM
12
13/*
14 * For explanation of the elements of this struct, see
10ffebbe 15 * Documentation/fault-injection/fault-injection.rst
6ff1cb35
AM
16 */
17struct fault_attr {
18 unsigned long probability;
19 unsigned long interval;
20 atomic_t times;
21 atomic_t space;
22 unsigned long verbose;
621a5f7a 23 bool task_filter;
329409ae
AM
24 unsigned long stacktrace_depth;
25 unsigned long require_start;
26 unsigned long require_end;
27 unsigned long reject_start;
28 unsigned long reject_end;
6ff1cb35
AM
29
30 unsigned long count;
6adc4a22
DM
31 struct ratelimit_state ratelimit_state;
32 struct dentry *dname;
6ff1cb35
AM
33};
34
ea4452de
QZ
35enum fault_flags {
36 FAULT_NOWARN = 1 << 0,
37};
38
6adc4a22
DM
39#define FAULT_ATTR_INITIALIZER { \
40 .interval = 1, \
41 .times = ATOMIC_INIT(1), \
42 .require_end = ULONG_MAX, \
43 .stacktrace_depth = 32, \
44 .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
45 .verbose = 2, \
46 .dname = NULL, \
6ff1cb35
AM
47 }
48
49#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
50int setup_fault_attr(struct fault_attr *attr, char *str);
ea4452de 51bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
08b3df2d 52bool should_fail(struct fault_attr *attr, ssize_t size);
6ff1cb35
AM
53
54#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
55
dd48c085
AM
56struct dentry *fault_create_debugfs_attr(const char *name,
57 struct dentry *parent, struct fault_attr *attr);
6ff1cb35
AM
58
59#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
60
dd48c085
AM
61static inline struct dentry *fault_create_debugfs_attr(const char *name,
62 struct dentry *parent, struct fault_attr *attr)
6ff1cb35 63{
dd48c085 64 return ERR_PTR(-ENODEV);
6ff1cb35
AM
65}
66
67#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
68
4668c7a2
AM
69#ifdef CONFIG_FAULT_INJECTION_CONFIGFS
70
71struct fault_config {
72 struct fault_attr attr;
73 struct config_group group;
74};
75
76void fault_config_init(struct fault_config *config, const char *name);
77
78#else /* CONFIG_FAULT_INJECTION_CONFIGFS */
79
80struct fault_config {
81};
82
83static inline void fault_config_init(struct fault_config *config,
84 const char *name)
85{
86}
87
88#endif /* CONFIG_FAULT_INJECTION_CONFIGFS */
89
6ff1cb35
AM
90#endif /* CONFIG_FAULT_INJECTION */
91
cc689c5b
IM
92struct kmem_cache;
93
1e7a8181
VB
94bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
95
4f6923fb 96int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
773ff60e 97#ifdef CONFIG_FAILSLAB
4f6923fb 98extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
773ff60e 99#else
4f6923fb 100static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
773ff60e
AM
101{
102 return false;
103}
104#endif /* CONFIG_FAILSLAB */
105
6ff1cb35 106#endif /* _LINUX_FAULT_INJECT_H */