fault-inject.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. enum fault_flags {
  30. FAULT_NOWARN = 1 << 0,
  31. };
  32. #define FAULT_ATTR_INITIALIZER { \
  33. .interval = 1, \
  34. .times = ATOMIC_INIT(1), \
  35. .require_end = ULONG_MAX, \
  36. .stacktrace_depth = 32, \
  37. .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED, \
  38. .verbose = 2, \
  39. .dname = NULL, \
  40. }
  41. #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
  42. int setup_fault_attr(struct fault_attr *attr, char *str);
  43. bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags);
  44. bool should_fail(struct fault_attr *attr, ssize_t size);
  45. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  46. struct dentry *fault_create_debugfs_attr(const char *name,
  47. struct dentry *parent, struct fault_attr *attr);
  48. #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  49. static inline struct dentry *fault_create_debugfs_attr(const char *name,
  50. struct dentry *parent, struct fault_attr *attr)
  51. {
  52. return ERR_PTR(-ENODEV);
  53. }
  54. #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  55. #endif /* CONFIG_FAULT_INJECTION */
  56. struct kmem_cache;
  57. bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order);
  58. int should_failslab(struct kmem_cache *s, gfp_t gfpflags);
  59. #ifdef CONFIG_FAILSLAB
  60. extern bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags);
  61. #else
  62. static inline bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags)
  63. {
  64. return false;
  65. }
  66. #endif /* CONFIG_FAILSLAB */
  67. #endif /* _LINUX_FAULT_INJECT_H */