enclosure.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * Enclosure Services
  3. *
  4. * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
  5. *
  6. **-----------------------------------------------------------------------------
  7. **
  8. ** This program is free software; you can redistribute it and/or
  9. ** modify it under the terms of the GNU General Public License
  10. ** version 2 as published by the Free Software Foundation.
  11. **
  12. ** This program is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with this program; if not, write to the Free Software
  19. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. **
  21. **-----------------------------------------------------------------------------
  22. */
  23. #include <linux/device.h>
  24. #include <linux/enclosure.h>
  25. #include <linux/err.h>
  26. #include <linux/list.h>
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/mutex.h>
  30. #include <linux/slab.h>
  31. static LIST_HEAD(container_list);
  32. static DEFINE_MUTEX(container_list_lock);
  33. static struct class enclosure_class;
  34. /**
  35. * enclosure_find - find an enclosure given a parent device
  36. * @dev: the parent to match against
  37. * @start: Optional enclosure device to start from (NULL if none)
  38. *
  39. * Looks through the list of registered enclosures to find all those
  40. * with @dev as a parent. Returns NULL if no enclosure is
  41. * found. @start can be used as a starting point to obtain multiple
  42. * enclosures per parent (should begin with NULL and then be set to
  43. * each returned enclosure device). Obtains a reference to the
  44. * enclosure class device which must be released with device_put().
  45. * If @start is not NULL, a reference must be taken on it which is
  46. * released before returning (this allows a loop through all
  47. * enclosures to exit with only the reference on the enclosure of
  48. * interest held). Note that the @dev may correspond to the actual
  49. * device housing the enclosure, in which case no iteration via @start
  50. * is required.
  51. */
  52. struct enclosure_device *enclosure_find(struct device *dev,
  53. struct enclosure_device *start)
  54. {
  55. struct enclosure_device *edev;
  56. mutex_lock(&container_list_lock);
  57. edev = list_prepare_entry(start, &container_list, node);
  58. if (start)
  59. put_device(&start->edev);
  60. list_for_each_entry_continue(edev, &container_list, node) {
  61. struct device *parent = edev->edev.parent;
  62. /* parent might not be immediate, so iterate up to
  63. * the root of the tree if necessary */
  64. while (parent) {
  65. if (parent == dev) {
  66. get_device(&edev->edev);
  67. mutex_unlock(&container_list_lock);
  68. return edev;
  69. }
  70. parent = parent->parent;
  71. }
  72. }
  73. mutex_unlock(&container_list_lock);
  74. return NULL;
  75. }
  76. EXPORT_SYMBOL_GPL(enclosure_find);
  77. /**
  78. * enclosure_for_each_device - calls a function for each enclosure
  79. * @fn: the function to call
  80. * @data: the data to pass to each call
  81. *
  82. * Loops over all the enclosures calling the function.
  83. *
  84. * Note, this function uses a mutex which will be held across calls to
  85. * @fn, so it must have non atomic context, and @fn may (although it
  86. * should not) sleep or otherwise cause the mutex to be held for
  87. * indefinite periods
  88. */
  89. int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
  90. void *data)
  91. {
  92. int error = 0;
  93. struct enclosure_device *edev;
  94. mutex_lock(&container_list_lock);
  95. list_for_each_entry(edev, &container_list, node) {
  96. error = fn(edev, data);
  97. if (error)
  98. break;
  99. }
  100. mutex_unlock(&container_list_lock);
  101. return error;
  102. }
  103. EXPORT_SYMBOL_GPL(enclosure_for_each_device);
  104. /**
  105. * enclosure_register - register device as an enclosure
  106. *
  107. * @dev: device containing the enclosure
  108. * @components: number of components in the enclosure
  109. *
  110. * This sets up the device for being an enclosure. Note that @dev does
  111. * not have to be a dedicated enclosure device. It may be some other type
  112. * of device that additionally responds to enclosure services
  113. */
  114. struct enclosure_device *
  115. enclosure_register(struct device *dev, const char *name, int components,
  116. struct enclosure_component_callbacks *cb)
  117. {
  118. struct enclosure_device *edev =
  119. kzalloc(sizeof(struct enclosure_device) +
  120. sizeof(struct enclosure_component)*components,
  121. GFP_KERNEL);
  122. int err, i;
  123. BUG_ON(!cb);
  124. if (!edev)
  125. return ERR_PTR(-ENOMEM);
  126. edev->components = components;
  127. edev->edev.class = &enclosure_class;
  128. edev->edev.parent = get_device(dev);
  129. edev->cb = cb;
  130. dev_set_name(&edev->edev, "%s", name);
  131. err = device_register(&edev->edev);
  132. if (err)
  133. goto err;
  134. for (i = 0; i < components; i++) {
  135. edev->component[i].number = -1;
  136. edev->component[i].slot = -1;
  137. edev->component[i].power_status = -1;
  138. }
  139. mutex_lock(&container_list_lock);
  140. list_add_tail(&edev->node, &container_list);
  141. mutex_unlock(&container_list_lock);
  142. return edev;
  143. err:
  144. put_device(edev->edev.parent);
  145. kfree(edev);
  146. return ERR_PTR(err);
  147. }
  148. EXPORT_SYMBOL_GPL(enclosure_register);
  149. static struct enclosure_component_callbacks enclosure_null_callbacks;
  150. /**
  151. * enclosure_unregister - remove an enclosure
  152. *
  153. * @edev: the registered enclosure to remove;
  154. */
  155. void enclosure_unregister(struct enclosure_device *edev)
  156. {
  157. int i;
  158. mutex_lock(&container_list_lock);
  159. list_del(&edev->node);
  160. mutex_unlock(&container_list_lock);
  161. for (i = 0; i < edev->components; i++)
  162. if (edev->component[i].number != -1)
  163. device_unregister(&edev->component[i].cdev);
  164. /* prevent any callbacks into service user */
  165. edev->cb = &enclosure_null_callbacks;
  166. device_unregister(&edev->edev);
  167. }
  168. EXPORT_SYMBOL_GPL(enclosure_unregister);
  169. #define ENCLOSURE_NAME_SIZE 64
  170. #define COMPONENT_NAME_SIZE 64
  171. static void enclosure_link_name(struct enclosure_component *cdev, char *name)
  172. {
  173. strcpy(name, "enclosure_device:");
  174. strcat(name, dev_name(&cdev->cdev));
  175. }
  176. static void enclosure_remove_links(struct enclosure_component *cdev)
  177. {
  178. char name[ENCLOSURE_NAME_SIZE];
  179. enclosure_link_name(cdev, name);
  180. /*
  181. * In odd circumstances, like multipath devices, something else may
  182. * already have removed the links, so check for this condition first.
  183. */
  184. if (cdev->dev->kobj.sd)
  185. sysfs_remove_link(&cdev->dev->kobj, name);
  186. if (cdev->cdev.kobj.sd)
  187. sysfs_remove_link(&cdev->cdev.kobj, "device");
  188. }
  189. static int enclosure_add_links(struct enclosure_component *cdev)
  190. {
  191. int error;
  192. char name[ENCLOSURE_NAME_SIZE];
  193. error = sysfs_create_link(&cdev->cdev.kobj, &cdev->dev->kobj, "device");
  194. if (error)
  195. return error;
  196. enclosure_link_name(cdev, name);
  197. error = sysfs_create_link(&cdev->dev->kobj, &cdev->cdev.kobj, name);
  198. if (error)
  199. sysfs_remove_link(&cdev->cdev.kobj, "device");
  200. return error;
  201. }
  202. static void enclosure_release(struct device *cdev)
  203. {
  204. struct enclosure_device *edev = to_enclosure_device(cdev);
  205. put_device(cdev->parent);
  206. kfree(edev);
  207. }
  208. static void enclosure_component_release(struct device *dev)
  209. {
  210. struct enclosure_component *cdev = to_enclosure_component(dev);
  211. if (cdev->dev) {
  212. enclosure_remove_links(cdev);
  213. put_device(cdev->dev);
  214. }
  215. put_device(dev->parent);
  216. }
  217. static struct enclosure_component *
  218. enclosure_component_find_by_name(struct enclosure_device *edev,
  219. const char *name)
  220. {
  221. int i;
  222. const char *cname;
  223. struct enclosure_component *ecomp;
  224. if (!edev || !name || !name[0])
  225. return NULL;
  226. for (i = 0; i < edev->components; i++) {
  227. ecomp = &edev->component[i];
  228. cname = dev_name(&ecomp->cdev);
  229. if (ecomp->number != -1 &&
  230. cname && cname[0] &&
  231. !strcmp(cname, name))
  232. return ecomp;
  233. }
  234. return NULL;
  235. }
  236. static const struct attribute_group *enclosure_component_groups[];
  237. /**
  238. * enclosure_component_alloc - prepare a new enclosure component
  239. * @edev: the enclosure to add the component
  240. * @num: the device number
  241. * @type: the type of component being added
  242. * @name: an optional name to appear in sysfs (leave NULL if none)
  243. *
  244. * The name is optional for enclosures that give their components a unique
  245. * name. If not, leave the field NULL and a name will be assigned.
  246. *
  247. * Returns a pointer to the enclosure component or an error.
  248. */
  249. struct enclosure_component *
  250. enclosure_component_alloc(struct enclosure_device *edev,
  251. unsigned int number,
  252. enum enclosure_component_type type,
  253. const char *name)
  254. {
  255. struct enclosure_component *ecomp;
  256. struct device *cdev;
  257. int i;
  258. char newname[COMPONENT_NAME_SIZE];
  259. if (number >= edev->components)
  260. return ERR_PTR(-EINVAL);
  261. ecomp = &edev->component[number];
  262. if (ecomp->number != -1)
  263. return ERR_PTR(-EINVAL);
  264. ecomp->type = type;
  265. ecomp->number = number;
  266. cdev = &ecomp->cdev;
  267. cdev->parent = get_device(&edev->edev);
  268. if (name && name[0]) {
  269. /* Some hardware (e.g. enclosure in RX300 S6) has components
  270. * with non unique names. Registering duplicates in sysfs
  271. * will lead to warnings during bootup. So make the names
  272. * unique by appending consecutive numbers -1, -2, ... */
  273. i = 1;
  274. snprintf(newname, COMPONENT_NAME_SIZE,
  275. "%s", name);
  276. while (enclosure_component_find_by_name(edev, newname))
  277. snprintf(newname, COMPONENT_NAME_SIZE,
  278. "%s-%i", name, i++);
  279. dev_set_name(cdev, "%s", newname);
  280. } else
  281. dev_set_name(cdev, "%u", number);
  282. cdev->release = enclosure_component_release;
  283. cdev->groups = enclosure_component_groups;
  284. return ecomp;
  285. }
  286. EXPORT_SYMBOL_GPL(enclosure_component_alloc);
  287. /**
  288. * enclosure_component_register - publishes an initialized enclosure component
  289. * @ecomp: component to add
  290. *
  291. * Returns 0 on successful registration, releases the component otherwise
  292. */
  293. int enclosure_component_register(struct enclosure_component *ecomp)
  294. {
  295. struct device *cdev;
  296. int err;
  297. cdev = &ecomp->cdev;
  298. err = device_register(cdev);
  299. if (err) {
  300. ecomp->number = -1;
  301. put_device(cdev);
  302. return err;
  303. }
  304. return 0;
  305. }
  306. EXPORT_SYMBOL_GPL(enclosure_component_register);
  307. /**
  308. * enclosure_add_device - add a device as being part of an enclosure
  309. * @edev: the enclosure device being added to.
  310. * @num: the number of the component
  311. * @dev: the device being added
  312. *
  313. * Declares a real device to reside in slot (or identifier) @num of an
  314. * enclosure. This will cause the relevant sysfs links to appear.
  315. * This function may also be used to change a device associated with
  316. * an enclosure without having to call enclosure_remove_device() in
  317. * between.
  318. *
  319. * Returns zero on success or an error.
  320. */
  321. int enclosure_add_device(struct enclosure_device *edev, int component,
  322. struct device *dev)
  323. {
  324. struct enclosure_component *cdev;
  325. int err;
  326. if (!edev || component >= edev->components)
  327. return -EINVAL;
  328. cdev = &edev->component[component];
  329. if (cdev->dev == dev)
  330. return -EEXIST;
  331. if (cdev->dev) {
  332. enclosure_remove_links(cdev);
  333. put_device(cdev->dev);
  334. }
  335. cdev->dev = get_device(dev);
  336. err = enclosure_add_links(cdev);
  337. if (err) {
  338. put_device(cdev->dev);
  339. cdev->dev = NULL;
  340. }
  341. return err;
  342. }
  343. EXPORT_SYMBOL_GPL(enclosure_add_device);
  344. /**
  345. * enclosure_remove_device - remove a device from an enclosure
  346. * @edev: the enclosure device
  347. * @num: the number of the component to remove
  348. *
  349. * Returns zero on success or an error.
  350. *
  351. */
  352. int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
  353. {
  354. struct enclosure_component *cdev;
  355. int i;
  356. if (!edev || !dev)
  357. return -EINVAL;
  358. for (i = 0; i < edev->components; i++) {
  359. cdev = &edev->component[i];
  360. if (cdev->dev == dev) {
  361. enclosure_remove_links(cdev);
  362. put_device(dev);
  363. cdev->dev = NULL;
  364. return 0;
  365. }
  366. }
  367. return -ENODEV;
  368. }
  369. EXPORT_SYMBOL_GPL(enclosure_remove_device);
  370. /*
  371. * sysfs pieces below
  372. */
  373. static ssize_t components_show(struct device *cdev,
  374. struct device_attribute *attr, char *buf)
  375. {
  376. struct enclosure_device *edev = to_enclosure_device(cdev);
  377. return snprintf(buf, 40, "%d\n", edev->components);
  378. }
  379. static DEVICE_ATTR_RO(components);
  380. static ssize_t id_show(struct device *cdev,
  381. struct device_attribute *attr,
  382. char *buf)
  383. {
  384. struct enclosure_device *edev = to_enclosure_device(cdev);
  385. if (edev->cb->show_id)
  386. return edev->cb->show_id(edev, buf);
  387. return -EINVAL;
  388. }
  389. static DEVICE_ATTR_RO(id);
  390. static struct attribute *enclosure_class_attrs[] = {
  391. &dev_attr_components.attr,
  392. &dev_attr_id.attr,
  393. NULL,
  394. };
  395. ATTRIBUTE_GROUPS(enclosure_class);
  396. static struct class enclosure_class = {
  397. .name = "enclosure",
  398. .owner = THIS_MODULE,
  399. .dev_release = enclosure_release,
  400. .dev_groups = enclosure_class_groups,
  401. };
  402. static const char *const enclosure_status[] = {
  403. [ENCLOSURE_STATUS_UNSUPPORTED] = "unsupported",
  404. [ENCLOSURE_STATUS_OK] = "OK",
  405. [ENCLOSURE_STATUS_CRITICAL] = "critical",
  406. [ENCLOSURE_STATUS_NON_CRITICAL] = "non-critical",
  407. [ENCLOSURE_STATUS_UNRECOVERABLE] = "unrecoverable",
  408. [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
  409. [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
  410. [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
  411. [ENCLOSURE_STATUS_MAX] = NULL,
  412. };
  413. static const char *const enclosure_type[] = {
  414. [ENCLOSURE_COMPONENT_DEVICE] = "device",
  415. [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device",
  416. };
  417. static ssize_t get_component_fault(struct device *cdev,
  418. struct device_attribute *attr, char *buf)
  419. {
  420. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  421. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  422. if (edev->cb->get_fault)
  423. edev->cb->get_fault(edev, ecomp);
  424. return snprintf(buf, 40, "%d\n", ecomp->fault);
  425. }
  426. static ssize_t set_component_fault(struct device *cdev,
  427. struct device_attribute *attr,
  428. const char *buf, size_t count)
  429. {
  430. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  431. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  432. int val = simple_strtoul(buf, NULL, 0);
  433. if (edev->cb->set_fault)
  434. edev->cb->set_fault(edev, ecomp, val);
  435. return count;
  436. }
  437. static ssize_t get_component_status(struct device *cdev,
  438. struct device_attribute *attr,char *buf)
  439. {
  440. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  441. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  442. if (edev->cb->get_status)
  443. edev->cb->get_status(edev, ecomp);
  444. return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]);
  445. }
  446. static ssize_t set_component_status(struct device *cdev,
  447. struct device_attribute *attr,
  448. const char *buf, size_t count)
  449. {
  450. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  451. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  452. int i;
  453. for (i = 0; enclosure_status[i]; i++) {
  454. if (strncmp(buf, enclosure_status[i],
  455. strlen(enclosure_status[i])) == 0 &&
  456. (buf[strlen(enclosure_status[i])] == '\n' ||
  457. buf[strlen(enclosure_status[i])] == '\0'))
  458. break;
  459. }
  460. if (enclosure_status[i] && edev->cb->set_status) {
  461. edev->cb->set_status(edev, ecomp, i);
  462. return count;
  463. } else
  464. return -EINVAL;
  465. }
  466. static ssize_t get_component_active(struct device *cdev,
  467. struct device_attribute *attr, char *buf)
  468. {
  469. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  470. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  471. if (edev->cb->get_active)
  472. edev->cb->get_active(edev, ecomp);
  473. return snprintf(buf, 40, "%d\n", ecomp->active);
  474. }
  475. static ssize_t set_component_active(struct device *cdev,
  476. struct device_attribute *attr,
  477. const char *buf, size_t count)
  478. {
  479. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  480. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  481. int val = simple_strtoul(buf, NULL, 0);
  482. if (edev->cb->set_active)
  483. edev->cb->set_active(edev, ecomp, val);
  484. return count;
  485. }
  486. static ssize_t get_component_locate(struct device *cdev,
  487. struct device_attribute *attr, char *buf)
  488. {
  489. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  490. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  491. if (edev->cb->get_locate)
  492. edev->cb->get_locate(edev, ecomp);
  493. return snprintf(buf, 40, "%d\n", ecomp->locate);
  494. }
  495. static ssize_t set_component_locate(struct device *cdev,
  496. struct device_attribute *attr,
  497. const char *buf, size_t count)
  498. {
  499. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  500. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  501. int val = simple_strtoul(buf, NULL, 0);
  502. if (edev->cb->set_locate)
  503. edev->cb->set_locate(edev, ecomp, val);
  504. return count;
  505. }
  506. static ssize_t get_component_power_status(struct device *cdev,
  507. struct device_attribute *attr,
  508. char *buf)
  509. {
  510. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  511. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  512. if (edev->cb->get_power_status)
  513. edev->cb->get_power_status(edev, ecomp);
  514. /* If still uninitialized, the callback failed or does not exist. */
  515. if (ecomp->power_status == -1)
  516. return (edev->cb->get_power_status) ? -EIO : -ENOTTY;
  517. return snprintf(buf, 40, "%s\n", ecomp->power_status ? "on" : "off");
  518. }
  519. static ssize_t set_component_power_status(struct device *cdev,
  520. struct device_attribute *attr,
  521. const char *buf, size_t count)
  522. {
  523. struct enclosure_device *edev = to_enclosure_device(cdev->parent);
  524. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  525. int val;
  526. if (strncmp(buf, "on", 2) == 0 &&
  527. (buf[2] == '\n' || buf[2] == '\0'))
  528. val = 1;
  529. else if (strncmp(buf, "off", 3) == 0 &&
  530. (buf[3] == '\n' || buf[3] == '\0'))
  531. val = 0;
  532. else
  533. return -EINVAL;
  534. if (edev->cb->set_power_status)
  535. edev->cb->set_power_status(edev, ecomp, val);
  536. return count;
  537. }
  538. static ssize_t get_component_type(struct device *cdev,
  539. struct device_attribute *attr, char *buf)
  540. {
  541. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  542. return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
  543. }
  544. static ssize_t get_component_slot(struct device *cdev,
  545. struct device_attribute *attr, char *buf)
  546. {
  547. struct enclosure_component *ecomp = to_enclosure_component(cdev);
  548. int slot;
  549. /* if the enclosure does not override then use 'number' as a stand-in */
  550. if (ecomp->slot >= 0)
  551. slot = ecomp->slot;
  552. else
  553. slot = ecomp->number;
  554. return snprintf(buf, 40, "%d\n", slot);
  555. }
  556. static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
  557. set_component_fault);
  558. static DEVICE_ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
  559. set_component_status);
  560. static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
  561. set_component_active);
  562. static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
  563. set_component_locate);
  564. static DEVICE_ATTR(power_status, S_IRUGO | S_IWUSR, get_component_power_status,
  565. set_component_power_status);
  566. static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL);
  567. static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL);
  568. static struct attribute *enclosure_component_attrs[] = {
  569. &dev_attr_fault.attr,
  570. &dev_attr_status.attr,
  571. &dev_attr_active.attr,
  572. &dev_attr_locate.attr,
  573. &dev_attr_power_status.attr,
  574. &dev_attr_type.attr,
  575. &dev_attr_slot.attr,
  576. NULL
  577. };
  578. ATTRIBUTE_GROUPS(enclosure_component);
  579. static int __init enclosure_init(void)
  580. {
  581. return class_register(&enclosure_class);
  582. }
  583. static void __exit enclosure_exit(void)
  584. {
  585. class_unregister(&enclosure_class);
  586. }
  587. module_init(enclosure_init);
  588. module_exit(enclosure_exit);
  589. MODULE_AUTHOR("James Bottomley");
  590. MODULE_DESCRIPTION("Enclosure Services");
  591. MODULE_LICENSE("GPL v2");