fault-inject.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _LINUX_FAULT_INJECT_H
  2. #define _LINUX_FAULT_INJECT_H
  3. #ifdef CONFIG_FAULT_INJECTION
  4. #include <linux/types.h>
  5. #include <linux/debugfs.h>
  6. #include <asm/atomic.h>
  7. /*
  8. * For explanation of the elements of this struct, see
  9. * Documentation/fault-injection/fault-injection.txt
  10. */
  11. struct fault_attr {
  12. unsigned long probability;
  13. unsigned long interval;
  14. atomic_t times;
  15. atomic_t space;
  16. unsigned long verbose;
  17. u32 task_filter;
  18. unsigned long stacktrace_depth;
  19. unsigned long require_start;
  20. unsigned long require_end;
  21. unsigned long reject_start;
  22. unsigned long reject_end;
  23. unsigned long count;
  24. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  25. struct {
  26. struct dentry *dir;
  27. struct dentry *probability_file;
  28. struct dentry *interval_file;
  29. struct dentry *times_file;
  30. struct dentry *space_file;
  31. struct dentry *verbose_file;
  32. struct dentry *task_filter_file;
  33. struct dentry *stacktrace_depth_file;
  34. struct dentry *require_start_file;
  35. struct dentry *require_end_file;
  36. struct dentry *reject_start_file;
  37. struct dentry *reject_end_file;
  38. } dentries;
  39. #endif
  40. };
  41. #define FAULT_ATTR_INITIALIZER { \
  42. .interval = 1, \
  43. .times = ATOMIC_INIT(1), \
  44. .require_end = ULONG_MAX, \
  45. .stacktrace_depth = 32, \
  46. .verbose = 2, \
  47. }
  48. #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
  49. int setup_fault_attr(struct fault_attr *attr, char *str);
  50. void should_fail_srandom(unsigned long entropy);
  51. bool should_fail(struct fault_attr *attr, ssize_t size);
  52. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  53. int init_fault_attr_dentries(struct fault_attr *attr, const char *name);
  54. void cleanup_fault_attr_dentries(struct fault_attr *attr);
  55. #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  56. static inline int init_fault_attr_dentries(struct fault_attr *attr,
  57. const char *name)
  58. {
  59. return -ENODEV;
  60. }
  61. static inline void cleanup_fault_attr_dentries(struct fault_attr *attr)
  62. {
  63. }
  64. #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  65. #endif /* CONFIG_FAULT_INJECTION */
  66. #ifdef CONFIG_FAILSLAB
  67. extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags);
  68. #else
  69. static inline bool should_failslab(size_t size, gfp_t gfpflags,
  70. unsigned long flags)
  71. {
  72. return false;
  73. }
  74. #endif /* CONFIG_FAILSLAB */
  75. #endif /* _LINUX_FAULT_INJECT_H */