target_core_fabric_configfs.c 35 KB

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