raid_class.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_3,
  32. RAID_LEVEL_4,
  33. RAID_LEVEL_5,
  34. RAID_LEVEL_50,
  35. RAID_LEVEL_6,
  36. };
  37. struct raid_data {
  38. struct list_head component_list;
  39. int component_count;
  40. enum raid_level level;
  41. enum raid_state state;
  42. int resync;
  43. };
  44. /* resync complete goes from 0 to this */
  45. #define RAID_MAX_RESYNC (10000)
  46. #define DEFINE_RAID_ATTRIBUTE(type, attr) \
  47. static inline void \
  48. raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
  49. struct class_device *cdev = \
  50. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  51. struct raid_data *rd; \
  52. BUG_ON(!cdev); \
  53. rd = class_get_devdata(cdev); \
  54. rd->attr = value; \
  55. } \
  56. static inline type \
  57. raid_get_##attr(struct raid_template *r, struct device *dev) { \
  58. struct class_device *cdev = \
  59. attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
  60. struct raid_data *rd; \
  61. BUG_ON(!cdev); \
  62. rd = class_get_devdata(cdev); \
  63. return rd->attr; \
  64. }
  65. DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
  66. DEFINE_RAID_ATTRIBUTE(int, resync)
  67. DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
  68. struct raid_template *raid_class_attach(struct raid_function_template *);
  69. void raid_class_release(struct raid_template *);
  70. int __must_check raid_component_add(struct raid_template *, struct device *,
  71. struct device *);