target_core_fabric_configfs.c 34 KB

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