fault-inject.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. unsigned long count;
  18. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  19. struct {
  20. struct dentry *dir;
  21. struct dentry *probability_file;
  22. struct dentry *interval_file;
  23. struct dentry *times_file;
  24. struct dentry *space_file;
  25. struct dentry *verbose_file;
  26. } dentries;
  27. #endif
  28. };
  29. #define FAULT_ATTR_INITIALIZER { \
  30. .interval = 1, \
  31. .times = ATOMIC_INIT(1), \
  32. }
  33. #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
  34. int setup_fault_attr(struct fault_attr *attr, char *str);
  35. void should_fail_srandom(unsigned long entropy);
  36. int should_fail(struct fault_attr *attr, ssize_t size);
  37. #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
  38. int init_fault_attr_dentries(struct fault_attr *attr, const char *name);
  39. void cleanup_fault_attr_dentries(struct fault_attr *attr);
  40. #else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  41. static inline int init_fault_attr_dentries(struct fault_attr *attr,
  42. const char *name)
  43. {
  44. return -ENODEV;
  45. }
  46. static inline void cleanup_fault_attr_dentries(struct fault_attr *attr)
  47. {
  48. }
  49. #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
  50. #endif /* CONFIG_FAULT_INJECTION */
  51. #endif /* _LINUX_FAULT_INJECT_H */