iscsi_boot_sysfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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_subnet, subnet-mask, ISCSI_BOOT_ETH_SUBNET_MASK);
  153. iscsi_boot_rd_attr(eth_origin, origin, ISCSI_BOOT_ETH_ORIGIN);
  154. iscsi_boot_rd_attr(eth_gateway, gateway, ISCSI_BOOT_ETH_GATEWAY);
  155. iscsi_boot_rd_attr(eth_primary_dns, primary-dns, ISCSI_BOOT_ETH_PRIMARY_DNS);
  156. iscsi_boot_rd_attr(eth_secondary_dns, secondary-dns,
  157. ISCSI_BOOT_ETH_SECONDARY_DNS);
  158. iscsi_boot_rd_attr(eth_dhcp, dhcp, ISCSI_BOOT_ETH_DHCP);
  159. iscsi_boot_rd_attr(eth_vlan, vlan, ISCSI_BOOT_ETH_VLAN);
  160. iscsi_boot_rd_attr(eth_mac, mac, ISCSI_BOOT_ETH_MAC);
  161. iscsi_boot_rd_attr(eth_hostname, hostname, ISCSI_BOOT_ETH_HOSTNAME);
  162. static struct attribute *ethernet_attrs[] = {
  163. &iscsi_boot_attr_eth_index.attr,
  164. &iscsi_boot_attr_eth_flags.attr,
  165. &iscsi_boot_attr_eth_ip.attr,
  166. &iscsi_boot_attr_eth_subnet.attr,
  167. &iscsi_boot_attr_eth_origin.attr,
  168. &iscsi_boot_attr_eth_gateway.attr,
  169. &iscsi_boot_attr_eth_primary_dns.attr,
  170. &iscsi_boot_attr_eth_secondary_dns.attr,
  171. &iscsi_boot_attr_eth_dhcp.attr,
  172. &iscsi_boot_attr_eth_vlan.attr,
  173. &iscsi_boot_attr_eth_mac.attr,
  174. &iscsi_boot_attr_eth_hostname.attr,
  175. NULL
  176. };
  177. static umode_t iscsi_boot_eth_attr_is_visible(struct kobject *kobj,
  178. struct attribute *attr, int i)
  179. {
  180. struct iscsi_boot_kobj *boot_kobj =
  181. container_of(kobj, struct iscsi_boot_kobj, kobj);
  182. if (attr == &iscsi_boot_attr_eth_index.attr)
  183. return boot_kobj->is_visible(boot_kobj->data,
  184. ISCSI_BOOT_ETH_INDEX);
  185. else if (attr == &iscsi_boot_attr_eth_flags.attr)
  186. return boot_kobj->is_visible(boot_kobj->data,
  187. ISCSI_BOOT_ETH_FLAGS);
  188. else if (attr == &iscsi_boot_attr_eth_ip.attr)
  189. return boot_kobj->is_visible(boot_kobj->data,
  190. ISCSI_BOOT_ETH_IP_ADDR);
  191. else if (attr == &iscsi_boot_attr_eth_subnet.attr)
  192. return boot_kobj->is_visible(boot_kobj->data,
  193. ISCSI_BOOT_ETH_SUBNET_MASK);
  194. else if (attr == &iscsi_boot_attr_eth_origin.attr)
  195. return boot_kobj->is_visible(boot_kobj->data,
  196. ISCSI_BOOT_ETH_ORIGIN);
  197. else if (attr == &iscsi_boot_attr_eth_gateway.attr)
  198. return boot_kobj->is_visible(boot_kobj->data,
  199. ISCSI_BOOT_ETH_GATEWAY);
  200. else if (attr == &iscsi_boot_attr_eth_primary_dns.attr)
  201. return boot_kobj->is_visible(boot_kobj->data,
  202. ISCSI_BOOT_ETH_PRIMARY_DNS);
  203. else if (attr == &iscsi_boot_attr_eth_secondary_dns.attr)
  204. return boot_kobj->is_visible(boot_kobj->data,
  205. ISCSI_BOOT_ETH_SECONDARY_DNS);
  206. else if (attr == &iscsi_boot_attr_eth_dhcp.attr)
  207. return boot_kobj->is_visible(boot_kobj->data,
  208. ISCSI_BOOT_ETH_DHCP);
  209. else if (attr == &iscsi_boot_attr_eth_vlan.attr)
  210. return boot_kobj->is_visible(boot_kobj->data,
  211. ISCSI_BOOT_ETH_VLAN);
  212. else if (attr == &iscsi_boot_attr_eth_mac.attr)
  213. return boot_kobj->is_visible(boot_kobj->data,
  214. ISCSI_BOOT_ETH_MAC);
  215. else if (attr == &iscsi_boot_attr_eth_hostname.attr)
  216. return boot_kobj->is_visible(boot_kobj->data,
  217. ISCSI_BOOT_ETH_HOSTNAME);
  218. return 0;
  219. }
  220. static struct attribute_group iscsi_boot_ethernet_attr_group = {
  221. .attrs = ethernet_attrs,
  222. .is_visible = iscsi_boot_eth_attr_is_visible,
  223. };
  224. /* Initiator attrs */
  225. iscsi_boot_rd_attr(ini_index, index, ISCSI_BOOT_INI_INDEX);
  226. iscsi_boot_rd_attr(ini_flags, flags, ISCSI_BOOT_INI_FLAGS);
  227. iscsi_boot_rd_attr(ini_isns, isns-server, ISCSI_BOOT_INI_ISNS_SERVER);
  228. iscsi_boot_rd_attr(ini_slp, slp-server, ISCSI_BOOT_INI_SLP_SERVER);
  229. iscsi_boot_rd_attr(ini_primary_radius, pri-radius-server,
  230. ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
  231. iscsi_boot_rd_attr(ini_secondary_radius, sec-radius-server,
  232. ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
  233. iscsi_boot_rd_attr(ini_name, initiator-name, ISCSI_BOOT_INI_INITIATOR_NAME);
  234. static struct attribute *initiator_attrs[] = {
  235. &iscsi_boot_attr_ini_index.attr,
  236. &iscsi_boot_attr_ini_flags.attr,
  237. &iscsi_boot_attr_ini_isns.attr,
  238. &iscsi_boot_attr_ini_slp.attr,
  239. &iscsi_boot_attr_ini_primary_radius.attr,
  240. &iscsi_boot_attr_ini_secondary_radius.attr,
  241. &iscsi_boot_attr_ini_name.attr,
  242. NULL
  243. };
  244. static umode_t iscsi_boot_ini_attr_is_visible(struct kobject *kobj,
  245. struct attribute *attr, int i)
  246. {
  247. struct iscsi_boot_kobj *boot_kobj =
  248. container_of(kobj, struct iscsi_boot_kobj, kobj);
  249. if (attr == &iscsi_boot_attr_ini_index.attr)
  250. return boot_kobj->is_visible(boot_kobj->data,
  251. ISCSI_BOOT_INI_INDEX);
  252. if (attr == &iscsi_boot_attr_ini_flags.attr)
  253. return boot_kobj->is_visible(boot_kobj->data,
  254. ISCSI_BOOT_INI_FLAGS);
  255. if (attr == &iscsi_boot_attr_ini_isns.attr)
  256. return boot_kobj->is_visible(boot_kobj->data,
  257. ISCSI_BOOT_INI_ISNS_SERVER);
  258. if (attr == &iscsi_boot_attr_ini_slp.attr)
  259. return boot_kobj->is_visible(boot_kobj->data,
  260. ISCSI_BOOT_INI_SLP_SERVER);
  261. if (attr == &iscsi_boot_attr_ini_primary_radius.attr)
  262. return boot_kobj->is_visible(boot_kobj->data,
  263. ISCSI_BOOT_INI_PRI_RADIUS_SERVER);
  264. if (attr == &iscsi_boot_attr_ini_secondary_radius.attr)
  265. return boot_kobj->is_visible(boot_kobj->data,
  266. ISCSI_BOOT_INI_SEC_RADIUS_SERVER);
  267. if (attr == &iscsi_boot_attr_ini_name.attr)
  268. return boot_kobj->is_visible(boot_kobj->data,
  269. ISCSI_BOOT_INI_INITIATOR_NAME);
  270. return 0;
  271. }
  272. static struct attribute_group iscsi_boot_initiator_attr_group = {
  273. .attrs = initiator_attrs,
  274. .is_visible = iscsi_boot_ini_attr_is_visible,
  275. };
  276. static struct iscsi_boot_kobj *
  277. iscsi_boot_create_kobj(struct iscsi_boot_kset *boot_kset,
  278. struct attribute_group *attr_group,
  279. const char *name, int index, void *data,
  280. ssize_t (*show) (void *data, int type, char *buf),
  281. umode_t (*is_visible) (void *data, int type),
  282. void (*release) (void *data))
  283. {
  284. struct iscsi_boot_kobj *boot_kobj;
  285. boot_kobj = kzalloc(sizeof(*boot_kobj), GFP_KERNEL);
  286. if (!boot_kobj)
  287. return NULL;
  288. INIT_LIST_HEAD(&boot_kobj->list);
  289. boot_kobj->kobj.kset = boot_kset->kset;
  290. if (kobject_init_and_add(&boot_kobj->kobj, &iscsi_boot_ktype,
  291. NULL, name, index)) {
  292. kfree(boot_kobj);
  293. return NULL;
  294. }
  295. boot_kobj->data = data;
  296. boot_kobj->show = show;
  297. boot_kobj->is_visible = is_visible;
  298. boot_kobj->release = release;
  299. if (sysfs_create_group(&boot_kobj->kobj, attr_group)) {
  300. /*
  301. * We do not want to free this because the caller
  302. * will assume that since the creation call failed
  303. * the boot kobj was not setup and the normal release
  304. * path is not being run.
  305. */
  306. boot_kobj->release = NULL;
  307. kobject_put(&boot_kobj->kobj);
  308. return NULL;
  309. }
  310. boot_kobj->attr_group = attr_group;
  311. kobject_uevent(&boot_kobj->kobj, KOBJ_ADD);
  312. /* Nothing broke so lets add it to the list. */
  313. list_add_tail(&boot_kobj->list, &boot_kset->kobj_list);
  314. return boot_kobj;
  315. }
  316. static void iscsi_boot_remove_kobj(struct iscsi_boot_kobj *boot_kobj)
  317. {
  318. list_del(&boot_kobj->list);
  319. sysfs_remove_group(&boot_kobj->kobj, boot_kobj->attr_group);
  320. kobject_put(&boot_kobj->kobj);
  321. }
  322. /**
  323. * iscsi_boot_create_target() - create boot target sysfs dir
  324. * @boot_kset: boot kset
  325. * @index: the target id
  326. * @data: driver specific data for target
  327. * @show: attr show function
  328. * @is_visible: attr visibility function
  329. * @release: release function
  330. *
  331. * Note: The boot sysfs lib will free the data passed in for the caller
  332. * when all refs to the target kobject have been released.
  333. */
  334. struct iscsi_boot_kobj *
  335. iscsi_boot_create_target(struct iscsi_boot_kset *boot_kset, int index,
  336. void *data,
  337. ssize_t (*show) (void *data, int type, char *buf),
  338. umode_t (*is_visible) (void *data, int type),
  339. void (*release) (void *data))
  340. {
  341. return iscsi_boot_create_kobj(boot_kset, &iscsi_boot_target_attr_group,
  342. "target%d", index, data, show, is_visible,
  343. release);
  344. }
  345. EXPORT_SYMBOL_GPL(iscsi_boot_create_target);
  346. /**
  347. * iscsi_boot_create_initiator() - create boot initiator sysfs dir
  348. * @boot_kset: boot kset
  349. * @index: the initiator id
  350. * @data: driver specific data
  351. * @show: attr show function
  352. * @is_visible: attr visibility function
  353. * @release: release function
  354. *
  355. * Note: The boot sysfs lib will free the data passed in for the caller
  356. * when all refs to the initiator kobject have been released.
  357. */
  358. struct iscsi_boot_kobj *
  359. iscsi_boot_create_initiator(struct iscsi_boot_kset *boot_kset, int index,
  360. void *data,
  361. ssize_t (*show) (void *data, int type, char *buf),
  362. umode_t (*is_visible) (void *data, int type),
  363. void (*release) (void *data))
  364. {
  365. return iscsi_boot_create_kobj(boot_kset,
  366. &iscsi_boot_initiator_attr_group,
  367. "initiator", index, data, show,
  368. is_visible, release);
  369. }
  370. EXPORT_SYMBOL_GPL(iscsi_boot_create_initiator);
  371. /**
  372. * iscsi_boot_create_ethernet() - create boot ethernet sysfs dir
  373. * @boot_kset: boot kset
  374. * @index: the ethernet device id
  375. * @data: driver specific data
  376. * @show: attr show function
  377. * @is_visible: attr visibility function
  378. * @release: release function
  379. *
  380. * Note: The boot sysfs lib will free the data passed in for the caller
  381. * when all refs to the ethernet kobject have been released.
  382. */
  383. struct iscsi_boot_kobj *
  384. iscsi_boot_create_ethernet(struct iscsi_boot_kset *boot_kset, int index,
  385. void *data,
  386. ssize_t (*show) (void *data, int type, char *buf),
  387. umode_t (*is_visible) (void *data, int type),
  388. void (*release) (void *data))
  389. {
  390. return iscsi_boot_create_kobj(boot_kset,
  391. &iscsi_boot_ethernet_attr_group,
  392. "ethernet%d", index, data, show,
  393. is_visible, release);
  394. }
  395. EXPORT_SYMBOL_GPL(iscsi_boot_create_ethernet);
  396. /**
  397. * iscsi_boot_create_kset() - creates root sysfs tree
  398. * @set_name: name of root dir
  399. */
  400. struct iscsi_boot_kset *iscsi_boot_create_kset(const char *set_name)
  401. {
  402. struct iscsi_boot_kset *boot_kset;
  403. boot_kset = kzalloc(sizeof(*boot_kset), GFP_KERNEL);
  404. if (!boot_kset)
  405. return NULL;
  406. boot_kset->kset = kset_create_and_add(set_name, NULL, firmware_kobj);
  407. if (!boot_kset->kset) {
  408. kfree(boot_kset);
  409. return NULL;
  410. }
  411. INIT_LIST_HEAD(&boot_kset->kobj_list);
  412. return boot_kset;
  413. }
  414. EXPORT_SYMBOL_GPL(iscsi_boot_create_kset);
  415. /**
  416. * iscsi_boot_create_host_kset() - creates root sysfs tree for a scsi host
  417. * @hostno: host number of scsi host
  418. */
  419. struct iscsi_boot_kset *iscsi_boot_create_host_kset(unsigned int hostno)
  420. {
  421. struct iscsi_boot_kset *boot_kset;
  422. char *set_name;
  423. set_name = kasprintf(GFP_KERNEL, "iscsi_boot%u", hostno);
  424. if (!set_name)
  425. return NULL;
  426. boot_kset = iscsi_boot_create_kset(set_name);
  427. kfree(set_name);
  428. return boot_kset;
  429. }
  430. EXPORT_SYMBOL_GPL(iscsi_boot_create_host_kset);
  431. /**
  432. * iscsi_boot_destroy_kset() - destroy kset and kobjects under it
  433. * @boot_kset: boot kset
  434. *
  435. * This will remove the kset and kobjects and attrs under it.
  436. */
  437. void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)
  438. {
  439. struct iscsi_boot_kobj *boot_kobj, *tmp_kobj;
  440. if (!boot_kset)
  441. return;
  442. list_for_each_entry_safe(boot_kobj, tmp_kobj,
  443. &boot_kset->kobj_list, list)
  444. iscsi_boot_remove_kobj(boot_kobj);
  445. kset_unregister(boot_kset->kset);
  446. kfree(boot_kset);
  447. }
  448. EXPORT_SYMBOL_GPL(iscsi_boot_destroy_kset);