target_core_fabric_configfs.c 34 KB

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