Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_FAULT_INJECT_H
0003 #define _LINUX_FAULT_INJECT_H
0004 
0005 #ifdef CONFIG_FAULT_INJECTION
0006 
0007 #include <linux/types.h>
0008 #include <linux/debugfs.h>
0009 #include <linux/ratelimit.h>
0010 #include <linux/atomic.h>
0011 
0012 /*
0013  * For explanation of the elements of this struct, see
0014  * Documentation/fault-injection/fault-injection.rst
0015  */
0016 struct fault_attr {
0017     unsigned long probability;
0018     unsigned long interval;
0019     atomic_t times;
0020     atomic_t space;
0021     unsigned long verbose;
0022     bool task_filter;
0023     bool no_warn;
0024     unsigned long stacktrace_depth;
0025     unsigned long require_start;
0026     unsigned long require_end;
0027     unsigned long reject_start;
0028     unsigned long reject_end;
0029 
0030     unsigned long count;
0031     struct ratelimit_state ratelimit_state;
0032     struct dentry *dname;
0033 };
0034 
0035 #define FAULT_ATTR_INITIALIZER {                    \
0036         .interval = 1,                      \
0037         .times = ATOMIC_INIT(1),                \
0038         .require_end = ULONG_MAX,               \
0039         .stacktrace_depth = 32,                 \
0040         .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,   \
0041         .verbose = 2,                       \
0042         .dname = NULL,                      \
0043         .no_warn = false,                   \
0044     }
0045 
0046 #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
0047 int setup_fault_attr(struct fault_attr *attr, char *str);
0048 bool should_fail(struct fault_attr *attr, ssize_t size);
0049 
0050 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
0051 
0052 struct dentry *fault_create_debugfs_attr(const char *name,
0053             struct dentry *parent, struct fault_attr *attr);
0054 
0055 #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
0056 
0057 static inline struct dentry *fault_create_debugfs_attr(const char *name,
0058             struct dentry *parent, struct fault_attr *attr)
0059 {
0060     return ERR_PTR(-ENODEV);
0061 }
0062 
0063 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
0064 
0065 #endif /* CONFIG_FAULT_INJECTION */
0066 
0067 struct kmem_cache;
0068 
0069 bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
0070 
0071 int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
0072 #ifdef CONFIG_FAILSLAB
0073 extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
0074 #else
0075 static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
0076 {
0077     return false;
0078 }
0079 #endif /* CONFIG_FAILSLAB */
0080 
0081 #endif /* _LINUX_FAULT_INJECT_H */