File Index
Files and directories
Sign in
FILE

fault-inject.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/fault-inject.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _LINUX_FAULT_INJECT_H
  3#define _LINUX_FAULT_INJECT_H
  4
  5#include <linux/err.h>
  6#include <linux/types.h>
  7
  8struct dentry;
  9struct kmem_cache;
 10
 11enum fault_flags {
 12	FAULT_NOWARN =	1 << 0,
 13};
 14
 15#ifdef CONFIG_FAULT_INJECTION
 16
 17#include <linux/atomic.h>
 18#include <linux/configfs.h>
 19#include <linux/ratelimit.h>
 20
 21/*
 22 * For explanation of the elements of this struct, see
 23 * Documentation/fault-injection/fault-injection.rst
 24 */
 25struct fault_attr {
 26	unsigned long probability;
 27	unsigned long interval;
 28	atomic_t times;
 29	atomic_t space;
 30	unsigned long verbose;
 31	bool task_filter;
 32	unsigned long stacktrace_depth;
 33	unsigned long require_start;
 34	unsigned long require_end;
 35	unsigned long reject_start;
 36	unsigned long reject_end;
 37
 38	unsigned long count;
 39	struct ratelimit_state ratelimit_state;
 40	struct dentry *dname;
 41};
 42
 43#define FAULT_ATTR_INITIALIZER {					\
 44		.interval = 1,						\
 45		.times = ATOMIC_INIT(1),				\
 46		.require_end = ULONG_MAX,				\
 47		.stacktrace_depth = 32,					\
 48		.ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,	\
 49		.verbose = 2,						\
 50		.dname = NULL,						\
 51	}
 52
 53#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
 54int setup_fault_attr(struct fault_attr *attr, char *str);
 55bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
 56bool should_fail(struct fault_attr *attr, ssize_t size);
 57
 58#else /* CONFIG_FAULT_INJECTION */
 59
 60struct fault_attr {
 61};
 62
 63#define DECLARE_FAULT_ATTR(name) struct fault_attr name = {}
 64
 65static inline int setup_fault_attr(struct fault_attr *attr, char *str)
 66{
 67	return 0; /* Note: 0 means error for __setup() handlers! */
 68}
 69static inline bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags)
 70{
 71	return false;
 72}
 73static inline bool should_fail(struct fault_attr *attr, ssize_t size)
 74{
 75	return false;
 76}
 77
 78#endif /* CONFIG_FAULT_INJECTION */
 79
 80#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 81
 82struct dentry *fault_create_debugfs_attr(const char *name,
 83			struct dentry *parent, struct fault_attr *attr);
 84
 85#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
 86
 87static inline struct dentry *fault_create_debugfs_attr(const char *name,
 88			struct dentry *parent, struct fault_attr *attr)
 89{
 90	return ERR_PTR(-ENODEV);
 91}
 92
 93#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
 94
 95#ifdef CONFIG_FAULT_INJECTION_CONFIGFS
 96
 97struct fault_config {
 98	struct fault_attr attr;
 99	struct config_group group;
100};
101
102void fault_config_init(struct fault_config *config, const char *name);
103
104#else /* CONFIG_FAULT_INJECTION_CONFIGFS */
105
106struct fault_config {
107};
108
109static inline void fault_config_init(struct fault_config *config,
110			const char *name)
111{
112}
113
114#endif /* CONFIG_FAULT_INJECTION_CONFIGFS */
115
116#ifdef CONFIG_FAIL_PAGE_ALLOC
117bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
118#else
119static inline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
120{
121	return false;
122}
123#endif /* CONFIG_FAIL_PAGE_ALLOC */
124
125#ifdef CONFIG_FAILSLAB
126int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
127#else
128static inline int should_failslab(struct kmem_cache *s, gfp_t gfpflags)
129{
130	return false;
131}
132#endif /* CONFIG_FAILSLAB */
133
134#endif /* _LINUX_FAULT_INJECT_H */
~/ Read-only file preview.