raid_class.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * raid_class.h - a generic raid visualisation class
  3. *
  4. * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
  5. *
  6. * This file is licensed under GPLv2
  7. */
  8. #include <linux/transport_class.h>
  9. struct raid_template {
  10. struct transport_container raid_attrs;
  11. };
  12. struct raid_function_template {
  13. void *cookie;
  14. int (*is_raid)(struct device *);
  15. void (*get_resync)(struct device *);
  16. void (*get_state)(struct device *);
  17. };
  18. enum raid_state {
  19. RAID_STATE_UNKNOWN = 0,
  20. RAID_STATE_ACTIVE,
  21. RAID_STATE_DEGRADED,
  22. RAID_STATE_RESYNCING,
  23. RAID_STATE_OFFLINE,
  24. };
  25. enum raid_level {
  26. RAID_LEVEL_UNKNOWN = 0,
  27. RAID_LEVEL_LINEAR,
  28. RAID_LEVEL_0,
  29. RAID_LEVEL_1,
  30. RAID_LEVEL_10,
  31. RAID_LEVEL_1E,
  32. RAID_LEVEL_3,
  33. RAID_LEVEL_4,
  34. RAID_LEVEL_5,
  35. RAID_LEVEL_50,
  36. RAID_LEVEL_6,
  37. };
  38. struct raid_data {
  39. struct list_head component_list;
  40. int component_count;
  41. enum raid_level level;
  42. enum raid_state state;
  43. int resync;
  44. };
  45. /* resync complete goes from 0 to this */
  46. #define RAID_MAX_RESYNC (10000)
  47. #define DEFINE_RAID_ATTRIBUTE(type, attr) \
  48. static inline void \
  49. raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
  50. struct device *device = \
  51. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  52. struct raid_data *rd; \
  53. BUG_ON(!device); \
  54. rd = dev_get_drvdata(device); \
  55. rd->attr = value; \
  56. } \
  57. static inline type \
  58. raid_get_##attr(struct raid_template *r, struct device *dev) { \
  59. struct device *device = \
  60. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  61. struct raid_data *rd; \
  62. BUG_ON(!device); \
  63. rd = dev_get_drvdata(device); \
  64. return rd->attr; \
  65. }
  66. DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
  67. DEFINE_RAID_ATTRIBUTE(int, resync)
  68. DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
  69. struct raid_template *raid_class_attach(struct raid_function_template *);
  70. void raid_class_release(struct raid_template *);
  71. int __must_check raid_component_add(struct raid_template *, struct device *,
  72. struct device *);