fault-inject.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <linux/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. };
  25. #define FAULT_ATTR_INITIALIZER { \
  26. .interval = 1, \
  27. .times = ATOMIC_INIT(1), \
  28. .require_end = ULONG_MAX, \
  29. .stacktrace_depth = 32, \
  30. .verbose = 2, \
  31. }
  32. #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
  33. int setup_fault_attr(struct fault_attr *attr, char *str);
  34. bool should_fail(struct fault_attr *attr, ssize_t size);
  35. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  36. struct dentry *fault_create_debugfs_attr(const char *name,
  37. struct dentry *parent, struct fault_attr *attr);
  38. #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  39. static inline struct dentry *fault_create_debugfs_attr(const char *name,
  40. struct dentry *parent, struct fault_attr *attr)
  41. {
  42. return ERR_PTR(-ENODEV);
  43. }
  44. #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  45. #endif /* CONFIG_FAULT_INJECTION */
  46. #ifdef CONFIG_FAILSLAB
  47. extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags);
  48. #else
  49. static inline bool should_failslab(size_t size, gfp_t gfpflags,
  50. unsigned long flags)
  51. {
  52. return false;
  53. }
  54. #endif /* CONFIG_FAILSLAB */
  55. #endif /* _LINUX_FAULT_INJECT_H */