iscsi_boot_sysfs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /*
  2. * Export the iSCSI boot info to userland via sysfs.
  3. *
  4. * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
  5. * Copyright (C) 2010 Mike Christie
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License v2.0 as published by
  9. * the Free Software Foundation
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/string.h>
  18. #include <linux/slab.h>
  19. #include <linux/sysfs.h>
  20. #include <linux/capability.h>
  21. #include <linux/iscsi_boot_sysfs.h>
  22. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>");
  23. MODULE_DESCRIPTION("sysfs interface and helpers to export iSCSI boot information");
  24. MODULE_LICENSE("GPL");
  25. /*
  26. * The kobject and attribute structures.
  27. */
  28. struct iscsi_boot_attr {
  29. struct attribute attr;
  30. int type;
  31. ssize_t (*show) (void *data, int type, char *buf);
  32. };
  33. /*
  34. * The routine called for all sysfs attributes.
  35. */
  36. static ssize_t iscsi_boot_show_attribute(struct kobject *kobj,
  37. struct attribute *attr, char *buf)
  38. {
  39. struct iscsi_boot_kobj *boot_kobj =
  40. container_of(kobj, struct iscsi_boot_kobj, kobj);
  41. struct iscsi_boot_attr *boot_attr =
  42. container_of(attr, struct iscsi_boot_attr, attr);
  43. ssize_t ret = -EIO;
  44. char *str = buf;
  45. if (!capable(CAP_SYS_ADMIN))
  46. return -EACCES;
  47. if (boot_kobj->show)
  48. ret = boot_kobj->show(boot_kobj->data, boot_attr->type, str);
  49. return ret;
  50. }
  51. static const struct sysfs_ops iscsi_boot_attr_ops = {
  52. .show = iscsi_boot_show_attribute,
  53. };
  54. static void iscsi_boot_kobj_release(struct kobject *kobj)
  55. {
  56. struct iscsi_boot_kobj *boot_kobj =
  57. container_of(kobj, struct iscsi_boot_kobj, kobj);
  58. if (boot_kobj->release)
  59. boot_kobj->release(boot_kobj->data);
  60. kfree(boot_kobj);
  61. }
  62. static struct kobj_type iscsi_boot_ktype = {
  63. .release = iscsi_boot_kobj_release,
  64. .sysfs_ops = &iscsi_boot_attr_ops,
  65. };
  66. #define iscsi_boot_rd_attr(fnname, sysfs_name, attr_type) \
  67. static struct iscsi_boot_attr iscsi_boot_attr_##fnname = { \
  68. .attr = { .name = __stringify(sysfs_name), .mode = 0444 }, \
  69. .type = attr_type, \
  70. }
  71. /* Target attrs */
  72. iscsi_boot_rd_attr(tgt_index, index, ISCSI_BOOT_TGT_INDEX);
  73. iscsi_boot_rd_attr(tgt_flags, flags, ISCSI_BOOT_TGT_FLAGS);
  74. iscsi_boot_rd_attr(tgt_ip, ip-addr, ISCSI_BOOT_TGT_IP_ADDR);
  75. iscsi_boot_rd_attr(tgt_port, port, ISCSI_BOOT_TGT_PORT);
  76. iscsi_boot_rd_attr(tgt_lun, lun, ISCSI_BOOT_TGT_LUN);
  77. iscsi_boot_rd_attr(tgt_chap, chap-type, ISCSI_BOOT_TGT_CHAP_TYPE);
  78. iscsi_boot_rd_attr(tgt_nic, nic-assoc, ISCSI_BOOT_TGT_NIC_ASSOC);
  79. iscsi_boot_rd_attr(tgt_name, target-name, ISCSI_BOOT_TGT_NAME);
  80. iscsi_boot_rd_attr(tgt_chap_name, chap-name, ISCSI_BOOT_TGT_CHAP_NAME);
  81. iscsi_boot_rd_attr(tgt_chap_secret, chap-secret, ISCSI_BOOT_TGT_CHAP_SECRET);
  82. iscsi_boot_rd_attr(tgt_chap_rev_name, rev-chap-name,
  83. ISCSI_BOOT_TGT_REV_CHAP_NAME);
  84. iscsi_boot_rd_attr(tgt_chap_rev_secret, rev-chap-name-secret,
  85. ISCSI_BOOT_TGT_REV_CHAP_SECRET);
  86. static struct attribute *target_attrs[] = {
  87. &iscsi_boot_attr_tgt_index.attr,
  88. &iscsi_boot_attr_tgt_flags.attr,
  89. &iscsi_boot_attr_tgt_ip.attr,
  90. &iscsi_boot_attr_tgt_port.attr,
  91. &iscsi_boot_attr_tgt_lun.attr,
  92. &iscsi_boot_attr_tgt_chap.attr,
  93. &iscsi_boot_attr_tgt_nic.attr,
  94. &iscsi_boot_attr_tgt_name.attr,
  95. &iscsi_boot_attr_tgt_chap_name.attr,
  96. &iscsi_boot_attr_tgt_chap_secret.attr,
  97. &iscsi_boot_attr_tgt_chap_rev_name.attr,
  98. &iscsi_boot_attr_tgt_chap_rev_secret.attr,
  99. NULL
  100. };
  101. static umode_t iscsi_boot_tgt_attr_is_visible(struct kobject *kobj,
  102. struct attribute *attr, int i)
  103. {
  104. struct iscsi_boot_kobj *boot_kobj =
  105. container_of(kobj, struct iscsi_boot_kobj, kobj);
  106. if (attr == &iscsi_boot_attr_tgt_index.attr)
  107. return boot_kobj->is_visible(boot_kobj->data,
  108. ISCSI_BOOT_TGT_INDEX);
  109. else if (attr == &iscsi_boot_attr_tgt_flags.attr)
  110. return boot_kobj->is_visible(boot_kobj->data,
  111. ISCSI_BOOT_TGT_FLAGS);
  112. else if (attr == &iscsi_boot_attr_tgt_ip.attr)
  113. return boot_kobj->is_visible(boot_kobj->data,
  114. ISCSI_BOOT_TGT_IP_ADDR);
  115. else if (attr == &iscsi_boot_attr_tgt_port.attr)
  116. return boot_kobj->is_visible(boot_kobj->data,
  117. ISCSI_BOOT_TGT_PORT);
  118. else if (attr == &iscsi_boot_attr_tgt_lun.attr)
  119. return boot_kobj->is_visible(boot_kobj->data,
  120. ISCSI_BOOT_TGT_LUN);
  121. else if (attr == &iscsi_boot_attr_tgt_chap.attr)
  122. return boot_kobj->is_visible(boot_kobj->data,
  123. ISCSI_BOOT_TGT_CHAP_TYPE);
  124. else if (attr == &iscsi_boot_attr_tgt_nic.attr)
  125. return boot_kobj->is_visible(boot_kobj->data,
  126. ISCSI_BOOT_TGT_NIC_ASSOC);
  127. else if (attr == &iscsi_boot_attr_tgt_name.attr)
  128. return boot_kobj->is_visible(boot_kobj->data,
  129. ISCSI_BOOT_TGT_NAME);
  130. else if (attr == &iscsi_boot_attr_tgt_chap_name.attr)
  131. return boot_kobj->is_visible(boot_kobj->data,
  132. ISCSI_BOOT_TGT_CHAP_NAME);
  133. else if (attr == &iscsi_boot_attr_tgt_chap_secret.attr)
  134. return boot_kobj->is_visible(boot_kobj->data,
  135. ISCSI_BOOT_TGT_CHAP_SECRET);
  136. else if (attr == &iscsi_boot_attr_tgt_chap_rev_name.attr)
  137. return boot_kobj->is_visible(boot_kobj->data,
  138. ISCSI_BOOT_TGT_REV_CHAP_NAME);
  139. else if (attr == &iscsi_boot_attr_tgt_chap_rev_secret.attr)
  140. return boot_kobj->is_visible(boot_kobj->data,
  141. ISCSI_BOOT_TGT_REV_CHAP_SECRET);
  142. return 0;
  143. }
  144. static struct attribute_group iscsi_boot_target_attr_group = {
  145. .attrs = target_attrs,
  146. .is_visible = iscsi_boot_tgt_attr_is_visible,
  147. };
  148. /* Ethernet attrs */
  149. iscsi_boot_rd_attr(eth_index, index, ISCSI_BOOT_ETH_INDEX);
  150. iscsi_boot_rd_attr(eth_flags, flags, ISCSI_BOOT_ETH_FLAGS);
  151. iscsi_boot_rd_attr(eth_ip, ip-addr, ISCSI_BOOT_ETH_IP_ADDR);
  152. iscsi_boot_rd_attr(eth_prefix, prefix-len, ISCSI_BOOT_ETH_PREFIX_LEN);
  153. iscsi_boot_rd_attr(eth_subnet, subnet-mask, ISCSI_BOOT_ETH_SUBNET_MASK);
  154. iscsi_boot_rd_attr(eth_origin, origin, ISCSI_BOOT_ETH_ORIGIN);
  155. iscsi_boot_rd_attr(eth_gateway, gateway, ISCSI_BOOT_ETH_GATEWAY);
  156. iscsi_boot_rd_attr(eth_primary_dns, primary-dns, ISCSI_BOOT_ETH_PRIMARY_DNS);
  157. iscsi_boot_rd_attr(eth_secondary_dns, secondary-dns,
  158. ISCSI_BOOT_ETH_SECONDARY_DNS);
  159. iscsi_boot_rd_attr(eth_dhcp, dhcp, ISCSI_BOOT_ETH_DHCP);
  160. iscsi_boot_rd_attr(eth_vlan, vlan, ISCSI_BOOT_ETH_VLAN);
  161. iscsi_boot_rd_attr(eth_mac, mac, ISCSI_BOOT_ETH_MAC);
  162. iscsi_boot_rd_attr(eth_hostname, hostname, ISCSI_BOOT_ETH_HOSTNAME);
  163. static struct attribute *ethernet_attrs[] = {
  164. &iscsi_boot_attr_eth_index.attr,
  165. &iscsi_boot_attr_eth_flags.attr,
  166. &iscsi_boot_attr_eth_ip.attr,
  167. &iscsi_boot_attr_eth_prefix.attr,
  168. &iscsi_boot_attr_eth_subnet.attr,
  169. &iscsi_boot_attr_eth_origin.attr,
  170. &iscsi_boot_attr_eth_gateway.attr,
  171. &iscsi_boot_attr_eth_primary_dns.attr,
  172. &iscsi_boot_attr_eth_secondary_dns.attr,
  173. &iscsi_boot_attr_eth_dhcp.attr,
  174. &iscsi_boot_attr_eth_vlan.attr,
  175. &iscsi_boot_attr_eth_mac.attr,
  176. &iscsi_boot_attr_eth_hostname.attr,
  177. NULL
  178. };
  179. static umode_t iscsi_boot_eth_attr_is_visible(struct kobject *kobj,
  180. struct attribute *attr, int i)
  181. {
  182. struct iscsi_boot_kobj *boot_kobj =
  183. container_of(kobj, struct iscsi_boot_kobj, kobj);
  184. if (attr == &iscsi_boot_attr_eth_index.attr)
  185. return boot_kobj->is_visible(boot_kobj->data,
  186. ISCSI_BOOT_ETH_INDEX);
  187. else if (attr == &iscsi_boot_attr_eth_flags.attr)
  188. return boot_kobj->is_visible(boot_kobj->data,
  189. ISCSI_BOOT_ETH_FLAGS);
  190. else if (attr == &iscsi_boot_attr_eth_ip.attr)
  191. return boot_kobj->is_visible(boot_kobj->data,
  192. ISCSI_BOOT_ETH_IP_ADDR);
  193. else if (attr == &iscsi_boot_attr_eth_prefix.attr)
  194. return boot_kobj->is_visible(boot_kobj->data,
  195. ISCSI_BOOT_ETH_PREFIX_LEN);
  196. else if (attr == &iscsi_boot_attr_eth_subnet.attr)
  197. return boot_kobj->is_visible(boot_kobj->data,
  198. ISCSI_BOOT_ETH_SUBNET_MASK);
  199. else if (attr == &iscsi_boot_attr_eth_origin.attr)
  200. return boot_kobj->is_visible(boot_kobj->data,
  201. ISCSI_BOOT_ETH_ORIGIN);
  202. else if (attr == &iscsi_boot_attr_eth_gateway.attr)
  203. return boot_kobj->is_visible(boot_kobj->data,
  204. ISCSI_BOOT_ETH_GATEWAY);
  205. else if (attr == &iscsi_boot_attr_eth_primary_dns.attr)
  206. return boot_kobj->is_visible(boot_kobj->data,
  207. ISCSI_BOOT_ETH_PRIMARY_DNS);
  208. else if (attr == &iscsi_boot_attr_eth_secondary_dns.attr)
  209. return boot_kobj->is_visible(boot_kobj->data,
  210. ISCSI_BOOT_ETH_SECONDARY_DNS);
  211. else if (attr == &iscsi_boot_attr_eth_dhcp.attr)
  212. return boot_kobj->is_visible(boot_kobj->data,
  213. ISCSI_BOOT_ETH_DHCP);
  214. else if (attr == &iscsi_boot_attr_eth_vlan.attr)
  215. return boot_kobj->is_visible(boot_kobj->data,
  216. ISCSI_BOOT_ETH_VLAN);
  217. else if (attr == &iscsi_boot_attr_eth_mac.attr)
  218. return boot_kobj->is_visible(boot_kobj->data,
  219. ISCSI_BOOT_ETH_MAC);
  220. else if (attr == &iscsi_boot_attr_eth_hostname.attr)
  221. return boot_kobj->is_visible(boot_kobj->data,
  222. ISCSI_BOOT_ETH_HOSTNAME);
  223. return 0;
  224. }
  225. static struct attribute_group iscsi_boot_ethernet_attr_group = {
  226. .attrs = ethernet_attrs,
  227. .is_visible = iscsi_boot_eth_attr_is_visible,
  228. };
  229. /* Initiator attrs */
  230. iscsi_boot_rd_attr(ini_index, index, ISCSI_BOOT_INI_INDEX);
  231. iscsi_boot_rd_attr(ini_flags, flags, ISCSI_BOOT_INI_FLAGS);
  232. iscsi_boot_rd_attr(ini_isns, isns-server, ISCSI_BOOT_INI_ISNS_SERVER);
  233. iscsi_boot_rd_attr(ini_slp, slp-server, ISCSI_BOOT_INI_SLP_SERVER);
  234. iscsi_boot_rd_attr(ini_primary_radius, pri-radius-server,
  235. ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
  236. iscsi_boot_rd_attr(ini_secondary_radius, sec-radius-server,
  237. ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
  238. iscsi_boot_rd_attr(ini_name, initiator-name, ISCSI_BOOT_INI_INITIATOR_NAME);
  239. static struct attribute *initiator_attrs[] = {
  240. &iscsi_boot_attr_ini_index.attr,
  241. &iscsi_boot_attr_ini_flags.attr,
  242. &iscsi_boot_attr_ini_isns.attr,
  243. &iscsi_boot_attr_ini_slp.attr,
  244. &iscsi_boot_attr_ini_primary_radius.attr,
  245. &iscsi_boot_attr_ini_secondary_radius.attr,
  246. &iscsi_boot_attr_ini_name.attr,
  247. NULL
  248. };
  249. static umode_t iscsi_boot_ini_attr_is_visible(struct kobject *kobj,
  250. struct attribute *attr, int i)
  251. {
  252. struct iscsi_boot_kobj *boot_kobj =
  253. container_of(kobj, struct iscsi_boot_kobj, kobj);
  254. if (attr == &iscsi_boot_attr_ini_index.attr)
  255. return boot_kobj->is_visible(boot_kobj->data,
  256. ISCSI_BOOT_INI_INDEX);
  257. if (attr == &iscsi_boot_attr_ini_flags.attr)
  258. return boot_kobj->is_visible(boot_kobj->data,
  259. ISCSI_BOOT_INI_FLAGS);
  260. if (attr == &iscsi_boot_attr_ini_isns.attr)
  261. return boot_kobj->is_visible(boot_kobj->data,
  262. ISCSI_BOOT_INI_ISNS_SERVER);
  263. if (attr == &iscsi_boot_attr_ini_slp.attr)
  264. return boot_kobj->is_visible(boot_kobj->data,
  265. ISCSI_BOOT_INI_SLP_SERVER);
  266. if (attr == &iscsi_boot_attr_ini_primary_radius.attr)
  267. return boot_kobj->is_visible(boot_kobj->data,
  268. ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
  269. if (attr == &iscsi_boot_attr_ini_secondary_radius.attr)
  270. return boot_kobj->is_visible(boot_kobj->data,
  271. ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
  272. if (attr == &iscsi_boot_attr_ini_name.attr)
  273. return boot_kobj->is_visible(boot_kobj->data,
  274. ISCSI_BOOT_INI_INITIATOR_NAME);
  275. return 0;
  276. }
  277. static struct attribute_group iscsi_boot_initiator_attr_group = {
  278. .attrs = initiator_attrs,
  279. .is_visible = iscsi_boot_ini_attr_is_visible,
  280. };
  281. /* iBFT ACPI Table attributes */
  282. iscsi_boot_rd_attr(acpitbl_signature, signature, ISCSI_BOOT_ACPITBL_SIGNATURE);
  283. iscsi_boot_rd_attr(acpitbl_oem_id, oem_id, ISCSI_BOOT_ACPITBL_OEM_ID);
  284. iscsi_boot_rd_attr(acpitbl_oem_table_id, oem_table_id,
  285. ISCSI_BOOT_ACPITBL_OEM_TABLE_ID);
  286. static struct attribute *acpitbl_attrs[] = {
  287. &iscsi_boot_attr_acpitbl_signature.attr,
  288. &iscsi_boot_attr_acpitbl_oem_id.attr,
  289. &iscsi_boot_attr_acpitbl_oem_table_id.attr,
  290. NULL
  291. };
  292. static umode_t iscsi_boot_acpitbl_attr_is_visible(struct kobject *kobj,
  293. struct attribute *attr, int i)
  294. {
  295. struct iscsi_boot_kobj *boot_kobj =
  296. container_of(kobj, struct iscsi_boot_kobj, kobj);
  297. if (attr == &iscsi_boot_attr_acpitbl_signature.attr)
  298. return boot_kobj->is_visible(boot_kobj->data,
  299. ISCSI_BOOT_ACPITBL_SIGNATURE);
  300. if (attr == &iscsi_boot_attr_acpitbl_oem_id.attr)
  301. return boot_kobj->is_visible(boot_kobj->data,
  302. ISCSI_BOOT_ACPITBL_OEM_ID);
  303. if (attr == &iscsi_boot_attr_acpitbl_oem_table_id.attr)
  304. return boot_kobj->is_visible(boot_kobj->data,
  305. ISCSI_BOOT_ACPITBL_OEM_TABLE_ID);
  306. return 0;
  307. }
  308. static struct attribute_group iscsi_boot_acpitbl_attr_group = {
  309. .attrs = acpitbl_attrs,
  310. .is_visible = iscsi_boot_acpitbl_attr_is_visible,
  311. };
  312. static struct iscsi_boot_kobj *
  313. iscsi_boot_create_kobj(struct iscsi_boot_kset *boot_kset,
  314. struct attribute_group *attr_group,
  315. const char *name, int index, void *data,
  316. ssize_t (*show) (void *data, int type, char *buf),
  317. umode_t (*is_visible) (void *data, int type),
  318. void (*release) (void *data))
  319. {
  320. struct iscsi_boot_kobj *boot_kobj;
  321. boot_kobj = kzalloc(sizeof(*boot_kobj), GFP_KERNEL);
  322. if (!boot_kobj)
  323. return NULL;
  324. INIT_LIST_HEAD(&boot_kobj->list);
  325. boot_kobj->kobj.kset = boot_kset->kset;
  326. if (kobject_init_and_add(&boot_kobj->kobj, &iscsi_boot_ktype,
  327. NULL, name, index)) {
  328. kfree(boot_kobj);
  329. return NULL;
  330. }
  331. boot_kobj->data = data;
  332. boot_kobj->show = show;
  333. boot_kobj->is_visible = is_visible;
  334. boot_kobj->release = release;
  335. if (sysfs_create_group(&boot_kobj->kobj, attr_group)) {
  336. /*
  337. * We do not want to free this because the caller
  338. * will assume that since the creation call failed
  339. * the boot kobj was not setup and the normal release
  340. * path is not being run.
  341. */
  342. boot_kobj->release = NULL;
  343. kobject_put(&boot_kobj->kobj);
  344. return NULL;
  345. }
  346. boot_kobj->attr_group = attr_group;
  347. kobject_uevent(&boot_kobj->kobj, KOBJ_ADD);
  348. /* Nothing broke so lets add it to the list. */
  349. list_add_tail(&boot_kobj->list, &boot_kset->kobj_list);
  350. return boot_kobj;
  351. }
  352. static void iscsi_boot_remove_kobj(struct iscsi_boot_kobj *boot_kobj)
  353. {
  354. list_del(&boot_kobj->list);
  355. sysfs_remove_group(&boot_kobj->kobj, boot_kobj->attr_group);
  356. kobject_put(&boot_kobj->kobj);
  357. }
  358. /**
  359. * iscsi_boot_create_target() - create boot target sysfs dir
  360. * @boot_kset: boot kset
  361. * @index: the target id
  362. * @data: driver specific data for target
  363. * @show: attr show function
  364. * @is_visible: attr visibility function
  365. * @release: release function
  366. *
  367. * Note: The boot sysfs lib will free the data passed in for the caller
  368. * when all refs to the target kobject have been released.
  369. */
  370. struct iscsi_boot_kobj *
  371. iscsi_boot_create_target(struct iscsi_boot_kset *boot_kset, int index,
  372. void *data,
  373. ssize_t (*show) (void *data, int type, char *buf),
  374. umode_t (*is_visible) (void *data, int type),
  375. void (*release) (void *data))
  376. {
  377. return iscsi_boot_create_kobj(boot_kset, &iscsi_boot_target_attr_group,
  378. "target%d", index, data, show, is_visible,
  379. release);
  380. }
  381. EXPORT_SYMBOL_GPL(iscsi_boot_create_target);
  382. /**
  383. * iscsi_boot_create_initiator() - create boot initiator sysfs dir
  384. * @boot_kset: boot kset
  385. * @index: the initiator id
  386. * @data: driver specific data
  387. * @show: attr show function
  388. * @is_visible: attr visibility function
  389. * @release: release function
  390. *
  391. * Note: The boot sysfs lib will free the data passed in for the caller
  392. * when all refs to the initiator kobject have been released.
  393. */
  394. struct iscsi_boot_kobj *
  395. iscsi_boot_create_initiator(struct iscsi_boot_kset *boot_kset, int index,
  396. void *data,
  397. ssize_t (*show) (void *data, int type, char *buf),
  398. umode_t (*is_visible) (void *data, int type),
  399. void (*release) (void *data))
  400. {
  401. return iscsi_boot_create_kobj(boot_kset,
  402. &iscsi_boot_initiator_attr_group,
  403. "initiator", index, data, show,
  404. is_visible, release);
  405. }
  406. EXPORT_SYMBOL_GPL(iscsi_boot_create_initiator);
  407. /**
  408. * iscsi_boot_create_ethernet() - create boot ethernet sysfs dir
  409. * @boot_kset: boot kset
  410. * @index: the ethernet device id
  411. * @data: driver specific data
  412. * @show: attr show function
  413. * @is_visible: attr visibility function
  414. * @release: release function
  415. *
  416. * Note: The boot sysfs lib will free the data passed in for the caller
  417. * when all refs to the ethernet kobject have been released.
  418. */
  419. struct iscsi_boot_kobj *
  420. iscsi_boot_create_ethernet(struct iscsi_boot_kset *boot_kset, int index,
  421. void *data,
  422. ssize_t (*show) (void *data, int type, char *buf),
  423. umode_t (*is_visible) (void *data, int type),
  424. void (*release) (void *data))
  425. {
  426. return iscsi_boot_create_kobj(boot_kset,
  427. &iscsi_boot_ethernet_attr_group,
  428. "ethernet%d", index, data, show,
  429. is_visible, release);
  430. }
  431. EXPORT_SYMBOL_GPL(iscsi_boot_create_ethernet);
  432. /**
  433. * iscsi_boot_create_acpitbl() - create boot acpi table sysfs dir
  434. * @boot_kset: boot kset
  435. * @index: not used
  436. * @data: driver specific data
  437. * @show: attr show function
  438. * @is_visible: attr visibility function
  439. * @release: release function
  440. *
  441. * Note: The boot sysfs lib will free the data passed in for the caller
  442. * when all refs to the acpitbl kobject have been released.
  443. */
  444. struct iscsi_boot_kobj *
  445. iscsi_boot_create_acpitbl(struct iscsi_boot_kset *boot_kset, int index,
  446. void *data,
  447. ssize_t (*show)(void *data, int type, char *buf),
  448. umode_t (*is_visible)(void *data, int type),
  449. void (*release)(void *data))
  450. {
  451. return iscsi_boot_create_kobj(boot_kset,
  452. &iscsi_boot_acpitbl_attr_group,
  453. "acpi_header", index, data, show,
  454. is_visible, release);
  455. }
  456. EXPORT_SYMBOL_GPL(iscsi_boot_create_acpitbl);
  457. /**
  458. * iscsi_boot_create_kset() - creates root sysfs tree
  459. * @set_name: name of root dir
  460. */
  461. struct iscsi_boot_kset *iscsi_boot_create_kset(const char *set_name)
  462. {
  463. struct iscsi_boot_kset *boot_kset;
  464. boot_kset = kzalloc(sizeof(*boot_kset), GFP_KERNEL);
  465. if (!boot_kset)
  466. return NULL;
  467. boot_kset->kset = kset_create_and_add(set_name, NULL, firmware_kobj);
  468. if (!boot_kset->kset) {
  469. kfree(boot_kset);
  470. return NULL;
  471. }
  472. INIT_LIST_HEAD(&boot_kset->kobj_list);
  473. return boot_kset;
  474. }
  475. EXPORT_SYMBOL_GPL(iscsi_boot_create_kset);
  476. /**
  477. * iscsi_boot_create_host_kset() - creates root sysfs tree for a scsi host
  478. * @hostno: host number of scsi host
  479. */
  480. struct iscsi_boot_kset *iscsi_boot_create_host_kset(unsigned int hostno)
  481. {
  482. struct iscsi_boot_kset *boot_kset;
  483. char *set_name;
  484. set_name = kasprintf(GFP_KERNEL, "iscsi_boot%u", hostno);
  485. if (!set_name)
  486. return NULL;
  487. boot_kset = iscsi_boot_create_kset(set_name);
  488. kfree(set_name);
  489. return boot_kset;
  490. }
  491. EXPORT_SYMBOL_GPL(iscsi_boot_create_host_kset);
  492. /**
  493. * iscsi_boot_destroy_kset() - destroy kset and kobjects under it
  494. * @boot_kset: boot kset
  495. *
  496. * This will remove the kset and kobjects and attrs under it.
  497. */
  498. void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)
  499. {
  500. struct iscsi_boot_kobj *boot_kobj, *tmp_kobj;
  501. if (!boot_kset)
  502. return;
  503. list_for_each_entry_safe(boot_kobj, tmp_kobj,
  504. &boot_kset->kobj_list, list)
  505. iscsi_boot_remove_kobj(boot_kobj);
  506. kset_unregister(boot_kset->kset);
  507. kfree(boot_kset);
  508. }
  509. EXPORT_SYMBOL_GPL(iscsi_boot_destroy_kset);