blob: ec8655514283ec722f2bdd1360e1435be24dca7d [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,
Moore, Eric8e32ca42006-01-04 14:58:43 -070034 RAID_LEVEL_10,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +053035 RAID_LEVEL_1E,
James Bottomleyb1081ea2005-11-06 11:59:08 -060036 RAID_LEVEL_3,
37 RAID_LEVEL_4,
38 RAID_LEVEL_5,
Moore, Eric8e32ca42006-01-04 14:58:43 -070039 RAID_LEVEL_50,
James Bottomleyb1081ea2005-11-06 11:59:08 -060040 RAID_LEVEL_6,
Hannes Reinecke34e81f72018-01-24 09:07:58 +010041 RAID_LEVEL_JBOD,
James Bottomley61a7afa2005-08-16 18:27:34 -050042};
43
44struct raid_data {
45 struct list_head component_list;
46 int component_count;
James Bottomleyb1081ea2005-11-06 11:59:08 -060047 enum raid_level level;
James Bottomley61a7afa2005-08-16 18:27:34 -050048 enum raid_state state;
49 int resync;
50};
51
James Bottomleyb1081ea2005-11-06 11:59:08 -060052/* resync complete goes from 0 to this */
53#define RAID_MAX_RESYNC (10000)
54
James Bottomley61a7afa2005-08-16 18:27:34 -050055#define DEFINE_RAID_ATTRIBUTE(type, attr) \
56static inline void \
57raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
Tony Jonesee959b02008-02-22 00:13:36 +010058 struct device *device = \
James Bottomley61a7afa2005-08-16 18:27:34 -050059 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
60 struct raid_data *rd; \
Tony Jonesee959b02008-02-22 00:13:36 +010061 BUG_ON(!device); \
62 rd = dev_get_drvdata(device); \
James Bottomley61a7afa2005-08-16 18:27:34 -050063 rd->attr = value; \
64} \
65static inline type \
66raid_get_##attr(struct raid_template *r, struct device *dev) { \
Tony Jonesee959b02008-02-22 00:13:36 +010067 struct device *device = \
James Bottomley61a7afa2005-08-16 18:27:34 -050068 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
69 struct raid_data *rd; \
Tony Jonesee959b02008-02-22 00:13:36 +010070 BUG_ON(!device); \
71 rd = dev_get_drvdata(device); \
James Bottomley61a7afa2005-08-16 18:27:34 -050072 return rd->attr; \
73}
74
James Bottomleyb1081ea2005-11-06 11:59:08 -060075DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
James Bottomley61a7afa2005-08-16 18:27:34 -050076DEFINE_RAID_ATTRIBUTE(int, resync)
77DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
78
79struct raid_template *raid_class_attach(struct raid_function_template *);
80void raid_class_release(struct raid_template *);
81
Jeff Garziked542be2006-10-04 07:05:11 -040082int __must_check raid_component_add(struct raid_template *, struct device *,
83 struct device *);
84