tfc_conf.c 16 KB

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