fault-inject.h 1.8 KB

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