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