blob: 4bdf7a25ae67886e9c6e7acbd86ad170fcd0f3d7 [file] [log] [blame]
Kiran Patil3699d922011-04-18 16:24:14 -07001/*******************************************************************************
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
24#include <linux/module.h>
25#include <linux/moduleparam.h>
Kiran Patil3699d922011-04-18 16:24:14 -070026#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>
Andy Shevchenko635a2b32011-09-30 14:45:40 +030034#include <linux/kernel.h>
Kiran Patil3699d922011-04-18 16:24:14 -070035#include <linux/ctype.h>
36#include <asm/unaligned.h>
37#include <scsi/scsi.h>
38#include <scsi/scsi_host.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/libfc.h>
42
43#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050044#include <target/target_core_fabric.h>
Kiran Patil3699d922011-04-18 16:24:14 -070045#include <target/target_core_fabric_configfs.h>
Kiran Patil3699d922011-04-18 16:24:14 -070046#include <target/target_core_configfs.h>
Kiran Patil3699d922011-04-18 16:24:14 -070047#include <target/configfs_macros.h>
48
49#include "tcm_fc.h"
50
Christoph Hellwig9ac89282015-04-08 20:01:35 +020051static const struct target_core_fabric_ops ft_fabric_ops;
Kiran Patil3699d922011-04-18 16:24:14 -070052
Andy Grover705665d2014-04-04 16:54:13 -070053static LIST_HEAD(ft_wwn_list);
Kiran Patil3699d922011-04-18 16:24:14 -070054DEFINE_MUTEX(ft_lport_lock);
55
56unsigned int ft_debug_logging;
57module_param_named(debug_logging, ft_debug_logging, int, S_IRUGO|S_IWUSR);
58MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
59
60/*
61 * Parse WWN.
62 * If strict, we require lower-case hex and colon separators to be sure
63 * the name is the same as what would be generated by ft_format_wwn()
64 * so the name and wwn are mapped one-to-one.
65 */
66static ssize_t ft_parse_wwn(const char *name, u64 *wwn, int strict)
67{
68 const char *cp;
69 char c;
Kiran Patil3699d922011-04-18 16:24:14 -070070 u32 byte = 0;
71 u32 pos = 0;
72 u32 err;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030073 int val;
Kiran Patil3699d922011-04-18 16:24:14 -070074
75 *wwn = 0;
76 for (cp = name; cp < &name[FT_NAMELEN - 1]; cp++) {
77 c = *cp;
78 if (c == '\n' && cp[1] == '\0')
79 continue;
80 if (strict && pos++ == 2 && byte++ < 7) {
81 pos = 0;
82 if (c == ':')
83 continue;
84 err = 1;
85 goto fail;
86 }
87 if (c == '\0') {
88 err = 2;
89 if (strict && byte != 8)
90 goto fail;
91 return cp - name;
92 }
93 err = 3;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030094 val = hex_to_bin(c);
95 if (val < 0 || (strict && isupper(c)))
Kiran Patil3699d922011-04-18 16:24:14 -070096 goto fail;
Andy Shevchenko635a2b32011-09-30 14:45:40 +030097 *wwn = (*wwn << 4) | val;
Kiran Patil3699d922011-04-18 16:24:14 -070098 }
99 err = 4;
100fail:
Andy Grover6708bb22011-06-08 10:36:43 -0700101 pr_debug("err %u len %zu pos %u byte %u\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700102 err, cp - name, pos, byte);
103 return -1;
104}
105
106ssize_t ft_format_wwn(char *buf, size_t len, u64 wwn)
107{
108 u8 b[8];
109
110 put_unaligned_be64(wwn, b);
111 return snprintf(buf, len,
112 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
113 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
114}
115
116static ssize_t ft_wwn_show(void *arg, char *buf)
117{
118 u64 *wwn = arg;
119 ssize_t len;
120
121 len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn);
122 buf[len++] = '\n';
123 return len;
124}
125
126static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
127{
128 ssize_t ret;
129 u64 wwn;
130
131 ret = ft_parse_wwn(buf, &wwn, 0);
132 if (ret > 0)
133 *(u64 *)arg = wwn;
134 return ret;
135}
136
137/*
138 * ACL auth ops.
139 */
140
141static ssize_t ft_nacl_show_port_name(
142 struct se_node_acl *se_nacl,
143 char *page)
144{
145 struct ft_node_acl *acl = container_of(se_nacl,
146 struct ft_node_acl, se_node_acl);
147
148 return ft_wwn_show(&acl->node_auth.port_name, page);
149}
150
151static ssize_t ft_nacl_store_port_name(
152 struct se_node_acl *se_nacl,
153 const char *page,
154 size_t count)
155{
156 struct ft_node_acl *acl = container_of(se_nacl,
157 struct ft_node_acl, se_node_acl);
158
159 return ft_wwn_store(&acl->node_auth.port_name, page, count);
160}
161
162TF_NACL_BASE_ATTR(ft, port_name, S_IRUGO | S_IWUSR);
163
164static ssize_t ft_nacl_show_node_name(
165 struct se_node_acl *se_nacl,
166 char *page)
167{
168 struct ft_node_acl *acl = container_of(se_nacl,
169 struct ft_node_acl, se_node_acl);
170
171 return ft_wwn_show(&acl->node_auth.node_name, page);
172}
173
174static ssize_t ft_nacl_store_node_name(
175 struct se_node_acl *se_nacl,
176 const char *page,
177 size_t count)
178{
179 struct ft_node_acl *acl = container_of(se_nacl,
180 struct ft_node_acl, se_node_acl);
181
182 return ft_wwn_store(&acl->node_auth.node_name, page, count);
183}
184
185TF_NACL_BASE_ATTR(ft, node_name, S_IRUGO | S_IWUSR);
186
187static struct configfs_attribute *ft_nacl_base_attrs[] = {
188 &ft_nacl_port_name.attr,
189 &ft_nacl_node_name.attr,
190 NULL,
191};
192
193/*
194 * ACL ops.
195 */
196
197/*
198 * Add ACL for an initiator. The ACL is named arbitrarily.
199 * The port_name and/or node_name are attributes.
200 */
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200201static int ft_init_nodeacl(struct se_node_acl *nacl, const char *name)
Kiran Patil3699d922011-04-18 16:24:14 -0700202{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200203 struct ft_node_acl *acl =
204 container_of(nacl, struct ft_node_acl, se_node_acl);
Kiran Patil3699d922011-04-18 16:24:14 -0700205 u64 wwpn;
Kiran Patil3699d922011-04-18 16:24:14 -0700206
207 if (ft_parse_wwn(name, &wwpn, 1) < 0)
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200208 return -EINVAL;
Kiran Patil3699d922011-04-18 16:24:14 -0700209
Kiran Patil3699d922011-04-18 16:24:14 -0700210 acl->node_auth.port_name = wwpn;
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200211 return 0;
Kiran Patil3699d922011-04-18 16:24:14 -0700212}
213
214struct 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
Roland Dreier28638882011-08-16 09:40:01 -0700221 spin_lock_irq(&se_tpg->acl_node_lock);
Kiran Patil3699d922011-04-18 16:24:14 -0700222 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);
Andy Grover6708bb22011-06-08 10:36:43 -0700224 pr_debug("acl %p port_name %llx\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700225 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) {
Andy Grover6708bb22011-06-08 10:36:43 -0700228 pr_debug("acl %p port_name %llx matched\n", acl,
Kiran Patil3699d922011-04-18 16:24:14 -0700229 (unsigned long long)rdata->ids.port_name);
230 found = acl;
231 /* XXX need to hold onto ACL */
232 break;
233 }
234 }
Roland Dreier28638882011-08-16 09:40:01 -0700235 spin_unlock_irq(&se_tpg->acl_node_lock);
Kiran Patil3699d922011-04-18 16:24:14 -0700236 return found;
237}
238
Kiran Patil3699d922011-04-18 16:24:14 -0700239/*
240 * local_port port_group (tpg) ops.
241 */
242static struct se_portal_group *ft_add_tpg(
243 struct se_wwn *wwn,
244 struct config_group *group,
245 const char *name)
246{
Andy Grover705665d2014-04-04 16:54:13 -0700247 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700248 struct ft_tpg *tpg;
Mark Rustad06383f12012-04-03 10:24:52 -0700249 struct workqueue_struct *wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700250 unsigned long index;
251 int ret;
252
Andy Grover6708bb22011-06-08 10:36:43 -0700253 pr_debug("tcm_fc: add tpg %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700254
255 /*
256 * Name must be "tpgt_" followed by the index.
257 */
258 if (strstr(name, "tpgt_") != name)
259 return NULL;
Jingoo Han57103d72013-07-19 16:22:19 +0900260
261 ret = kstrtoul(name + 5, 10, &index);
262 if (ret)
263 return NULL;
264 if (index > UINT_MAX)
Kiran Patil3699d922011-04-18 16:24:14 -0700265 return NULL;
266
Andy Groverd242c1d2014-04-04 16:54:12 -0700267 if ((index != 1)) {
268 pr_err("Error, a single TPG=1 is used for HW port mappings\n");
269 return ERR_PTR(-ENOSYS);
270 }
271
Andy Grover705665d2014-04-04 16:54:13 -0700272 ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700273 tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
274 if (!tpg)
275 return NULL;
276 tpg->index = index;
Andy Grover705665d2014-04-04 16:54:13 -0700277 tpg->lport_wwn = ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700278 INIT_LIST_HEAD(&tpg->lun_list);
Kiran Patil3699d922011-04-18 16:24:14 -0700279
Mark Rustad06383f12012-04-03 10:24:52 -0700280 wq = alloc_workqueue("tcm_fc", 0, 1);
281 if (!wq) {
Kiran Patil3699d922011-04-18 16:24:14 -0700282 kfree(tpg);
283 return NULL;
284 }
285
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200286 ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg,
Mark Rustad06383f12012-04-03 10:24:52 -0700287 tpg, TRANSPORT_TPG_TYPE_NORMAL);
288 if (ret < 0) {
289 destroy_workqueue(wq);
Kiran Patil3699d922011-04-18 16:24:14 -0700290 kfree(tpg);
291 return NULL;
292 }
Mark Rustad06383f12012-04-03 10:24:52 -0700293 tpg->workqueue = wq;
Kiran Patil3699d922011-04-18 16:24:14 -0700294
295 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700296 ft_wwn->tpg = tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700297 mutex_unlock(&ft_lport_lock);
298
299 return &tpg->se_tpg;
300}
301
302static 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);
Andy Grover705665d2014-04-04 16:54:13 -0700305 struct ft_lport_wwn *ft_wwn = tpg->lport_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700306
Andy Grover6708bb22011-06-08 10:36:43 -0700307 pr_debug("del tpg %s\n",
Kiran Patil3699d922011-04-18 16:24:14 -0700308 config_item_name(&tpg->se_tpg.tpg_group.cg_item));
309
Christoph Hellwig58fc73d2011-08-26 09:25:38 -0700310 destroy_workqueue(tpg->workqueue);
Kiran Patil3699d922011-04-18 16:24:14 -0700311
312 /* Wait for sessions to be freed thru RCU, for BUG_ON below */
313 synchronize_rcu();
314
315 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700316 ft_wwn->tpg = NULL;
Kiran Patil3699d922011-04-18 16:24:14 -0700317 if (tpg->tport) {
318 tpg->tport->tpg = NULL;
319 tpg->tport = NULL;
320 }
321 mutex_unlock(&ft_lport_lock);
322
323 core_tpg_deregister(se_tpg);
324 kfree(tpg);
325}
326
327/*
328 * Verify that an lport is configured to use the tcm_fc module, and return
329 * the target port group that should be used.
330 *
331 * The caller holds ft_lport_lock.
332 */
333struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
334{
Andy Grover705665d2014-04-04 16:54:13 -0700335 struct ft_lport_wwn *ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700336
Andy Grover705665d2014-04-04 16:54:13 -0700337 list_for_each_entry(ft_wwn, &ft_wwn_list, ft_wwn_node) {
338 if (ft_wwn->wwpn == lport->wwpn)
339 return ft_wwn->tpg;
Kiran Patil3699d922011-04-18 16:24:14 -0700340 }
341 return NULL;
342}
343
344/*
345 * target config instance ops.
346 */
347
348/*
349 * Add lport to allowed config.
350 * The name is the WWPN in lower-case ASCII, colon-separated bytes.
351 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700352static struct se_wwn *ft_add_wwn(
Kiran Patil3699d922011-04-18 16:24:14 -0700353 struct target_fabric_configfs *tf,
354 struct config_group *group,
355 const char *name)
356{
Andy Grover705665d2014-04-04 16:54:13 -0700357 struct ft_lport_wwn *ft_wwn;
358 struct ft_lport_wwn *old_ft_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700359 u64 wwpn;
360
Andy Grover0d7cb932014-04-04 16:54:14 -0700361 pr_debug("add wwn %s\n", name);
Kiran Patil3699d922011-04-18 16:24:14 -0700362 if (ft_parse_wwn(name, &wwpn, 1) < 0)
363 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700364 ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL);
365 if (!ft_wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700366 return NULL;
Andy Grover705665d2014-04-04 16:54:13 -0700367 ft_wwn->wwpn = wwpn;
Kiran Patil3699d922011-04-18 16:24:14 -0700368
369 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700370 list_for_each_entry(old_ft_wwn, &ft_wwn_list, ft_wwn_node) {
371 if (old_ft_wwn->wwpn == wwpn) {
Kiran Patil3699d922011-04-18 16:24:14 -0700372 mutex_unlock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700373 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700374 return NULL;
375 }
376 }
Andy Grover705665d2014-04-04 16:54:13 -0700377 list_add_tail(&ft_wwn->ft_wwn_node, &ft_wwn_list);
378 ft_format_wwn(ft_wwn->name, sizeof(ft_wwn->name), wwpn);
Kiran Patil3699d922011-04-18 16:24:14 -0700379 mutex_unlock(&ft_lport_lock);
380
Andy Grover705665d2014-04-04 16:54:13 -0700381 return &ft_wwn->se_wwn;
Kiran Patil3699d922011-04-18 16:24:14 -0700382}
383
Andy Grover0d7cb932014-04-04 16:54:14 -0700384static void ft_del_wwn(struct se_wwn *wwn)
Kiran Patil3699d922011-04-18 16:24:14 -0700385{
Andy Grover705665d2014-04-04 16:54:13 -0700386 struct ft_lport_wwn *ft_wwn = container_of(wwn,
387 struct ft_lport_wwn, se_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700388
Andy Grover0d7cb932014-04-04 16:54:14 -0700389 pr_debug("del wwn %s\n", ft_wwn->name);
Kiran Patil3699d922011-04-18 16:24:14 -0700390 mutex_lock(&ft_lport_lock);
Andy Grover705665d2014-04-04 16:54:13 -0700391 list_del(&ft_wwn->ft_wwn_node);
Kiran Patil3699d922011-04-18 16:24:14 -0700392 mutex_unlock(&ft_lport_lock);
393
Andy Grover705665d2014-04-04 16:54:13 -0700394 kfree(ft_wwn);
Kiran Patil3699d922011-04-18 16:24:14 -0700395}
396
397static ssize_t ft_wwn_show_attr_version(
398 struct target_fabric_configfs *tf,
399 char *page)
400{
401 return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on "
402 ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
403}
404
405TF_WWN_ATTR_RO(ft, version);
406
407static struct configfs_attribute *ft_wwn_attrs[] = {
408 &ft_wwn_version.attr,
409 NULL,
410};
411
Christoph Hellwig3868e432015-05-01 17:47:55 +0200412static inline struct ft_tpg *ft_tpg(struct se_portal_group *se_tpg)
413{
414 return container_of(se_tpg, struct ft_tpg, se_tpg);
415}
416
Kiran Patil3699d922011-04-18 16:24:14 -0700417static char *ft_get_fabric_name(void)
418{
419 return "fc";
420}
421
422static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg)
423{
Christoph Hellwig3868e432015-05-01 17:47:55 +0200424 return ft_tpg(se_tpg)->lport_wwn->name;
Kiran Patil3699d922011-04-18 16:24:14 -0700425}
426
427static u16 ft_get_tag(struct se_portal_group *se_tpg)
428{
Kiran Patil3699d922011-04-18 16:24:14 -0700429 /*
430 * This tag is used when forming SCSI Name identifier in EVPD=1 0x83
431 * to represent the SCSI Target Port.
432 */
Christoph Hellwig3868e432015-05-01 17:47:55 +0200433 return ft_tpg(se_tpg)->index;
Kiran Patil3699d922011-04-18 16:24:14 -0700434}
435
Kiran Patil3699d922011-04-18 16:24:14 -0700436static int ft_check_false(struct se_portal_group *se_tpg)
437{
438 return 0;
439}
440
441static void ft_set_default_node_attr(struct se_node_acl *se_nacl)
442{
443}
444
Kiran Patil3699d922011-04-18 16:24:14 -0700445static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
446{
Christoph Hellwig3868e432015-05-01 17:47:55 +0200447 return ft_tpg(se_tpg)->index;
Kiran Patil3699d922011-04-18 16:24:14 -0700448}
449
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200450static const struct target_core_fabric_ops ft_fabric_ops = {
451 .module = THIS_MODULE,
452 .name = "fc",
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200453 .node_acl_size = sizeof(struct ft_node_acl),
Kiran Patil3699d922011-04-18 16:24:14 -0700454 .get_fabric_name = ft_get_fabric_name,
455 .get_fabric_proto_ident = fc_get_fabric_proto_ident,
456 .tpg_get_wwn = ft_get_fabric_wwn,
457 .tpg_get_tag = ft_get_tag,
Kiran Patil3699d922011-04-18 16:24:14 -0700458 .tpg_get_pr_transport_id = fc_get_pr_transport_id,
459 .tpg_get_pr_transport_id_len = fc_get_pr_transport_id_len,
460 .tpg_parse_pr_out_transport_id = fc_parse_pr_out_transport_id,
461 .tpg_check_demo_mode = ft_check_false,
462 .tpg_check_demo_mode_cache = ft_check_false,
463 .tpg_check_demo_mode_write_protect = ft_check_false,
464 .tpg_check_prod_mode_write_protect = ft_check_false,
Kiran Patil3699d922011-04-18 16:24:14 -0700465 .tpg_get_inst_index = ft_tpg_get_inst_index,
466 .check_stop_free = ft_check_stop_free,
Christoph Hellwig35462972011-05-31 23:56:57 -0400467 .release_cmd = ft_release_cmd,
Kiran Patil3699d922011-04-18 16:24:14 -0700468 .shutdown_session = ft_sess_shutdown,
469 .close_session = ft_sess_close,
Kiran Patil3699d922011-04-18 16:24:14 -0700470 .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,
Kiran Patil3699d922011-04-18 16:24:14 -0700477 .queue_data_in = ft_queue_data_in,
478 .queue_status = ft_queue_status,
479 .queue_tm_rsp = ft_queue_tm_resp,
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -0700480 .aborted_task = ft_aborted_task,
Kiran Patil3699d922011-04-18 16:24:14 -0700481 /*
482 * Setup function pointers for generic logic in
483 * target_core_fabric_configfs.c
484 */
Andy Grover0d7cb932014-04-04 16:54:14 -0700485 .fabric_make_wwn = &ft_add_wwn,
486 .fabric_drop_wwn = &ft_del_wwn,
Kiran Patil3699d922011-04-18 16:24:14 -0700487 .fabric_make_tpg = &ft_add_tpg,
488 .fabric_drop_tpg = &ft_del_tpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200489 .fabric_init_nodeacl = &ft_init_nodeacl,
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200490
491 .tfc_wwn_attrs = ft_wwn_attrs,
492 .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs,
Kiran Patil3699d922011-04-18 16:24:14 -0700493};
494
Kiran Patil3699d922011-04-18 16:24:14 -0700495static struct notifier_block ft_notifier = {
496 .notifier_call = ft_lport_notify
497};
498
499static int __init ft_init(void)
500{
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200501 int ret;
502
503 ret = target_register_template(&ft_fabric_ops);
504 if (ret)
505 goto out;
506
507 ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov);
508 if (ret)
509 goto out_unregister_template;
510
Kiran Patil3699d922011-04-18 16:24:14 -0700511 blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
512 fc_lport_iterate(ft_lport_add, NULL);
513 return 0;
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200514
515out_unregister_template:
516 target_unregister_template(&ft_fabric_ops);
517out:
518 return ret;
Kiran Patil3699d922011-04-18 16:24:14 -0700519}
520
521static void __exit ft_exit(void)
522{
523 blocking_notifier_chain_unregister(&fc_lport_notifier_head,
524 &ft_notifier);
525 fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
526 fc_lport_iterate(ft_lport_del, NULL);
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200527 target_unregister_template(&ft_fabric_ops);
Kiran Patil3699d922011-04-18 16:24:14 -0700528 synchronize_rcu();
529}
530
Kiran Patil3699d922011-04-18 16:24:14 -0700531MODULE_DESCRIPTION("FC TCM fabric driver " FT_VERSION);
532MODULE_LICENSE("GPL");
533module_init(ft_init);
534module_exit(ft_exit);