James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 1 | /* |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 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 |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 7 | */ |
| 8 | #include <linux/transport_class.h> |
| 9 | |
| 10 | struct raid_template { |
| 11 | struct transport_container raid_attrs; |
| 12 | }; |
| 13 | |
| 14 | struct 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 | |
| 21 | enum raid_state { |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 22 | RAID_STATE_UNKNOWN = 0, |
| 23 | RAID_STATE_ACTIVE, |
| 24 | RAID_STATE_DEGRADED, |
| 25 | RAID_STATE_RESYNCING, |
| 26 | RAID_STATE_OFFLINE, |
| 27 | }; |
| 28 | |
| 29 | enum raid_level { |
| 30 | RAID_LEVEL_UNKNOWN = 0, |
| 31 | RAID_LEVEL_LINEAR, |
| 32 | RAID_LEVEL_0, |
| 33 | RAID_LEVEL_1, |
Moore, Eric | 8e32ca4 | 2006-01-04 14:58:43 -0700 | [diff] [blame] | 34 | RAID_LEVEL_10, |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 35 | RAID_LEVEL_3, |
| 36 | RAID_LEVEL_4, |
| 37 | RAID_LEVEL_5, |
Moore, Eric | 8e32ca4 | 2006-01-04 14:58:43 -0700 | [diff] [blame] | 38 | RAID_LEVEL_50, |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 39 | RAID_LEVEL_6, |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct raid_data { |
| 43 | struct list_head component_list; |
| 44 | int component_count; |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 45 | enum raid_level level; |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 46 | enum raid_state state; |
| 47 | int resync; |
| 48 | }; |
| 49 | |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 50 | /* resync complete goes from 0 to this */ |
| 51 | #define RAID_MAX_RESYNC (10000) |
| 52 | |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 53 | #define DEFINE_RAID_ATTRIBUTE(type, attr) \ |
| 54 | static inline void \ |
| 55 | raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame^] | 56 | struct device *device = \ |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 57 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ |
| 58 | struct raid_data *rd; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame^] | 59 | BUG_ON(!device); \ |
| 60 | rd = dev_get_drvdata(device); \ |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 61 | rd->attr = value; \ |
| 62 | } \ |
| 63 | static inline type \ |
| 64 | raid_get_##attr(struct raid_template *r, struct device *dev) { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame^] | 65 | struct device *device = \ |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 66 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ |
| 67 | struct raid_data *rd; \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame^] | 68 | BUG_ON(!device); \ |
| 69 | rd = dev_get_drvdata(device); \ |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 70 | return rd->attr; \ |
| 71 | } |
| 72 | |
James Bottomley | b1081ea | 2005-11-06 11:59:08 -0600 | [diff] [blame] | 73 | DEFINE_RAID_ATTRIBUTE(enum raid_level, level) |
James Bottomley | 61a7afa | 2005-08-16 18:27:34 -0500 | [diff] [blame] | 74 | DEFINE_RAID_ATTRIBUTE(int, resync) |
| 75 | DEFINE_RAID_ATTRIBUTE(enum raid_state, state) |
| 76 | |
| 77 | struct raid_template *raid_class_attach(struct raid_function_template *); |
| 78 | void raid_class_release(struct raid_template *); |
| 79 | |
Jeff Garzik | ed542be | 2006-10-04 07:05:11 -0400 | [diff] [blame] | 80 | int __must_check raid_component_add(struct raid_template *, struct device *, |
| 81 | struct device *); |
| 82 | |