target_core_fabric_configfs.c 35 KB

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