tfc_conf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. /*******************************************************************************
  2. * Filename: tcm_fc.c
  3. *
  4. * This file contains the configfs implementation for TCM_fc fabric node.
  5. * Based on tcm_loop_configfs.c
  6. *
  7. * Copyright (c) 2010 Cisco Systems, Inc.
  8. * Copyright (c) 2009,2010 Rising Tide, Inc.
  9. * Copyright (c) 2009,2010 Linux-iSCSI.org
  10. *
  11. * Copyright (c) 2009,2010 Nicholas A. Bellinger <nab@linux-iscsi.org>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. ****************************************************************************/
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/version.h>
  26. #include <generated/utsrelease.h>
  27. #include <linux/utsname.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/kthread.h>
  31. #include <linux/types.h>
  32. #include <linux/string.h>
  33. #include <linux/configfs.h>
  34. #include <linux/ctype.h>
  35. #include <asm/unaligned.h>
  36. #include <scsi/scsi.h>
  37. #include <scsi/scsi_host.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_cmnd.h>
  40. #include <scsi/libfc.h>
  41. #include <target/target_core_base.h>
  42. #include <target/target_core_transport.h>
  43. #include <target/target_core_fabric_ops.h>
  44. #include <target/target_core_fabric_configfs.h>
  45. #include <target/target_core_fabric_lib.h>
  46. #include <target/target_core_device.h>
  47. #include <target/target_core_tpg.h>
  48. #include <target/target_core_configfs.h>
  49. #include <target/target_core_base.h>
  50. #include <target/configfs_macros.h>
  51. #include "tcm_fc.h"
  52. struct target_fabric_configfs *ft_configfs;
  53. LIST_HEAD(ft_lport_list);
  54. DEFINE_MUTEX(ft_lport_lock);
  55. unsigned int ft_debug_logging;
  56. module_param_named(debug_logging, ft_debug_logging, int, S_IRUGO|S_IWUSR);
  57. MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
  58. /*
  59. * Parse WWN.
  60. * If strict, we require lower-case hex and colon separators to be sure
  61. * the name is the same as what would be generated by ft_format_wwn()
  62. * so the name and wwn are mapped one-to-one.
  63. */
  64. static ssize_t ft_parse_wwn(const char *name, u64 *wwn, int strict)
  65. {
  66. const char *cp;
  67. char c;
  68. u32 nibble;
  69. u32 byte = 0;
  70. u32 pos = 0;
  71. u32 err;
  72. *wwn = 0;
  73. for (cp = name; cp < &name[FT_NAMELEN - 1]; cp++) {
  74. c = *cp;
  75. if (c == '\n' && cp[1] == '\0')
  76. continue;
  77. if (strict && pos++ == 2 && byte++ < 7) {
  78. pos = 0;
  79. if (c == ':')
  80. continue;
  81. err = 1;
  82. goto fail;
  83. }
  84. if (c == '\0') {
  85. err = 2;
  86. if (strict && byte != 8)
  87. goto fail;
  88. return cp - name;
  89. }
  90. err = 3;
  91. if (isdigit(c))
  92. nibble = c - '0';
  93. else if (isxdigit(c) && (islower(c) || !strict))
  94. nibble = tolower(c) - 'a' + 10;
  95. else
  96. goto fail;
  97. *wwn = (*wwn << 4) | nibble;
  98. }
  99. err = 4;
  100. fail:
  101. FT_CONF_DBG("err %u len %zu pos %u byte %u\n",
  102. err, cp - name, pos, byte);
  103. return -1;
  104. }
  105. ssize_t ft_format_wwn(char *buf, size_t len, u64 wwn)
  106. {
  107. u8 b[8];
  108. put_unaligned_be64(wwn, b);
  109. return snprintf(buf, len,
  110. "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
  111. b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
  112. }
  113. static ssize_t ft_wwn_show(void *arg, char *buf)
  114. {
  115. u64 *wwn = arg;
  116. ssize_t len;
  117. len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn);
  118. buf[len++] = '\n';
  119. return len;
  120. }
  121. static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
  122. {
  123. ssize_t ret;
  124. u64 wwn;
  125. ret = ft_parse_wwn(buf, &wwn, 0);
  126. if (ret > 0)
  127. *(u64 *)arg = wwn;
  128. return ret;
  129. }
  130. /*
  131. * ACL auth ops.
  132. */
  133. static ssize_t ft_nacl_show_port_name(
  134. struct se_node_acl *se_nacl,
  135. char *page)
  136. {
  137. struct ft_node_acl *acl = container_of(se_nacl,
  138. struct ft_node_acl, se_node_acl);
  139. return ft_wwn_show(&acl->node_auth.port_name, page);
  140. }
  141. static ssize_t ft_nacl_store_port_name(
  142. struct se_node_acl *se_nacl,
  143. const char *page,
  144. size_t count)
  145. {
  146. struct ft_node_acl *acl = container_of(se_nacl,
  147. struct ft_node_acl, se_node_acl);
  148. return ft_wwn_store(&acl->node_auth.port_name, page, count);
  149. }
  150. TF_NACL_BASE_ATTR(ft, port_name, S_IRUGO | S_IWUSR);
  151. static ssize_t ft_nacl_show_node_name(
  152. struct se_node_acl *se_nacl,
  153. char *page)
  154. {
  155. struct ft_node_acl *acl = container_of(se_nacl,
  156. struct ft_node_acl, se_node_acl);
  157. return ft_wwn_show(&acl->node_auth.node_name, page);
  158. }
  159. static ssize_t ft_nacl_store_node_name(
  160. struct se_node_acl *se_nacl,
  161. const char *page,
  162. size_t count)
  163. {
  164. struct ft_node_acl *acl = container_of(se_nacl,
  165. struct ft_node_acl, se_node_acl);
  166. return ft_wwn_store(&acl->node_auth.node_name, page, count);
  167. }
  168. TF_NACL_BASE_ATTR(ft, node_name, S_IRUGO | S_IWUSR);
  169. static struct configfs_attribute *ft_nacl_base_attrs[] = {
  170. &ft_nacl_port_name.attr,
  171. &ft_nacl_node_name.attr,
  172. NULL,
  173. };
  174. /*
  175. * ACL ops.
  176. */
  177. /*
  178. * Add ACL for an initiator. The ACL is named arbitrarily.
  179. * The port_name and/or node_name are attributes.
  180. */
  181. static struct se_node_acl *ft_add_acl(
  182. struct se_portal_group *se_tpg,
  183. struct config_group *group,
  184. const char *name)
  185. {
  186. struct ft_node_acl *acl;
  187. struct ft_tpg *tpg;
  188. u64 wwpn;
  189. u32 q_depth;
  190. FT_CONF_DBG("add acl %s\n", name);
  191. tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
  192. if (ft_parse_wwn(name, &wwpn, 1) < 0)
  193. return ERR_PTR(-EINVAL);
  194. acl = kzalloc(sizeof(struct ft_node_acl), GFP_KERNEL);
  195. if (!(acl))
  196. return ERR_PTR(-ENOMEM);
  197. acl->node_auth.port_name = wwpn;
  198. q_depth = 32; /* XXX bogus default - get from tpg? */
  199. return core_tpg_add_initiator_node_acl(&tpg->se_tpg,
  200. &acl->se_node_acl, name, q_depth);
  201. }
  202. static void ft_del_acl(struct se_node_acl *se_acl)
  203. {
  204. struct se_portal_group *se_tpg = se_acl->se_tpg;
  205. struct ft_tpg *tpg;
  206. struct ft_node_acl *acl = container_of(se_acl,
  207. struct ft_node_acl, se_node_acl);
  208. FT_CONF_DBG("del acl %s\n",
  209. config_item_name(&se_acl->acl_group.cg_item));
  210. tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
  211. FT_CONF_DBG("del acl %p se_acl %p tpg %p se_tpg %p\n",
  212. acl, se_acl, tpg, &tpg->se_tpg);
  213. core_tpg_del_initiator_node_acl(&tpg->se_tpg, se_acl, 1);
  214. kfree(acl);
  215. }
  216. struct ft_node_acl *ft_acl_get(struct ft_tpg *tpg, struct fc_rport_priv *rdata)
  217. {
  218. struct ft_node_acl *found = NULL;
  219. struct ft_node_acl *acl;
  220. struct se_portal_group *se_tpg = &tpg->se_tpg;
  221. struct se_node_acl *se_acl;
  222. spin_lock_bh(&se_tpg->acl_node_lock);
  223. list_for_each_entry(se_acl, &se_tpg->acl_node_list, acl_list) {
  224. acl = container_of(se_acl, struct ft_node_acl, se_node_acl);
  225. FT_CONF_DBG("acl %p port_name %llx\n",
  226. acl, (unsigned long long)acl->node_auth.port_name);
  227. if (acl->node_auth.port_name == rdata->ids.port_name ||
  228. acl->node_auth.node_name == rdata->ids.node_name) {
  229. FT_CONF_DBG("acl %p port_name %llx matched\n", acl,
  230. (unsigned long long)rdata->ids.port_name);
  231. found = acl;
  232. /* XXX need to hold onto ACL */
  233. break;
  234. }
  235. }
  236. spin_unlock_bh(&se_tpg->acl_node_lock);
  237. return found;
  238. }
  239. struct se_node_acl *ft_tpg_alloc_fabric_acl(struct se_portal_group *se_tpg)
  240. {
  241. struct ft_node_acl *acl;
  242. acl = kzalloc(sizeof(*acl), GFP_KERNEL);
  243. if (!(acl)) {
  244. printk(KERN_ERR "Unable to allocate struct ft_node_acl\n");
  245. return NULL;
  246. }
  247. FT_CONF_DBG("acl %p\n", acl);
  248. return &acl->se_node_acl;
  249. }
  250. static void ft_tpg_release_fabric_acl(struct se_portal_group *se_tpg,
  251. struct se_node_acl *se_acl)
  252. {
  253. struct ft_node_acl *acl = container_of(se_acl,
  254. struct ft_node_acl, se_node_acl);
  255. FT_CONF_DBG(KERN_INFO "acl %p\n", acl);
  256. kfree(acl);
  257. }
  258. /*
  259. * local_port port_group (tpg) ops.
  260. */
  261. static struct se_portal_group *ft_add_tpg(
  262. struct se_wwn *wwn,
  263. struct config_group *group,
  264. const char *name)
  265. {
  266. struct ft_lport_acl *lacl;
  267. struct ft_tpg *tpg;
  268. unsigned long index;
  269. int ret;
  270. FT_CONF_DBG("tcm_fc: add tpg %s\n", name);
  271. /*
  272. * Name must be "tpgt_" followed by the index.
  273. */
  274. if (strstr(name, "tpgt_") != name)
  275. return NULL;
  276. if (strict_strtoul(name + 5, 10, &index) || index > UINT_MAX)
  277. return NULL;
  278. lacl = container_of(wwn, struct ft_lport_acl, fc_lport_wwn);
  279. tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
  280. if (!tpg)
  281. return NULL;
  282. tpg->index = index;
  283. tpg->lport_acl = lacl;
  284. INIT_LIST_HEAD(&tpg->lun_list);
  285. transport_init_queue_obj(&tpg->qobj);
  286. ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
  287. (void *)tpg, TRANSPORT_TPG_TYPE_NORMAL);
  288. if (ret < 0) {
  289. kfree(tpg);
  290. return NULL;
  291. }
  292. tpg->thread = kthread_run(ft_thread, tpg, "ft_tpg%lu", index);
  293. if (IS_ERR(tpg->thread)) {
  294. kfree(tpg);
  295. return NULL;
  296. }
  297. mutex_lock(&ft_lport_lock);
  298. list_add_tail(&tpg->list, &lacl->tpg_list);
  299. mutex_unlock(&ft_lport_lock);
  300. return &tpg->se_tpg;
  301. }
  302. static void ft_del_tpg(struct se_portal_group *se_tpg)
  303. {
  304. struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
  305. FT_CONF_DBG("del tpg %s\n",
  306. config_item_name(&tpg->se_tpg.tpg_group.cg_item));
  307. kthread_stop(tpg->thread);
  308. /* Wait for sessions to be freed thru RCU, for BUG_ON below */
  309. synchronize_rcu();
  310. mutex_lock(&ft_lport_lock);
  311. list_del(&tpg->list);
  312. if (tpg->tport) {
  313. tpg->tport->tpg = NULL;
  314. tpg->tport = NULL;
  315. }
  316. mutex_unlock(&ft_lport_lock);
  317. core_tpg_deregister(se_tpg);
  318. kfree(tpg);
  319. }
  320. /*
  321. * Verify that an lport is configured to use the tcm_fc module, and return
  322. * the target port group that should be used.
  323. *
  324. * The caller holds ft_lport_lock.
  325. */
  326. struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
  327. {
  328. struct ft_lport_acl *lacl;
  329. struct ft_tpg *tpg;
  330. list_for_each_entry(lacl, &ft_lport_list, list) {
  331. if (lacl->wwpn == lport->wwpn) {
  332. list_for_each_entry(tpg, &lacl->tpg_list, list)
  333. return tpg; /* XXX for now return first entry */
  334. return NULL;
  335. }
  336. }
  337. return NULL;
  338. }
  339. /*
  340. * target config instance ops.
  341. */
  342. /*
  343. * Add lport to allowed config.
  344. * The name is the WWPN in lower-case ASCII, colon-separated bytes.
  345. */
  346. static struct se_wwn *ft_add_lport(
  347. struct target_fabric_configfs *tf,
  348. struct config_group *group,
  349. const char *name)
  350. {
  351. struct ft_lport_acl *lacl;
  352. struct ft_lport_acl *old_lacl;
  353. u64 wwpn;
  354. FT_CONF_DBG("add lport %s\n", name);
  355. if (ft_parse_wwn(name, &wwpn, 1) < 0)
  356. return NULL;
  357. lacl = kzalloc(sizeof(*lacl), GFP_KERNEL);
  358. if (!lacl)
  359. return NULL;
  360. lacl->wwpn = wwpn;
  361. INIT_LIST_HEAD(&lacl->tpg_list);
  362. mutex_lock(&ft_lport_lock);
  363. list_for_each_entry(old_lacl, &ft_lport_list, list) {
  364. if (old_lacl->wwpn == wwpn) {
  365. mutex_unlock(&ft_lport_lock);
  366. kfree(lacl);
  367. return NULL;
  368. }
  369. }
  370. list_add_tail(&lacl->list, &ft_lport_list);
  371. ft_format_wwn(lacl->name, sizeof(lacl->name), wwpn);
  372. mutex_unlock(&ft_lport_lock);
  373. return &lacl->fc_lport_wwn;
  374. }
  375. static void ft_del_lport(struct se_wwn *wwn)
  376. {
  377. struct ft_lport_acl *lacl = container_of(wwn,
  378. struct ft_lport_acl, fc_lport_wwn);
  379. FT_CONF_DBG("del lport %s\n",
  380. config_item_name(&wwn->wwn_group.cg_item));
  381. mutex_lock(&ft_lport_lock);
  382. list_del(&lacl->list);
  383. mutex_unlock(&ft_lport_lock);
  384. kfree(lacl);
  385. }
  386. static ssize_t ft_wwn_show_attr_version(
  387. struct target_fabric_configfs *tf,
  388. char *page)
  389. {
  390. return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on "
  391. ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
  392. }
  393. TF_WWN_ATTR_RO(ft, version);
  394. static struct configfs_attribute *ft_wwn_attrs[] = {
  395. &ft_wwn_version.attr,
  396. NULL,
  397. };
  398. static char *ft_get_fabric_name(void)
  399. {
  400. return "fc";
  401. }
  402. static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg)
  403. {
  404. struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
  405. return tpg->lport_acl->name;
  406. }
  407. static u16 ft_get_tag(struct se_portal_group *se_tpg)
  408. {
  409. struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
  410. /*
  411. * This tag is used when forming SCSI Name identifier in EVPD=1 0x83
  412. * to represent the SCSI Target Port.
  413. */
  414. return tpg->index;
  415. }
  416. static u32 ft_get_default_depth(struct se_portal_group *se_tpg)
  417. {
  418. return 1;
  419. }
  420. static int ft_check_false(struct se_portal_group *se_tpg)
  421. {
  422. return 0;
  423. }
  424. static void ft_set_default_node_attr(struct se_node_acl *se_nacl)
  425. {
  426. }
  427. static u16 ft_get_fabric_sense_len(void)
  428. {
  429. return 0;
  430. }
  431. static u16 ft_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_len)
  432. {
  433. return 0;
  434. }
  435. static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
  436. {
  437. struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
  438. return tpg->index;
  439. }
  440. static u64 ft_pack_lun(unsigned int index)
  441. {
  442. WARN_ON(index >= 256);
  443. /* Caller wants this byte-swapped */
  444. return cpu_to_le64((index & 0xff) << 8);
  445. }
  446. static struct target_core_fabric_ops ft_fabric_ops = {
  447. .get_fabric_name = ft_get_fabric_name,
  448. .get_fabric_proto_ident = fc_get_fabric_proto_ident,
  449. .tpg_get_wwn = ft_get_fabric_wwn,
  450. .tpg_get_tag = ft_get_tag,
  451. .tpg_get_default_depth = ft_get_default_depth,
  452. .tpg_get_pr_transport_id = fc_get_pr_transport_id,
  453. .tpg_get_pr_transport_id_len = fc_get_pr_transport_id_len,
  454. .tpg_parse_pr_out_transport_id = fc_parse_pr_out_transport_id,
  455. .tpg_check_demo_mode = ft_check_false,
  456. .tpg_check_demo_mode_cache = ft_check_false,
  457. .tpg_check_demo_mode_write_protect = ft_check_false,
  458. .tpg_check_prod_mode_write_protect = ft_check_false,
  459. .tpg_alloc_fabric_acl = ft_tpg_alloc_fabric_acl,
  460. .tpg_release_fabric_acl = ft_tpg_release_fabric_acl,
  461. .tpg_get_inst_index = ft_tpg_get_inst_index,
  462. .check_stop_free = ft_check_stop_free,
  463. .release_cmd_to_pool = ft_release_cmd,
  464. .release_cmd_direct = ft_release_cmd,
  465. .shutdown_session = ft_sess_shutdown,
  466. .close_session = ft_sess_close,
  467. .stop_session = ft_sess_stop,
  468. .fall_back_to_erl0 = ft_sess_set_erl0,
  469. .sess_logged_in = ft_sess_logged_in,
  470. .sess_get_index = ft_sess_get_index,
  471. .sess_get_initiator_sid = NULL,
  472. .write_pending = ft_write_pending,
  473. .write_pending_status = ft_write_pending_status,
  474. .set_default_node_attributes = ft_set_default_node_attr,
  475. .get_task_tag = ft_get_task_tag,
  476. .get_cmd_state = ft_get_cmd_state,
  477. .new_cmd_failure = ft_new_cmd_failure,
  478. .queue_data_in = ft_queue_data_in,
  479. .queue_status = ft_queue_status,
  480. .queue_tm_rsp = ft_queue_tm_resp,
  481. .get_fabric_sense_len = ft_get_fabric_sense_len,
  482. .set_fabric_sense_len = ft_set_fabric_sense_len,
  483. .is_state_remove = ft_is_state_remove,
  484. .pack_lun = ft_pack_lun,
  485. /*
  486. * Setup function pointers for generic logic in
  487. * target_core_fabric_configfs.c
  488. */
  489. .fabric_make_wwn = &ft_add_lport,
  490. .fabric_drop_wwn = &ft_del_lport,
  491. .fabric_make_tpg = &ft_add_tpg,
  492. .fabric_drop_tpg = &ft_del_tpg,
  493. .fabric_post_link = NULL,
  494. .fabric_pre_unlink = NULL,
  495. .fabric_make_np = NULL,
  496. .fabric_drop_np = NULL,
  497. .fabric_make_nodeacl = &ft_add_acl,
  498. .fabric_drop_nodeacl = &ft_del_acl,
  499. };
  500. int ft_register_configfs(void)
  501. {
  502. struct target_fabric_configfs *fabric;
  503. int ret;
  504. /*
  505. * Register the top level struct config_item_type with TCM core
  506. */
  507. fabric = target_fabric_configfs_init(THIS_MODULE, "fc");
  508. if (!fabric) {
  509. printk(KERN_INFO "%s: target_fabric_configfs_init() failed!\n",
  510. __func__);
  511. return -1;
  512. }
  513. fabric->tf_ops = ft_fabric_ops;
  514. /* Allowing support for task_sg_chaining */
  515. fabric->tf_ops.task_sg_chaining = 1;
  516. /*
  517. * Setup default attribute lists for various fabric->tf_cit_tmpl
  518. */
  519. TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = ft_wwn_attrs;
  520. TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;
  521. TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;
  522. TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;
  523. TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;
  524. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs =
  525. ft_nacl_base_attrs;
  526. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
  527. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
  528. TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;
  529. /*
  530. * register the fabric for use within TCM
  531. */
  532. ret = target_fabric_configfs_register(fabric);
  533. if (ret < 0) {
  534. FT_CONF_DBG("target_fabric_configfs_register() for"
  535. " FC Target failed!\n");
  536. printk(KERN_INFO
  537. "%s: target_fabric_configfs_register() failed!\n",
  538. __func__);
  539. target_fabric_configfs_free(fabric);
  540. return -1;
  541. }
  542. /*
  543. * Setup our local pointer to *fabric.
  544. */
  545. ft_configfs = fabric;
  546. return 0;
  547. }
  548. void ft_deregister_configfs(void)
  549. {
  550. if (!ft_configfs)
  551. return;
  552. target_fabric_configfs_deregister(ft_configfs);
  553. ft_configfs = NULL;
  554. }
  555. static struct notifier_block ft_notifier = {
  556. .notifier_call = ft_lport_notify
  557. };
  558. static int __init ft_init(void)
  559. {
  560. if (ft_register_configfs())
  561. return -1;
  562. if (fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov)) {
  563. ft_deregister_configfs();
  564. return -1;
  565. }
  566. blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
  567. fc_lport_iterate(ft_lport_add, NULL);
  568. return 0;
  569. }
  570. static void __exit ft_exit(void)
  571. {
  572. blocking_notifier_chain_unregister(&fc_lport_notifier_head,
  573. &ft_notifier);
  574. fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
  575. fc_lport_iterate(ft_lport_del, NULL);
  576. ft_deregister_configfs();
  577. synchronize_rcu();
  578. }
  579. #ifdef MODULE
  580. MODULE_DESCRIPTION("FC TCM fabric driver " FT_VERSION);
  581. MODULE_LICENSE("GPL");
  582. module_init(ft_init);
  583. module_exit(ft_exit);
  584. #endif /* MODULE */