blob: 48831eac291075b31cb45d766cc8f76b6c9cdaac [file] [log] [blame]
James Bottomley61a7afa2005-08-16 18:27:34 -05001/*
James Bottomleyb1081ea2005-11-06 11:59:08 -06002 * 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
James Bottomley61a7afa2005-08-16 18:27:34 -05007 */
8#include <linux/transport_class.h>
9
10struct raid_template {
11 struct transport_container raid_attrs;
12};
13
14struct raid_function_template {
15 void *cookie;
16 int (*is_raid)(struct device *);
17 void (*get_resync)(struct device *);
18 void (*get_state)(struct device *);
19};
20
21enum raid_state {
James Bottomleyb1081ea2005-11-06 11:59:08 -060022 RAID_STATE_UNKNOWN = 0,
23 RAID_STATE_ACTIVE,
24 RAID_STATE_DEGRADED,
25 RAID_STATE_RESYNCING,
26 RAID_STATE_OFFLINE,
27};
28
29enum raid_level {
30 RAID_LEVEL_UNKNOWN = 0,
31 RAID_LEVEL_LINEAR,
32 RAID_LEVEL_0,
33 RAID_LEVEL_1,
34 RAID_LEVEL_3,
35 RAID_LEVEL_4,
36 RAID_LEVEL_5,
37 RAID_LEVEL_6,
James Bottomley61a7afa2005-08-16 18:27:34 -050038};
39
40struct raid_data {
41 struct list_head component_list;
42 int component_count;
James Bottomleyb1081ea2005-11-06 11:59:08 -060043 enum raid_level level;
James Bottomley61a7afa2005-08-16 18:27:34 -050044 enum raid_state state;
45 int resync;
46};
47
James Bottomleyb1081ea2005-11-06 11:59:08 -060048/* resync complete goes from 0 to this */
49#define RAID_MAX_RESYNC (10000)
50
James Bottomley61a7afa2005-08-16 18:27:34 -050051#define DEFINE_RAID_ATTRIBUTE(type, attr) \
52static inline void \
53raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
54 struct class_device *cdev = \
55 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
56 struct raid_data *rd; \
57 BUG_ON(!cdev); \
58 rd = class_get_devdata(cdev); \
59 rd->attr = value; \
60} \
61static inline type \
62raid_get_##attr(struct raid_template *r, struct device *dev) { \
63 struct class_device *cdev = \
64 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
65 struct raid_data *rd; \
66 BUG_ON(!cdev); \
67 rd = class_get_devdata(cdev); \
68 return rd->attr; \
69}
70
James Bottomleyb1081ea2005-11-06 11:59:08 -060071DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
James Bottomley61a7afa2005-08-16 18:27:34 -050072DEFINE_RAID_ATTRIBUTE(int, resync)
73DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
74
75struct raid_template *raid_class_attach(struct raid_function_template *);
76void raid_class_release(struct raid_template *);
77
78void raid_component_add(struct raid_template *, struct device *,
79 struct device *);