diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/raid_class.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/linux/raid_class.h b/include/linux/raid_class.h new file mode 100644 index 000000000000..a71123c28272 --- /dev/null +++ b/include/linux/raid_class.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | */ | ||
3 | #include <linux/transport_class.h> | ||
4 | |||
5 | struct raid_template { | ||
6 | struct transport_container raid_attrs; | ||
7 | }; | ||
8 | |||
9 | struct raid_function_template { | ||
10 | void *cookie; | ||
11 | int (*is_raid)(struct device *); | ||
12 | void (*get_resync)(struct device *); | ||
13 | void (*get_state)(struct device *); | ||
14 | }; | ||
15 | |||
16 | enum raid_state { | ||
17 | RAID_ACTIVE = 1, | ||
18 | RAID_DEGRADED, | ||
19 | RAID_RESYNCING, | ||
20 | RAID_OFFLINE, | ||
21 | }; | ||
22 | |||
23 | struct raid_data { | ||
24 | struct list_head component_list; | ||
25 | int component_count; | ||
26 | int level; | ||
27 | enum raid_state state; | ||
28 | int resync; | ||
29 | }; | ||
30 | |||
31 | #define DEFINE_RAID_ATTRIBUTE(type, attr) \ | ||
32 | static inline void \ | ||
33 | raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \ | ||
34 | struct class_device *cdev = \ | ||
35 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ | ||
36 | struct raid_data *rd; \ | ||
37 | BUG_ON(!cdev); \ | ||
38 | rd = class_get_devdata(cdev); \ | ||
39 | rd->attr = value; \ | ||
40 | } \ | ||
41 | static inline type \ | ||
42 | raid_get_##attr(struct raid_template *r, struct device *dev) { \ | ||
43 | struct class_device *cdev = \ | ||
44 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ | ||
45 | struct raid_data *rd; \ | ||
46 | BUG_ON(!cdev); \ | ||
47 | rd = class_get_devdata(cdev); \ | ||
48 | return rd->attr; \ | ||
49 | } | ||
50 | |||
51 | DEFINE_RAID_ATTRIBUTE(int, level) | ||
52 | DEFINE_RAID_ATTRIBUTE(int, resync) | ||
53 | DEFINE_RAID_ATTRIBUTE(enum raid_state, state) | ||
54 | |||
55 | struct raid_template *raid_class_attach(struct raid_function_template *); | ||
56 | void raid_class_release(struct raid_template *); | ||
57 | |||
58 | void raid_component_add(struct raid_template *, struct device *, | ||
59 | struct device *); | ||