fault-inject.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_FAULT_INJECT_H
  3. #define _LINUX_FAULT_INJECT_H
  4. #ifdef CONFIG_FAULT_INJECTION
  5. #include <linux/types.h>
  6. #include <linux/debugfs.h>
  7. #include <linux/ratelimit.h>
  8. #include <linux/atomic.h>
  9. /*
  10. * For explanation of the elements of this struct, see
  11. * Documentation/fault-injection/fault-injection.rst
  12. */
  13. struct fault_attr {
  14. unsigned long probability;
  15. unsigned long interval;
  16. atomic_t times;
  17. atomic_t space;
  18. unsigned long verbose;
  19. bool task_filter;
  20. unsigned long stacktrace_depth;
  21. unsigned long require_start;
  22. unsigned long require_end;
  23. unsigned long reject_start;
  24. unsigned long reject_end;
  25. unsigned long count;
  26. struct ratelimit_state ratelimit_state;
  27. struct dentry *dname;
  28. };
  29. #define FAULT_ATTR_INITIALIZER { \
  30. .interval = 1, \
  31. .times = ATOMIC_INIT(1), \
  32. .require_end = ULONG_MAX, \
  33. .stacktrace_depth = 32, \
  34. .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
  35. .verbose = 2, \
  36. .dname = NULL, \
  37. }
  38. #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
  39. int setup_fault_attr(struct fault_attr *attr, char *str);
  40. bool should_fail(struct fault_attr *attr, ssize_t size);
  41. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  42. struct dentry *fault_create_debugfs_attr(const char *name,
  43. struct dentry *parent, struct fault_attr *attr);
  44. #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  45. static inline struct dentry *fault_create_debugfs_attr(const char *name,
  46. struct dentry *parent, struct fault_attr *attr)
  47. {
  48. return ERR_PTR(-ENODEV);
  49. }
  50. #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  51. #endif /* CONFIG_FAULT_INJECTION */
  52. struct kmem_cache;
  53. int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
  54. #ifdef CONFIG_FAILSLAB
  55. extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
  56. #else
  57. static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
  58. {
  59. return false;
  60. }
  61. #endif /* CONFIG_FAILSLAB */
  62. #endif /* _LINUX_FAULT_INJECT_H */