target_core_fabric_configfs.c 34 KB

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