target_core_fabric_configfs.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*******************************************************************************
  2. * Filename: target_core_fabric_configfs.c
  3. *
  4. * This file contains generic fabric module configfs infrastructure for
  5. * TCM v4.x code
  6. *
  7. * (c) Copyright 2010-2012 RisingTide Systems LLC.
  8. *
  9. * Nicholas A. Bellinger <nab@linux-iscsi.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. ****************************************************************************/
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/utsname.h>
  24. #include <linux/init.h>
  25. #include <linux/fs.h>
  26. #include <linux/namei.h>
  27. #include <linux/slab.h>
  28. #include <linux/types.h>
  29. #include <linux/delay.h>
  30. #include <linux/unistd.h>
  31. #include <linux/string.h>
  32. #include <linux/syscalls.h>
  33. #include <linux/configfs.h>
  34. #include <target/target_core_base.h>
  35. #include <target/target_core_fabric.h>
  36. #include <target/target_core_fabric_configfs.h>
  37. #include <target/target_core_configfs.h>
  38. #include <target/configfs_macros.h>
  39. #include "target_core_internal.h"
  40. #include "target_core_alua.h"
  41. #include "target_core_pr.h"
  42. #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
  43. static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
  44. { \
  45. struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \
  46. struct config_item_type *cit = &tfc->tfc_##_name##_cit; \
  47. \
  48. cit->ct_item_ops = _item_ops; \
  49. cit->ct_group_ops = _group_ops; \
  50. cit->ct_attrs = _attrs; \
  51. cit->ct_owner = tf->tf_module; \
  52. pr_debug("Setup generic %s\n", __stringify(_name)); \
  53. }
  54. /* Start of tfc_tpg_mappedlun_cit */
  55. static int target_fabric_mappedlun_link(
  56. struct config_item *lun_acl_ci,
  57. struct config_item *lun_ci)
  58. {
  59. struct se_dev_entry *deve;
  60. struct se_lun *lun = container_of(to_config_group(lun_ci),
  61. struct se_lun, lun_group);
  62. struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
  63. struct se_lun_acl, se_lun_group);
  64. struct se_portal_group *se_tpg;
  65. struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
  66. int ret = 0, lun_access;
  67. if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) {
  68. pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:"
  69. " %p to struct lun: %p\n", lun_ci, lun);
  70. return -EFAULT;
  71. }
  72. /*
  73. * Ensure that the source port exists
  74. */
  75. if (!lun->lun_sep || !lun->lun_sep->sep_tpg) {
  76. pr_err("Source se_lun->lun_sep or lun->lun_sep->sep"
  77. "_tpg does not exist\n");
  78. return -EINVAL;
  79. }
  80. se_tpg = lun->lun_sep->sep_tpg;
  81. nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item;
  82. tpg_ci = &nacl_ci->ci_group->cg_item;
  83. wwn_ci = &tpg_ci->ci_group->cg_item;
  84. tpg_ci_s = &lun_ci->ci_parent->ci_group->cg_item;
  85. wwn_ci_s = &tpg_ci_s->ci_group->cg_item;
  86. /*
  87. * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT
  88. */
  89. if (strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) {
  90. pr_err("Illegal Initiator ACL SymLink outside of %s\n",
  91. config_item_name(wwn_ci));
  92. return -EINVAL;
  93. }
  94. if (strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) {
  95. pr_err("Illegal Initiator ACL Symlink outside of %s"
  96. " TPGT: %s\n", config_item_name(wwn_ci),
  97. config_item_name(tpg_ci));
  98. return -EINVAL;
  99. }
  100. /*
  101. * If this struct se_node_acl was dynamically generated with
  102. * tpg_1/attrib/generate_node_acls=1, use the existing deve->lun_flags,
  103. * which be will write protected (READ-ONLY) when
  104. * tpg_1/attrib/demo_mode_write_protect=1
  105. */
  106. spin_lock_irq(&lacl->se_lun_nacl->device_list_lock);
  107. deve = lacl->se_lun_nacl->device_list[lacl->mapped_lun];
  108. if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)
  109. lun_access = deve->lun_flags;
  110. else
  111. lun_access =
  112. (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect(
  113. se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY :
  114. TRANSPORT_LUNFLAGS_READ_WRITE;
  115. spin_unlock_irq(&lacl->se_lun_nacl->device_list_lock);
  116. /*
  117. * Determine the actual mapped LUN value user wants..
  118. *
  119. * This value is what the SCSI Initiator actually sees the
  120. * iscsi/$IQN/$TPGT/lun/lun_* as on their SCSI Initiator Ports.
  121. */
  122. ret = core_dev_add_initiator_node_lun_acl(se_tpg, lacl,
  123. lun->unpacked_lun, lun_access);
  124. return (ret < 0) ? -EINVAL : 0;
  125. }
  126. static int target_fabric_mappedlun_unlink(
  127. struct config_item *lun_acl_ci,
  128. struct config_item *lun_ci)
  129. {
  130. struct se_lun *lun;
  131. struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
  132. struct se_lun_acl, se_lun_group);
  133. struct se_node_acl *nacl = lacl->se_lun_nacl;
  134. struct se_dev_entry *deve = nacl->device_list[lacl->mapped_lun];
  135. struct se_portal_group *se_tpg;
  136. /*
  137. * Determine if the underlying MappedLUN has already been released..
  138. */
  139. if (!deve->se_lun)
  140. return 0;
  141. lun = container_of(to_config_group(lun_ci), struct se_lun, lun_group);
  142. se_tpg = lun->lun_sep->sep_tpg;
  143. core_dev_del_initiator_node_lun_acl(se_tpg, lun, lacl);
  144. return 0;
  145. }
  146. CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl);
  147. #define TCM_MAPPEDLUN_ATTR(_name, _mode) \
  148. static struct target_fabric_mappedlun_attribute target_fabric_mappedlun_##_name = \
  149. __CONFIGFS_EATTR(_name, _mode, \
  150. target_fabric_mappedlun_show_##_name, \
  151. target_fabric_mappedlun_store_##_name);
  152. static ssize_t target_fabric_mappedlun_show_write_protect(
  153. struct se_lun_acl *lacl,
  154. char *page)
  155. {
  156. struct se_node_acl *se_nacl = lacl->se_lun_nacl;
  157. struct se_dev_entry *deve;
  158. ssize_t len;
  159. spin_lock_irq(&se_nacl->device_list_lock);
  160. deve = se_nacl->device_list[lacl->mapped_lun];
  161. len = sprintf(page, "%d\n",
  162. (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ?
  163. 1 : 0);
  164. spin_unlock_irq(&se_nacl->device_list_lock);
  165. return len;
  166. }
  167. static ssize_t target_fabric_mappedlun_store_write_protect(
  168. struct se_lun_acl *lacl,
  169. const char *page,
  170. size_t count)
  171. {
  172. struct se_node_acl *se_nacl = lacl->se_lun_nacl;
  173. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  174. unsigned long op;
  175. if (strict_strtoul(page, 0, &op))
  176. return -EINVAL;
  177. if ((op != 1) && (op != 0))
  178. return -EINVAL;
  179. core_update_device_list_access(lacl->mapped_lun, (op) ?
  180. TRANSPORT_LUNFLAGS_READ_ONLY :
  181. TRANSPORT_LUNFLAGS_READ_WRITE,
  182. lacl->se_lun_nacl);
  183. pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
  184. " Mapped LUN: %u Write Protect bit to %s\n",
  185. se_tpg->se_tpg_tfo->get_fabric_name(),
  186. lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF");
  187. return count;
  188. }
  189. TCM_MAPPEDLUN_ATTR(write_protect, S_IRUGO | S_IWUSR);
  190. CONFIGFS_EATTR_OPS(target_fabric_mappedlun, se_lun_acl, se_lun_group);
  191. static void target_fabric_mappedlun_release(struct config_item *item)
  192. {
  193. struct se_lun_acl *lacl = container_of(to_config_group(item),
  194. struct se_lun_acl, se_lun_group);
  195. struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg;
  196. core_dev_free_initiator_node_lun_acl(se_tpg, lacl);
  197. }
  198. static struct configfs_attribute *target_fabric_mappedlun_attrs[] = {
  199. &target_fabric_mappedlun_write_protect.attr,
  200. NULL,
  201. };
  202. static struct configfs_item_operations target_fabric_mappedlun_item_ops = {
  203. .release = target_fabric_mappedlun_release,
  204. .show_attribute = target_fabric_mappedlun_attr_show,
  205. .store_attribute = target_fabric_mappedlun_attr_store,
  206. .allow_link = target_fabric_mappedlun_link,
  207. .drop_link = target_fabric_mappedlun_unlink,
  208. };
  209. TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL,
  210. target_fabric_mappedlun_attrs);
  211. /* End of tfc_tpg_mappedlun_cit */
  212. /* Start of tfc_tpg_mappedlun_port_cit */
  213. static struct config_group *target_core_mappedlun_stat_mkdir(
  214. struct config_group *group,
  215. const char *name)
  216. {
  217. return ERR_PTR(-ENOSYS);
  218. }
  219. static void target_core_mappedlun_stat_rmdir(
  220. struct config_group *group,
  221. struct config_item *item)
  222. {
  223. return;
  224. }
  225. static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = {
  226. .make_group = target_core_mappedlun_stat_mkdir,
  227. .drop_item = target_core_mappedlun_stat_rmdir,
  228. };
  229. TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops,
  230. NULL);
  231. /* End of tfc_tpg_mappedlun_port_cit */
  232. /* Start of tfc_tpg_nacl_attrib_cit */
  233. CONFIGFS_EATTR_OPS(target_fabric_nacl_attrib, se_node_acl, acl_attrib_group);
  234. static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = {
  235. .show_attribute = target_fabric_nacl_attrib_attr_show,
  236. .store_attribute = target_fabric_nacl_attrib_attr_store,
  237. };
  238. TF_CIT_SETUP(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL, NULL);
  239. /* End of tfc_tpg_nacl_attrib_cit */
  240. /* Start of tfc_tpg_nacl_auth_cit */
  241. CONFIGFS_EATTR_OPS(target_fabric_nacl_auth, se_node_acl, acl_auth_group);
  242. static struct configfs_item_operations target_fabric_nacl_auth_item_ops = {
  243. .show_attribute = target_fabric_nacl_auth_attr_show,
  244. .store_attribute = target_fabric_nacl_auth_attr_store,
  245. };
  246. TF_CIT_SETUP(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL, NULL);
  247. /* End of tfc_tpg_nacl_auth_cit */
  248. /* Start of tfc_tpg_nacl_param_cit */
  249. CONFIGFS_EATTR_OPS(target_fabric_nacl_param, se_node_acl, acl_param_group);
  250. static struct configfs_item_operations target_fabric_nacl_param_item_ops = {
  251. .show_attribute = target_fabric_nacl_param_attr_show,
  252. .store_attribute = target_fabric_nacl_param_attr_store,
  253. };
  254. TF_CIT_SETUP(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL, NULL);
  255. /* End of tfc_tpg_nacl_param_cit */
  256. /* Start of tfc_tpg_nacl_base_cit */
  257. CONFIGFS_EATTR_OPS(target_fabric_nacl_base, se_node_acl, acl_group);
  258. static struct config_group *target_fabric_make_mappedlun(
  259. struct config_group *group,
  260. const char *name)
  261. {
  262. struct se_node_acl *se_nacl = container_of(group,
  263. struct se_node_acl, acl_group);
  264. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  265. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  266. struct se_lun_acl *lacl;
  267. struct config_item *acl_ci;
  268. struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
  269. char *buf;
  270. unsigned long mapped_lun;
  271. int ret = 0;
  272. acl_ci = &group->cg_item;
  273. if (!acl_ci) {
  274. pr_err("Unable to locatel acl_ci\n");
  275. return NULL;
  276. }
  277. buf = kzalloc(strlen(name) + 1, GFP_KERNEL);
  278. if (!buf) {
  279. pr_err("Unable to allocate memory for name buf\n");
  280. return ERR_PTR(-ENOMEM);
  281. }
  282. snprintf(buf, strlen(name) + 1, "%s", name);
  283. /*
  284. * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID.
  285. */
  286. if (strstr(buf, "lun_") != buf) {
  287. pr_err("Unable to locate \"lun_\" from buf: %s"
  288. " name: %s\n", buf, name);
  289. ret = -EINVAL;
  290. goto out;
  291. }
  292. /*
  293. * Determine the Mapped LUN value. This is what the SCSI Initiator
  294. * Port will actually see.
  295. */
  296. if (strict_strtoul(buf + 4, 0, &mapped_lun) || mapped_lun > UINT_MAX) {
  297. ret = -EINVAL;
  298. goto out;
  299. }
  300. lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl,
  301. mapped_lun, &ret);
  302. if (!lacl) {
  303. ret = -EINVAL;
  304. goto out;
  305. }
  306. lacl_cg = &lacl->se_lun_group;
  307. lacl_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
  308. GFP_KERNEL);
  309. if (!lacl_cg->default_groups) {
  310. pr_err("Unable to allocate lacl_cg->default_groups\n");
  311. ret = -ENOMEM;
  312. goto out;
  313. }
  314. config_group_init_type_name(&lacl->se_lun_group, name,
  315. &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_cit);
  316. config_group_init_type_name(&lacl->ml_stat_grps.stat_group,
  317. "statistics", &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_stat_cit);
  318. lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group;
  319. lacl_cg->default_groups[1] = NULL;
  320. ml_stat_grp = &lacl->ml_stat_grps.stat_group;
  321. ml_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 3,
  322. GFP_KERNEL);
  323. if (!ml_stat_grp->default_groups) {
  324. pr_err("Unable to allocate ml_stat_grp->default_groups\n");
  325. ret = -ENOMEM;
  326. goto out;
  327. }
  328. target_stat_setup_mappedlun_default_groups(lacl);
  329. kfree(buf);
  330. return &lacl->se_lun_group;
  331. out:
  332. if (lacl_cg)
  333. kfree(lacl_cg->default_groups);
  334. kfree(buf);
  335. return ERR_PTR(ret);
  336. }
  337. static void target_fabric_drop_mappedlun(
  338. struct config_group *group,
  339. struct config_item *item)
  340. {
  341. struct se_lun_acl *lacl = container_of(to_config_group(item),
  342. struct se_lun_acl, se_lun_group);
  343. struct config_item *df_item;
  344. struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
  345. int i;
  346. ml_stat_grp = &lacl->ml_stat_grps.stat_group;
  347. for (i = 0; ml_stat_grp->default_groups[i]; i++) {
  348. df_item = &ml_stat_grp->default_groups[i]->cg_item;
  349. ml_stat_grp->default_groups[i] = NULL;
  350. config_item_put(df_item);
  351. }
  352. kfree(ml_stat_grp->default_groups);
  353. lacl_cg = &lacl->se_lun_group;
  354. for (i = 0; lacl_cg->default_groups[i]; i++) {
  355. df_item = &lacl_cg->default_groups[i]->cg_item;
  356. lacl_cg->default_groups[i] = NULL;
  357. config_item_put(df_item);
  358. }
  359. kfree(lacl_cg->default_groups);
  360. config_item_put(item);
  361. }
  362. static void target_fabric_nacl_base_release(struct config_item *item)
  363. {
  364. struct se_node_acl *se_nacl = container_of(to_config_group(item),
  365. struct se_node_acl, acl_group);
  366. struct se_portal_group *se_tpg = se_nacl->se_tpg;
  367. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  368. tf->tf_ops.fabric_drop_nodeacl(se_nacl);
  369. }
  370. static struct configfs_item_operations target_fabric_nacl_base_item_ops = {
  371. .release = target_fabric_nacl_base_release,
  372. .show_attribute = target_fabric_nacl_base_attr_show,
  373. .store_attribute = target_fabric_nacl_base_attr_store,
  374. };
  375. static struct configfs_group_operations target_fabric_nacl_base_group_ops = {
  376. .make_group = target_fabric_make_mappedlun,
  377. .drop_item = target_fabric_drop_mappedlun,
  378. };
  379. TF_CIT_SETUP(tpg_nacl_base, &target_fabric_nacl_base_item_ops,
  380. &target_fabric_nacl_base_group_ops, NULL);
  381. /* End of tfc_tpg_nacl_base_cit */
  382. /* Start of tfc_node_fabric_stats_cit */
  383. /*
  384. * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group
  385. * to allow fabrics access to ->acl_fabric_stat_group->default_groups[]
  386. */
  387. TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL);
  388. /* End of tfc_wwn_fabric_stats_cit */
  389. /* Start of tfc_tpg_nacl_cit */
  390. static struct config_group *target_fabric_make_nodeacl(
  391. struct config_group *group,
  392. const char *name)
  393. {
  394. struct se_portal_group *se_tpg = container_of(group,
  395. struct se_portal_group, tpg_acl_group);
  396. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  397. struct se_node_acl *se_nacl;
  398. struct config_group *nacl_cg;
  399. if (!tf->tf_ops.fabric_make_nodeacl) {
  400. pr_err("tf->tf_ops.fabric_make_nodeacl is NULL\n");
  401. return ERR_PTR(-ENOSYS);
  402. }
  403. se_nacl = tf->tf_ops.fabric_make_nodeacl(se_tpg, group, name);
  404. if (IS_ERR(se_nacl))
  405. return ERR_CAST(se_nacl);
  406. nacl_cg = &se_nacl->acl_group;
  407. nacl_cg->default_groups = se_nacl->acl_default_groups;
  408. nacl_cg->default_groups[0] = &se_nacl->acl_attrib_group;
  409. nacl_cg->default_groups[1] = &se_nacl->acl_auth_group;
  410. nacl_cg->default_groups[2] = &se_nacl->acl_param_group;
  411. nacl_cg->default_groups[3] = &se_nacl->acl_fabric_stat_group;
  412. nacl_cg->default_groups[4] = NULL;
  413. config_group_init_type_name(&se_nacl->acl_group, name,
  414. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_base_cit);
  415. config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib",
  416. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_attrib_cit);
  417. config_group_init_type_name(&se_nacl->acl_auth_group, "auth",
  418. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_auth_cit);
  419. config_group_init_type_name(&se_nacl->acl_param_group, "param",
  420. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_param_cit);
  421. config_group_init_type_name(&se_nacl->acl_fabric_stat_group,
  422. "fabric_statistics",
  423. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_stat_cit);
  424. return &se_nacl->acl_group;
  425. }
  426. static void target_fabric_drop_nodeacl(
  427. struct config_group *group,
  428. struct config_item *item)
  429. {
  430. struct se_node_acl *se_nacl = container_of(to_config_group(item),
  431. struct se_node_acl, acl_group);
  432. struct config_item *df_item;
  433. struct config_group *nacl_cg;
  434. int i;
  435. nacl_cg = &se_nacl->acl_group;
  436. for (i = 0; nacl_cg->default_groups[i]; i++) {
  437. df_item = &nacl_cg->default_groups[i]->cg_item;
  438. nacl_cg->default_groups[i] = NULL;
  439. config_item_put(df_item);
  440. }
  441. /*
  442. * struct se_node_acl free is done in target_fabric_nacl_base_release()
  443. */
  444. config_item_put(item);
  445. }
  446. static struct configfs_group_operations target_fabric_nacl_group_ops = {
  447. .make_group = target_fabric_make_nodeacl,
  448. .drop_item = target_fabric_drop_nodeacl,
  449. };
  450. TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL);
  451. /* End of tfc_tpg_nacl_cit */
  452. /* Start of tfc_tpg_np_base_cit */
  453. CONFIGFS_EATTR_OPS(target_fabric_np_base, se_tpg_np, tpg_np_group);
  454. static void target_fabric_np_base_release(struct config_item *item)
  455. {
  456. struct se_tpg_np *se_tpg_np = container_of(to_config_group(item),
  457. struct se_tpg_np, tpg_np_group);
  458. struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent;
  459. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  460. tf->tf_ops.fabric_drop_np(se_tpg_np);
  461. }
  462. static struct configfs_item_operations target_fabric_np_base_item_ops = {
  463. .release = target_fabric_np_base_release,
  464. .show_attribute = target_fabric_np_base_attr_show,
  465. .store_attribute = target_fabric_np_base_attr_store,
  466. };
  467. TF_CIT_SETUP(tpg_np_base, &target_fabric_np_base_item_ops, NULL, NULL);
  468. /* End of tfc_tpg_np_base_cit */
  469. /* Start of tfc_tpg_np_cit */
  470. static struct config_group *target_fabric_make_np(
  471. struct config_group *group,
  472. const char *name)
  473. {
  474. struct se_portal_group *se_tpg = container_of(group,
  475. struct se_portal_group, tpg_np_group);
  476. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  477. struct se_tpg_np *se_tpg_np;
  478. if (!tf->tf_ops.fabric_make_np) {
  479. pr_err("tf->tf_ops.fabric_make_np is NULL\n");
  480. return ERR_PTR(-ENOSYS);
  481. }
  482. se_tpg_np = tf->tf_ops.fabric_make_np(se_tpg, group, name);
  483. if (!se_tpg_np || IS_ERR(se_tpg_np))
  484. return ERR_PTR(-EINVAL);
  485. se_tpg_np->tpg_np_parent = se_tpg;
  486. config_group_init_type_name(&se_tpg_np->tpg_np_group, name,
  487. &TF_CIT_TMPL(tf)->tfc_tpg_np_base_cit);
  488. return &se_tpg_np->tpg_np_group;
  489. }
  490. static void target_fabric_drop_np(
  491. struct config_group *group,
  492. struct config_item *item)
  493. {
  494. /*
  495. * struct se_tpg_np is released via target_fabric_np_base_release()
  496. */
  497. config_item_put(item);
  498. }
  499. static struct configfs_group_operations target_fabric_np_group_ops = {
  500. .make_group = &target_fabric_make_np,
  501. .drop_item = &target_fabric_drop_np,
  502. };
  503. TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL);
  504. /* End of tfc_tpg_np_cit */
  505. /* Start of tfc_tpg_port_cit */
  506. CONFIGFS_EATTR_STRUCT(target_fabric_port, se_lun);
  507. #define TCM_PORT_ATTR(_name, _mode) \
  508. static struct target_fabric_port_attribute target_fabric_port_##_name = \
  509. __CONFIGFS_EATTR(_name, _mode, \
  510. target_fabric_port_show_attr_##_name, \
  511. target_fabric_port_store_attr_##_name);
  512. #define TCM_PORT_ATTOR_RO(_name) \
  513. __CONFIGFS_EATTR_RO(_name, \
  514. target_fabric_port_show_attr_##_name);
  515. /*
  516. * alua_tg_pt_gp
  517. */
  518. static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp(
  519. struct se_lun *lun,
  520. char *page)
  521. {
  522. if (!lun || !lun->lun_sep)
  523. return -ENODEV;
  524. return core_alua_show_tg_pt_gp_info(lun->lun_sep, page);
  525. }
  526. static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp(
  527. struct se_lun *lun,
  528. const char *page,
  529. size_t count)
  530. {
  531. if (!lun || !lun->lun_sep)
  532. return -ENODEV;
  533. return core_alua_store_tg_pt_gp_info(lun->lun_sep, page, count);
  534. }
  535. TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR);
  536. /*
  537. * alua_tg_pt_offline
  538. */
  539. static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline(
  540. struct se_lun *lun,
  541. char *page)
  542. {
  543. if (!lun || !lun->lun_sep)
  544. return -ENODEV;
  545. return core_alua_show_offline_bit(lun, page);
  546. }
  547. static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline(
  548. struct se_lun *lun,
  549. const char *page,
  550. size_t count)
  551. {
  552. if (!lun || !lun->lun_sep)
  553. return -ENODEV;
  554. return core_alua_store_offline_bit(lun, page, count);
  555. }
  556. TCM_PORT_ATTR(alua_tg_pt_offline, S_IRUGO | S_IWUSR);
  557. /*
  558. * alua_tg_pt_status
  559. */
  560. static ssize_t target_fabric_port_show_attr_alua_tg_pt_status(
  561. struct se_lun *lun,
  562. char *page)
  563. {
  564. if (!lun || !lun->lun_sep)
  565. return -ENODEV;
  566. return core_alua_show_secondary_status(lun, page);
  567. }
  568. static ssize_t target_fabric_port_store_attr_alua_tg_pt_status(
  569. struct se_lun *lun,
  570. const char *page,
  571. size_t count)
  572. {
  573. if (!lun || !lun->lun_sep)
  574. return -ENODEV;
  575. return core_alua_store_secondary_status(lun, page, count);
  576. }
  577. TCM_PORT_ATTR(alua_tg_pt_status, S_IRUGO | S_IWUSR);
  578. /*
  579. * alua_tg_pt_write_md
  580. */
  581. static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md(
  582. struct se_lun *lun,
  583. char *page)
  584. {
  585. if (!lun || !lun->lun_sep)
  586. return -ENODEV;
  587. return core_alua_show_secondary_write_metadata(lun, page);
  588. }
  589. static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md(
  590. struct se_lun *lun,
  591. const char *page,
  592. size_t count)
  593. {
  594. if (!lun || !lun->lun_sep)
  595. return -ENODEV;
  596. return core_alua_store_secondary_write_metadata(lun, page, count);
  597. }
  598. TCM_PORT_ATTR(alua_tg_pt_write_md, S_IRUGO | S_IWUSR);
  599. static struct configfs_attribute *target_fabric_port_attrs[] = {
  600. &target_fabric_port_alua_tg_pt_gp.attr,
  601. &target_fabric_port_alua_tg_pt_offline.attr,
  602. &target_fabric_port_alua_tg_pt_status.attr,
  603. &target_fabric_port_alua_tg_pt_write_md.attr,
  604. NULL,
  605. };
  606. CONFIGFS_EATTR_OPS(target_fabric_port, se_lun, lun_group);
  607. static int target_fabric_port_link(
  608. struct config_item *lun_ci,
  609. struct config_item *se_dev_ci)
  610. {
  611. struct config_item *tpg_ci;
  612. struct se_lun *lun = container_of(to_config_group(lun_ci),
  613. struct se_lun, lun_group);
  614. struct se_lun *lun_p;
  615. struct se_portal_group *se_tpg;
  616. struct se_device *dev =
  617. container_of(to_config_group(se_dev_ci), struct se_device, dev_group);
  618. struct target_fabric_configfs *tf;
  619. int ret;
  620. if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) {
  621. pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:"
  622. " %p to struct se_device: %p\n", se_dev_ci, dev);
  623. return -EFAULT;
  624. }
  625. if (!(dev->dev_flags & DF_CONFIGURED)) {
  626. pr_err("se_device not configured yet, cannot port link\n");
  627. return -ENODEV;
  628. }
  629. tpg_ci = &lun_ci->ci_parent->ci_group->cg_item;
  630. se_tpg = container_of(to_config_group(tpg_ci),
  631. struct se_portal_group, tpg_group);
  632. tf = se_tpg->se_tpg_wwn->wwn_tf;
  633. if (lun->lun_se_dev != NULL) {
  634. pr_err("Port Symlink already exists\n");
  635. return -EEXIST;
  636. }
  637. lun_p = core_dev_add_lun(se_tpg, dev, lun->unpacked_lun);
  638. if (IS_ERR(lun_p)) {
  639. pr_err("core_dev_add_lun() failed\n");
  640. ret = PTR_ERR(lun_p);
  641. goto out;
  642. }
  643. if (tf->tf_ops.fabric_post_link) {
  644. /*
  645. * Call the optional fabric_post_link() to allow a
  646. * fabric module to setup any additional state once
  647. * core_dev_add_lun() has been called..
  648. */
  649. tf->tf_ops.fabric_post_link(se_tpg, lun);
  650. }
  651. return 0;
  652. out:
  653. return ret;
  654. }
  655. static int target_fabric_port_unlink(
  656. struct config_item *lun_ci,
  657. struct config_item *se_dev_ci)
  658. {
  659. struct se_lun *lun = container_of(to_config_group(lun_ci),
  660. struct se_lun, lun_group);
  661. struct se_portal_group *se_tpg = lun->lun_sep->sep_tpg;
  662. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  663. if (tf->tf_ops.fabric_pre_unlink) {
  664. /*
  665. * Call the optional fabric_pre_unlink() to allow a
  666. * fabric module to release any additional stat before
  667. * core_dev_del_lun() is called.
  668. */
  669. tf->tf_ops.fabric_pre_unlink(se_tpg, lun);
  670. }
  671. core_dev_del_lun(se_tpg, lun->unpacked_lun);
  672. return 0;
  673. }
  674. static struct configfs_item_operations target_fabric_port_item_ops = {
  675. .show_attribute = target_fabric_port_attr_show,
  676. .store_attribute = target_fabric_port_attr_store,
  677. .allow_link = target_fabric_port_link,
  678. .drop_link = target_fabric_port_unlink,
  679. };
  680. TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs);
  681. /* End of tfc_tpg_port_cit */
  682. /* Start of tfc_tpg_port_stat_cit */
  683. static struct config_group *target_core_port_stat_mkdir(
  684. struct config_group *group,
  685. const char *name)
  686. {
  687. return ERR_PTR(-ENOSYS);
  688. }
  689. static void target_core_port_stat_rmdir(
  690. struct config_group *group,
  691. struct config_item *item)
  692. {
  693. return;
  694. }
  695. static struct configfs_group_operations target_fabric_port_stat_group_ops = {
  696. .make_group = target_core_port_stat_mkdir,
  697. .drop_item = target_core_port_stat_rmdir,
  698. };
  699. TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL);
  700. /* End of tfc_tpg_port_stat_cit */
  701. /* Start of tfc_tpg_lun_cit */
  702. static struct config_group *target_fabric_make_lun(
  703. struct config_group *group,
  704. const char *name)
  705. {
  706. struct se_lun *lun;
  707. struct se_portal_group *se_tpg = container_of(group,
  708. struct se_portal_group, tpg_lun_group);
  709. struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
  710. struct config_group *lun_cg = NULL, *port_stat_grp = NULL;
  711. unsigned long unpacked_lun;
  712. int errno;
  713. if (strstr(name, "lun_") != name) {
  714. pr_err("Unable to locate \'_\" in"
  715. " \"lun_$LUN_NUMBER\"\n");
  716. return ERR_PTR(-EINVAL);
  717. }
  718. if (strict_strtoul(name + 4, 0, &unpacked_lun) || unpacked_lun > UINT_MAX)
  719. return ERR_PTR(-EINVAL);
  720. lun = core_get_lun_from_tpg(se_tpg, unpacked_lun);
  721. if (!lun)
  722. return ERR_PTR(-EINVAL);
  723. lun_cg = &lun->lun_group;
  724. lun_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
  725. GFP_KERNEL);
  726. if (!lun_cg->default_groups) {
  727. pr_err("Unable to allocate lun_cg->default_groups\n");
  728. return ERR_PTR(-ENOMEM);
  729. }
  730. config_group_init_type_name(&lun->lun_group, name,
  731. &TF_CIT_TMPL(tf)->tfc_tpg_port_cit);
  732. config_group_init_type_name(&lun->port_stat_grps.stat_group,
  733. "statistics", &TF_CIT_TMPL(tf)->tfc_tpg_port_stat_cit);
  734. lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group;
  735. lun_cg->default_groups[1] = NULL;
  736. port_stat_grp = &lun->port_stat_grps.stat_group;
  737. port_stat_grp->default_groups = kzalloc(sizeof(struct config_group) * 3,
  738. GFP_KERNEL);
  739. if (!port_stat_grp->default_groups) {
  740. pr_err("Unable to allocate port_stat_grp->default_groups\n");
  741. errno = -ENOMEM;
  742. goto out;
  743. }
  744. target_stat_setup_port_default_groups(lun);
  745. return &lun->lun_group;
  746. out:
  747. if (lun_cg)
  748. kfree(lun_cg->default_groups);
  749. return ERR_PTR(errno);
  750. }
  751. static void target_fabric_drop_lun(
  752. struct config_group *group,
  753. struct config_item *item)
  754. {
  755. struct se_lun *lun = container_of(to_config_group(item),
  756. struct se_lun, lun_group);
  757. struct config_item *df_item;
  758. struct config_group *lun_cg, *port_stat_grp;
  759. int i;
  760. port_stat_grp = &lun->port_stat_grps.stat_group;
  761. for (i = 0; port_stat_grp->default_groups[i]; i++) {
  762. df_item = &port_stat_grp->default_groups[i]->cg_item;
  763. port_stat_grp->default_groups[i] = NULL;
  764. config_item_put(df_item);
  765. }
  766. kfree(port_stat_grp->default_groups);
  767. lun_cg = &lun->lun_group;
  768. for (i = 0; lun_cg->default_groups[i]; i++) {
  769. df_item = &lun_cg->default_groups[i]->cg_item;
  770. lun_cg->default_groups[i] = NULL;
  771. config_item_put(df_item);
  772. }
  773. kfree(lun_cg->default_groups);
  774. config_item_put(item);
  775. }
  776. static struct configfs_group_operations target_fabric_lun_group_ops = {
  777. .make_group = &target_fabric_make_lun,
  778. .drop_item = &target_fabric_drop_lun,
  779. };
  780. TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL);
  781. /* End of tfc_tpg_lun_cit */
  782. /* Start of tfc_tpg_attrib_cit */
  783. CONFIGFS_EATTR_OPS(target_fabric_tpg_attrib, se_portal_group, tpg_attrib_group);
  784. static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = {
  785. .show_attribute = target_fabric_tpg_attrib_attr_show,
  786. .store_attribute = target_fabric_tpg_attrib_attr_store,
  787. };
  788. TF_CIT_SETUP(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL, NULL);
  789. /* End of tfc_tpg_attrib_cit */
  790. /* Start of tfc_tpg_param_cit */
  791. CONFIGFS_EATTR_OPS(target_fabric_tpg_param, se_portal_group, tpg_param_group);
  792. static struct configfs_item_operations target_fabric_tpg_param_item_ops = {
  793. .show_attribute = target_fabric_tpg_param_attr_show,
  794. .store_attribute = target_fabric_tpg_param_attr_store,
  795. };
  796. TF_CIT_SETUP(tpg_param, &target_fabric_tpg_param_item_ops, NULL, NULL);
  797. /* End of tfc_tpg_param_cit */
  798. /* Start of tfc_tpg_base_cit */
  799. /*
  800. * For use with TF_TPG_ATTR() and TF_TPG_ATTR_RO()
  801. */
  802. CONFIGFS_EATTR_OPS(target_fabric_tpg, se_portal_group, tpg_group);
  803. static void target_fabric_tpg_release(struct config_item *item)
  804. {
  805. struct se_portal_group *se_tpg = container_of(to_config_group(item),
  806. struct se_portal_group, tpg_group);
  807. struct se_wwn *wwn = se_tpg->se_tpg_wwn;
  808. struct target_fabric_configfs *tf = wwn->wwn_tf;
  809. tf->tf_ops.fabric_drop_tpg(se_tpg);
  810. }
  811. static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
  812. .release = target_fabric_tpg_release,
  813. .show_attribute = target_fabric_tpg_attr_show,
  814. .store_attribute = target_fabric_tpg_attr_store,
  815. };
  816. TF_CIT_SETUP(tpg_base, &target_fabric_tpg_base_item_ops, NULL, NULL);
  817. /* End of tfc_tpg_base_cit */
  818. /* Start of tfc_tpg_cit */
  819. static struct config_group *target_fabric_make_tpg(
  820. struct config_group *group,
  821. const char *name)
  822. {
  823. struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group);
  824. struct target_fabric_configfs *tf = wwn->wwn_tf;
  825. struct se_portal_group *se_tpg;
  826. if (!tf->tf_ops.fabric_make_tpg) {
  827. pr_err("tf->tf_ops.fabric_make_tpg is NULL\n");
  828. return ERR_PTR(-ENOSYS);
  829. }
  830. se_tpg = tf->tf_ops.fabric_make_tpg(wwn, group, name);
  831. if (!se_tpg || IS_ERR(se_tpg))
  832. return ERR_PTR(-EINVAL);
  833. /*
  834. * Setup default groups from pre-allocated se_tpg->tpg_default_groups
  835. */
  836. se_tpg->tpg_group.default_groups = se_tpg->tpg_default_groups;
  837. se_tpg->tpg_group.default_groups[0] = &se_tpg->tpg_lun_group;
  838. se_tpg->tpg_group.default_groups[1] = &se_tpg->tpg_np_group;
  839. se_tpg->tpg_group.default_groups[2] = &se_tpg->tpg_acl_group;
  840. se_tpg->tpg_group.default_groups[3] = &se_tpg->tpg_attrib_group;
  841. se_tpg->tpg_group.default_groups[4] = &se_tpg->tpg_param_group;
  842. se_tpg->tpg_group.default_groups[5] = NULL;
  843. config_group_init_type_name(&se_tpg->tpg_group, name,
  844. &TF_CIT_TMPL(tf)->tfc_tpg_base_cit);
  845. config_group_init_type_name(&se_tpg->tpg_lun_group, "lun",
  846. &TF_CIT_TMPL(tf)->tfc_tpg_lun_cit);
  847. config_group_init_type_name(&se_tpg->tpg_np_group, "np",
  848. &TF_CIT_TMPL(tf)->tfc_tpg_np_cit);
  849. config_group_init_type_name(&se_tpg->tpg_acl_group, "acls",
  850. &TF_CIT_TMPL(tf)->tfc_tpg_nacl_cit);
  851. config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib",
  852. &TF_CIT_TMPL(tf)->tfc_tpg_attrib_cit);
  853. config_group_init_type_name(&se_tpg->tpg_param_group, "param",
  854. &TF_CIT_TMPL(tf)->tfc_tpg_param_cit);
  855. return &se_tpg->tpg_group;
  856. }
  857. static void target_fabric_drop_tpg(
  858. struct config_group *group,
  859. struct config_item *item)
  860. {
  861. struct se_portal_group *se_tpg = container_of(to_config_group(item),
  862. struct se_portal_group, tpg_group);
  863. struct config_group *tpg_cg = &se_tpg->tpg_group;
  864. struct config_item *df_item;
  865. int i;
  866. /*
  867. * Release default groups, but do not release tpg_cg->default_groups
  868. * memory as it is statically allocated at se_tpg->tpg_default_groups.
  869. */
  870. for (i = 0; tpg_cg->default_groups[i]; i++) {
  871. df_item = &tpg_cg->default_groups[i]->cg_item;
  872. tpg_cg->default_groups[i] = NULL;
  873. config_item_put(df_item);
  874. }
  875. config_item_put(item);
  876. }
  877. static void target_fabric_release_wwn(struct config_item *item)
  878. {
  879. struct se_wwn *wwn = container_of(to_config_group(item),
  880. struct se_wwn, wwn_group);
  881. struct target_fabric_configfs *tf = wwn->wwn_tf;
  882. tf->tf_ops.fabric_drop_wwn(wwn);
  883. }
  884. static struct configfs_item_operations target_fabric_tpg_item_ops = {
  885. .release = target_fabric_release_wwn,
  886. };
  887. static struct configfs_group_operations target_fabric_tpg_group_ops = {
  888. .make_group = target_fabric_make_tpg,
  889. .drop_item = target_fabric_drop_tpg,
  890. };
  891. TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops,
  892. NULL);
  893. /* End of tfc_tpg_cit */
  894. /* Start of tfc_wwn_fabric_stats_cit */
  895. /*
  896. * This is used as a placeholder for struct se_wwn->fabric_stat_group
  897. * to allow fabrics access to ->fabric_stat_group->default_groups[]
  898. */
  899. TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL);
  900. /* End of tfc_wwn_fabric_stats_cit */
  901. /* Start of tfc_wwn_cit */
  902. static struct config_group *target_fabric_make_wwn(
  903. struct config_group *group,
  904. const char *name)
  905. {
  906. struct target_fabric_configfs *tf = container_of(group,
  907. struct target_fabric_configfs, tf_group);
  908. struct se_wwn *wwn;
  909. if (!tf->tf_ops.fabric_make_wwn) {
  910. pr_err("tf->tf_ops.fabric_make_wwn is NULL\n");
  911. return ERR_PTR(-ENOSYS);
  912. }
  913. wwn = tf->tf_ops.fabric_make_wwn(tf, group, name);
  914. if (!wwn || IS_ERR(wwn))
  915. return ERR_PTR(-EINVAL);
  916. wwn->wwn_tf = tf;
  917. /*
  918. * Setup default groups from pre-allocated wwn->wwn_default_groups
  919. */
  920. wwn->wwn_group.default_groups = wwn->wwn_default_groups;
  921. wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group;
  922. wwn->wwn_group.default_groups[1] = NULL;
  923. config_group_init_type_name(&wwn->wwn_group, name,
  924. &TF_CIT_TMPL(tf)->tfc_tpg_cit);
  925. config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics",
  926. &TF_CIT_TMPL(tf)->tfc_wwn_fabric_stats_cit);
  927. return &wwn->wwn_group;
  928. }
  929. static void target_fabric_drop_wwn(
  930. struct config_group *group,
  931. struct config_item *item)
  932. {
  933. struct se_wwn *wwn = container_of(to_config_group(item),
  934. struct se_wwn, wwn_group);
  935. struct config_item *df_item;
  936. struct config_group *cg = &wwn->wwn_group;
  937. int i;
  938. for (i = 0; cg->default_groups[i]; i++) {
  939. df_item = &cg->default_groups[i]->cg_item;
  940. cg->default_groups[i] = NULL;
  941. config_item_put(df_item);
  942. }
  943. config_item_put(item);
  944. }
  945. static struct configfs_group_operations target_fabric_wwn_group_ops = {
  946. .make_group = target_fabric_make_wwn,
  947. .drop_item = target_fabric_drop_wwn,
  948. };
  949. /*
  950. * For use with TF_WWN_ATTR() and TF_WWN_ATTR_RO()
  951. */
  952. CONFIGFS_EATTR_OPS(target_fabric_wwn, target_fabric_configfs, tf_group);
  953. static struct configfs_item_operations target_fabric_wwn_item_ops = {
  954. .show_attribute = target_fabric_wwn_attr_show,
  955. .store_attribute = target_fabric_wwn_attr_store,
  956. };
  957. TF_CIT_SETUP(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops, NULL);
  958. /* End of tfc_wwn_cit */
  959. /* Start of tfc_discovery_cit */
  960. CONFIGFS_EATTR_OPS(target_fabric_discovery, target_fabric_configfs,
  961. tf_disc_group);
  962. static struct configfs_item_operations target_fabric_discovery_item_ops = {
  963. .show_attribute = target_fabric_discovery_attr_show,
  964. .store_attribute = target_fabric_discovery_attr_store,
  965. };
  966. TF_CIT_SETUP(discovery, &target_fabric_discovery_item_ops, NULL, NULL);
  967. /* End of tfc_discovery_cit */
  968. int target_fabric_setup_cits(struct target_fabric_configfs *tf)
  969. {
  970. target_fabric_setup_discovery_cit(tf);
  971. target_fabric_setup_wwn_cit(tf);
  972. target_fabric_setup_wwn_fabric_stats_cit(tf);
  973. target_fabric_setup_tpg_cit(tf);
  974. target_fabric_setup_tpg_base_cit(tf);
  975. target_fabric_setup_tpg_port_cit(tf);
  976. target_fabric_setup_tpg_port_stat_cit(tf);
  977. target_fabric_setup_tpg_lun_cit(tf);
  978. target_fabric_setup_tpg_np_cit(tf);
  979. target_fabric_setup_tpg_np_base_cit(tf);
  980. target_fabric_setup_tpg_attrib_cit(tf);
  981. target_fabric_setup_tpg_param_cit(tf);
  982. target_fabric_setup_tpg_nacl_cit(tf);
  983. target_fabric_setup_tpg_nacl_base_cit(tf);
  984. target_fabric_setup_tpg_nacl_attrib_cit(tf);
  985. target_fabric_setup_tpg_nacl_auth_cit(tf);
  986. target_fabric_setup_tpg_nacl_param_cit(tf);
  987. target_fabric_setup_tpg_nacl_stat_cit(tf);
  988. target_fabric_setup_tpg_mappedlun_cit(tf);
  989. target_fabric_setup_tpg_mappedlun_stat_cit(tf);
  990. return 0;
  991. }