Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * raid_class.h - a generic raid visualisation class
0004  *
0005  * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
0006  */
0007 #include <linux/transport_class.h>
0008 
0009 struct raid_template {
0010     struct transport_container raid_attrs;
0011 };
0012 
0013 struct raid_function_template {
0014     void *cookie;
0015     int (*is_raid)(struct device *);
0016     void (*get_resync)(struct device *);
0017     void (*get_state)(struct device *);
0018 };
0019 
0020 enum raid_state {
0021     RAID_STATE_UNKNOWN = 0,
0022     RAID_STATE_ACTIVE,
0023     RAID_STATE_DEGRADED,
0024     RAID_STATE_RESYNCING,
0025     RAID_STATE_OFFLINE,
0026 };
0027 
0028 enum raid_level {
0029     RAID_LEVEL_UNKNOWN = 0,
0030     RAID_LEVEL_LINEAR,
0031     RAID_LEVEL_0,
0032     RAID_LEVEL_1,
0033     RAID_LEVEL_10,
0034     RAID_LEVEL_1E,
0035     RAID_LEVEL_3,
0036     RAID_LEVEL_4,
0037     RAID_LEVEL_5,
0038     RAID_LEVEL_50,
0039     RAID_LEVEL_6,
0040     RAID_LEVEL_JBOD,
0041 };
0042 
0043 struct raid_data {
0044     struct list_head component_list;
0045     int component_count;
0046     enum raid_level level;
0047     enum raid_state state;
0048     int resync;
0049 };
0050 
0051 /* resync complete goes from 0 to this */
0052 #define RAID_MAX_RESYNC     (10000)
0053 
0054 #define DEFINE_RAID_ATTRIBUTE(type, attr)                     \
0055 static inline void                                \
0056 raid_set_##attr(struct raid_template *r, struct device *dev, type value) {    \
0057     struct device *device =                           \
0058         attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
0059     struct raid_data *rd;                             \
0060     BUG_ON(!device);                              \
0061     rd = dev_get_drvdata(device);                         \
0062     rd->attr = value;                             \
0063 }                                         \
0064 static inline type                                \
0065 raid_get_##attr(struct raid_template *r, struct device *dev) {            \
0066     struct device *device =                           \
0067         attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
0068     struct raid_data *rd;                             \
0069     BUG_ON(!device);                              \
0070     rd = dev_get_drvdata(device);                         \
0071     return rd->attr;                              \
0072 }
0073 
0074 DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
0075 DEFINE_RAID_ATTRIBUTE(int, resync)
0076 DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
0077     
0078 struct raid_template *raid_class_attach(struct raid_function_template *);
0079 void raid_class_release(struct raid_template *);
0080 
0081 int __must_check raid_component_add(struct raid_template *, struct device *,
0082                     struct device *);
0083