target_core_fabric_configfs.c 34 KB

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