raid_class.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. */
  3. #include <linux/transport_class.h>
  4. struct raid_template {
  5. struct transport_container raid_attrs;
  6. };
  7. struct raid_function_template {
  8. void *cookie;
  9. int (*is_raid)(struct device *);
  10. void (*get_resync)(struct device *);
  11. void (*get_state)(struct device *);
  12. };
  13. enum raid_state {
  14. RAID_ACTIVE = 1,
  15. RAID_DEGRADED,
  16. RAID_RESYNCING,
  17. RAID_OFFLINE,
  18. };
  19. struct raid_data {
  20. struct list_head component_list;
  21. int component_count;
  22. int level;
  23. enum raid_state state;
  24. int resync;
  25. };
  26. #define DEFINE_RAID_ATTRIBUTE(type, attr) \
  27. static inline void \
  28. raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
  29. struct class_device *cdev = \
  30. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  31. struct raid_data *rd; \
  32. BUG_ON(!cdev); \
  33. rd = class_get_devdata(cdev); \
  34. rd->attr = value; \
  35. } \
  36. static inline type \
  37. raid_get_##attr(struct raid_template *r, struct device *dev) { \
  38. struct class_device *cdev = \
  39. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  40. struct raid_data *rd; \
  41. BUG_ON(!cdev); \
  42. rd = class_get_devdata(cdev); \
  43. return rd->attr; \
  44. }
  45. DEFINE_RAID_ATTRIBUTE(int, level)
  46. DEFINE_RAID_ATTRIBUTE(int, resync)
  47. DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
  48. struct raid_template *raid_class_attach(struct raid_function_template *);
  49. void raid_class_release(struct raid_template *);
  50. void raid_component_add(struct raid_template *, struct device *,
  51. struct device *);