tfc_conf.c 16 KB

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