target_core_fabric_configfs.c 35 KB

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