diff options
author | James Bottomley <jejb@mulgrave.(none)> | 2005-11-08 12:50:26 -0500 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.(none)> | 2005-11-08 12:50:26 -0500 |
commit | 383f9749505cef0a30dbd7109db7fe469aa64753 (patch) | |
tree | 9e88d648396ac99a90d12ccf5471d001e87c65ae /drivers/scsi/raid_class.c | |
parent | f093182d313edde9b1f86dbdaf40ba4da2dbd0e7 (diff) | |
parent | 3da8b713da723e78a03f0404beedf3cc6f4f860b (diff) |
Merge by hand (conflicts between pending drivers and kfree cleanups)
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/raid_class.c')
-rw-r--r-- | drivers/scsi/raid_class.c | 96 |
1 files changed, 72 insertions, 24 deletions
diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c index caa0c3629626..5b1c12041a4f 100644 --- a/drivers/scsi/raid_class.c +++ b/drivers/scsi/raid_class.c | |||
@@ -1,5 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | * RAID Attributes | 2 | * raid_class.c - implementation of a simple raid visualisation class |
3 | * | ||
4 | * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com> | ||
5 | * | ||
6 | * This file is licensed under GPLv2 | ||
7 | * | ||
8 | * This class is designed to allow raid attributes to be visualised and | ||
9 | * manipulated in a form independent of the underlying raid. Ultimately this | ||
10 | * should work for both hardware and software raids. | ||
3 | */ | 11 | */ |
4 | #include <linux/init.h> | 12 | #include <linux/init.h> |
5 | #include <linux/module.h> | 13 | #include <linux/module.h> |
@@ -24,7 +32,7 @@ struct raid_internal { | |||
24 | 32 | ||
25 | struct raid_component { | 33 | struct raid_component { |
26 | struct list_head node; | 34 | struct list_head node; |
27 | struct device *dev; | 35 | struct class_device cdev; |
28 | int num; | 36 | int num; |
29 | }; | 37 | }; |
30 | 38 | ||
@@ -74,11 +82,10 @@ static int raid_setup(struct transport_container *tc, struct device *dev, | |||
74 | 82 | ||
75 | BUG_ON(class_get_devdata(cdev)); | 83 | BUG_ON(class_get_devdata(cdev)); |
76 | 84 | ||
77 | rd = kmalloc(sizeof(*rd), GFP_KERNEL); | 85 | rd = kzalloc(sizeof(*rd), GFP_KERNEL); |
78 | if (!rd) | 86 | if (!rd) |
79 | return -ENOMEM; | 87 | return -ENOMEM; |
80 | 88 | ||
81 | memset(rd, 0, sizeof(*rd)); | ||
82 | INIT_LIST_HEAD(&rd->component_list); | 89 | INIT_LIST_HEAD(&rd->component_list); |
83 | class_set_devdata(cdev, rd); | 90 | class_set_devdata(cdev, rd); |
84 | 91 | ||
@@ -90,15 +97,15 @@ static int raid_remove(struct transport_container *tc, struct device *dev, | |||
90 | { | 97 | { |
91 | struct raid_data *rd = class_get_devdata(cdev); | 98 | struct raid_data *rd = class_get_devdata(cdev); |
92 | struct raid_component *rc, *next; | 99 | struct raid_component *rc, *next; |
100 | dev_printk(KERN_ERR, dev, "RAID REMOVE\n"); | ||
93 | class_set_devdata(cdev, NULL); | 101 | class_set_devdata(cdev, NULL); |
94 | list_for_each_entry_safe(rc, next, &rd->component_list, node) { | 102 | list_for_each_entry_safe(rc, next, &rd->component_list, node) { |
95 | char buf[40]; | ||
96 | snprintf(buf, sizeof(buf), "component-%d", rc->num); | ||
97 | list_del(&rc->node); | 103 | list_del(&rc->node); |
98 | sysfs_remove_link(&cdev->kobj, buf); | 104 | dev_printk(KERN_ERR, rc->cdev.dev, "RAID COMPONENT REMOVE\n"); |
99 | kfree(rc); | 105 | class_device_unregister(&rc->cdev); |
100 | } | 106 | } |
101 | kfree(class_get_devdata(cdev)); | 107 | dev_printk(KERN_ERR, dev, "RAID REMOVE DONE\n"); |
108 | kfree(rd); | ||
102 | return 0; | 109 | return 0; |
103 | } | 110 | } |
104 | 111 | ||
@@ -112,10 +119,11 @@ static struct { | |||
112 | enum raid_state value; | 119 | enum raid_state value; |
113 | char *name; | 120 | char *name; |
114 | } raid_states[] = { | 121 | } raid_states[] = { |
115 | { RAID_ACTIVE, "active" }, | 122 | { RAID_STATE_UNKNOWN, "unknown" }, |
116 | { RAID_DEGRADED, "degraded" }, | 123 | { RAID_STATE_ACTIVE, "active" }, |
117 | { RAID_RESYNCING, "resyncing" }, | 124 | { RAID_STATE_DEGRADED, "degraded" }, |
118 | { RAID_OFFLINE, "offline" }, | 125 | { RAID_STATE_RESYNCING, "resyncing" }, |
126 | { RAID_STATE_OFFLINE, "offline" }, | ||
119 | }; | 127 | }; |
120 | 128 | ||
121 | static const char *raid_state_name(enum raid_state state) | 129 | static const char *raid_state_name(enum raid_state state) |
@@ -132,6 +140,33 @@ static const char *raid_state_name(enum raid_state state) | |||
132 | return name; | 140 | return name; |
133 | } | 141 | } |
134 | 142 | ||
143 | static struct { | ||
144 | enum raid_level value; | ||
145 | char *name; | ||
146 | } raid_levels[] = { | ||
147 | { RAID_LEVEL_UNKNOWN, "unknown" }, | ||
148 | { RAID_LEVEL_LINEAR, "linear" }, | ||
149 | { RAID_LEVEL_0, "raid0" }, | ||
150 | { RAID_LEVEL_1, "raid1" }, | ||
151 | { RAID_LEVEL_3, "raid3" }, | ||
152 | { RAID_LEVEL_4, "raid4" }, | ||
153 | { RAID_LEVEL_5, "raid5" }, | ||
154 | { RAID_LEVEL_6, "raid6" }, | ||
155 | }; | ||
156 | |||
157 | static const char *raid_level_name(enum raid_level level) | ||
158 | { | ||
159 | int i; | ||
160 | char *name = NULL; | ||
161 | |||
162 | for (i = 0; i < sizeof(raid_levels)/sizeof(raid_levels[0]); i++) { | ||
163 | if (raid_levels[i].value == level) { | ||
164 | name = raid_levels[i].name; | ||
165 | break; | ||
166 | } | ||
167 | } | ||
168 | return name; | ||
169 | } | ||
135 | 170 | ||
136 | #define raid_attr_show_internal(attr, fmt, var, code) \ | 171 | #define raid_attr_show_internal(attr, fmt, var, code) \ |
137 | static ssize_t raid_show_##attr(struct class_device *cdev, char *buf) \ | 172 | static ssize_t raid_show_##attr(struct class_device *cdev, char *buf) \ |
@@ -161,11 +196,22 @@ static CLASS_DEVICE_ATTR(attr, S_IRUGO, raid_show_##attr, NULL) | |||
161 | 196 | ||
162 | #define raid_attr_ro(attr) raid_attr_ro_internal(attr, ) | 197 | #define raid_attr_ro(attr) raid_attr_ro_internal(attr, ) |
163 | #define raid_attr_ro_fn(attr) raid_attr_ro_internal(attr, ATTR_CODE(attr)) | 198 | #define raid_attr_ro_fn(attr) raid_attr_ro_internal(attr, ATTR_CODE(attr)) |
164 | #define raid_attr_ro_state(attr) raid_attr_ro_states(attr, attr, ATTR_CODE(attr)) | 199 | #define raid_attr_ro_state(attr) raid_attr_ro_states(attr, attr, ) |
200 | #define raid_attr_ro_state_fn(attr) raid_attr_ro_states(attr, attr, ATTR_CODE(attr)) | ||
201 | |||
165 | 202 | ||
166 | raid_attr_ro(level); | 203 | raid_attr_ro_state(level); |
167 | raid_attr_ro_fn(resync); | 204 | raid_attr_ro_fn(resync); |
168 | raid_attr_ro_state(state); | 205 | raid_attr_ro_state_fn(state); |
206 | |||
207 | static void raid_component_release(struct class_device *cdev) | ||
208 | { | ||
209 | struct raid_component *rc = container_of(cdev, struct raid_component, | ||
210 | cdev); | ||
211 | dev_printk(KERN_ERR, rc->cdev.dev, "COMPONENT RELEASE\n"); | ||
212 | put_device(rc->cdev.dev); | ||
213 | kfree(rc); | ||
214 | } | ||
169 | 215 | ||
170 | void raid_component_add(struct raid_template *r,struct device *raid_dev, | 216 | void raid_component_add(struct raid_template *r,struct device *raid_dev, |
171 | struct device *component_dev) | 217 | struct device *component_dev) |
@@ -175,34 +221,36 @@ void raid_component_add(struct raid_template *r,struct device *raid_dev, | |||
175 | raid_dev); | 221 | raid_dev); |
176 | struct raid_component *rc; | 222 | struct raid_component *rc; |
177 | struct raid_data *rd = class_get_devdata(cdev); | 223 | struct raid_data *rd = class_get_devdata(cdev); |
178 | char buf[40]; | ||
179 | 224 | ||
180 | rc = kmalloc(sizeof(*rc), GFP_KERNEL); | 225 | rc = kzalloc(sizeof(*rc), GFP_KERNEL); |
181 | if (!rc) | 226 | if (!rc) |
182 | return; | 227 | return; |
183 | 228 | ||
184 | INIT_LIST_HEAD(&rc->node); | 229 | INIT_LIST_HEAD(&rc->node); |
185 | rc->dev = component_dev; | 230 | class_device_initialize(&rc->cdev); |
231 | rc->cdev.release = raid_component_release; | ||
232 | rc->cdev.dev = get_device(component_dev); | ||
186 | rc->num = rd->component_count++; | 233 | rc->num = rd->component_count++; |
187 | 234 | ||
188 | snprintf(buf, sizeof(buf), "component-%d", rc->num); | 235 | snprintf(rc->cdev.class_id, sizeof(rc->cdev.class_id), |
236 | "component-%d", rc->num); | ||
189 | list_add_tail(&rc->node, &rd->component_list); | 237 | list_add_tail(&rc->node, &rd->component_list); |
190 | sysfs_create_link(&cdev->kobj, &component_dev->kobj, buf); | 238 | rc->cdev.parent = cdev; |
239 | rc->cdev.class = &raid_class.class; | ||
240 | class_device_add(&rc->cdev); | ||
191 | } | 241 | } |
192 | EXPORT_SYMBOL(raid_component_add); | 242 | EXPORT_SYMBOL(raid_component_add); |
193 | 243 | ||
194 | struct raid_template * | 244 | struct raid_template * |
195 | raid_class_attach(struct raid_function_template *ft) | 245 | raid_class_attach(struct raid_function_template *ft) |
196 | { | 246 | { |
197 | struct raid_internal *i = kmalloc(sizeof(struct raid_internal), | 247 | struct raid_internal *i = kzalloc(sizeof(struct raid_internal), |
198 | GFP_KERNEL); | 248 | GFP_KERNEL); |
199 | int count = 0; | 249 | int count = 0; |
200 | 250 | ||
201 | if (unlikely(!i)) | 251 | if (unlikely(!i)) |
202 | return NULL; | 252 | return NULL; |
203 | 253 | ||
204 | memset(i, 0, sizeof(*i)); | ||
205 | |||
206 | i->f = ft; | 254 | i->f = ft; |
207 | 255 | ||
208 | i->r.raid_attrs.ac.class = &raid_class.class; | 256 | i->r.raid_attrs.ac.class = &raid_class.class; |