target_core_fabric_configfs.c 34 KB

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