24 #include <linux/module.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
29 #include <linux/slab.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
34 #include <linux/kernel.h>
35 #include <linux/ctype.h>
36 #include <asm/unaligned.h>
37 #include <scsi/scsi.h>
66 static ssize_t ft_parse_wwn(
const char *
name,
u64 *wwn,
int strict)
76 for (cp = name; cp < &name[
FT_NAMELEN - 1]; cp++) {
78 if (c ==
'\n' && cp[1] ==
'\0')
80 if (strict && pos++ == 2 && byte++ < 7) {
89 if (strict && byte != 8)
95 if (val < 0 || (strict &&
isupper(c)))
97 *wwn = (*wwn << 4) | val;
101 pr_debug(
"err %u len %zu pos %u byte %u\n",
102 err, cp - name, pos, byte);
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]);
126 static ssize_t ft_wwn_store(
void *
arg,
const char *
buf,
size_t len)
131 ret = ft_parse_wwn(buf, &wwn, 0);
141 static ssize_t ft_nacl_show_port_name(
148 return ft_wwn_show(&acl->
node_auth.port_name, page);
151 static ssize_t ft_nacl_store_port_name(
159 return ft_wwn_store(&acl->
node_auth.port_name, page, count);
164 static ssize_t ft_nacl_show_node_name(
171 return ft_wwn_show(&acl->
node_auth.node_name, page);
174 static ssize_t ft_nacl_store_node_name(
182 return ft_wwn_store(&acl->
node_auth.node_name, page, count);
188 &ft_nacl_port_name.attr,
189 &ft_nacl_node_name.attr,
214 if (ft_parse_wwn(name, &wwpn, 1) < 0)
235 config_item_name(&se_acl->
acl_group.cg_item));
238 pr_debug(
"del acl %p se_acl %p tpg %p se_tpg %p\n",
239 acl, se_acl, tpg, &tpg->
se_tpg);
256 acl, (
unsigned long long)acl->
node_auth.port_name);
259 pr_debug(
"acl %p port_name %llx matched\n", acl,
260 (
unsigned long long)rdata->
ids.port_name);
276 pr_err(
"Unable to allocate struct ft_node_acl\n");
307 pr_debug(
"tcm_fc: add tpg %s\n", name);
312 if (
strstr(name,
"tpgt_") != name)
352 config_item_name(&tpg->
se_tpg.tpg_group.cg_item));
400 static struct se_wwn *ft_add_lport(
410 if (ft_parse_wwn(name, &wwpn, 1) < 0)
420 if (old_lacl->
wwpn == wwpn) {
433 static void ft_del_lport(
struct se_wwn *wwn)
446 static ssize_t ft_wwn_show_attr_version(
451 ""UTS_RELEASE
"\n", utsname()->sysname, utsname()->
machine);
457 &ft_wwn_version.attr,
461 static char *ft_get_fabric_name(
void)
494 static void ft_set_default_node_attr(
struct se_node_acl *se_nacl)
506 .get_fabric_name = ft_get_fabric_name,
508 .tpg_get_wwn = ft_get_fabric_wwn,
509 .tpg_get_tag = ft_get_tag,
510 .tpg_get_default_depth = ft_get_default_depth,
514 .tpg_check_demo_mode = ft_check_false,
515 .tpg_check_demo_mode_cache = ft_check_false,
516 .tpg_check_demo_mode_write_protect = ft_check_false,
517 .tpg_check_prod_mode_write_protect = ft_check_false,
519 .tpg_release_fabric_acl = ft_tpg_release_fabric_acl,
520 .tpg_get_inst_index = ft_tpg_get_inst_index,
526 .sess_get_initiator_sid =
NULL,
529 .set_default_node_attributes = ft_set_default_node_attr,
539 .fabric_make_wwn = &ft_add_lport,
540 .fabric_drop_wwn = &ft_del_lport,
541 .fabric_make_tpg = &ft_add_tpg,
542 .fabric_drop_tpg = &ft_del_tpg,
543 .fabric_post_link =
NULL,
544 .fabric_pre_unlink =
NULL,
545 .fabric_make_np =
NULL,
546 .fabric_drop_np =
NULL,
547 .fabric_make_nodeacl = &ft_add_acl,
548 .fabric_drop_nodeacl = &ft_del_acl,
560 if (IS_ERR(fabric)) {
561 pr_err(
"%s: target_fabric_configfs_init() failed!\n",
563 return PTR_ERR(fabric);
565 fabric->
tf_ops = ft_fabric_ops;
570 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = ft_wwn_attrs;
575 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs =
585 pr_debug(
"target_fabric_configfs_register() for"
586 " FC Target failed!\n");
594 ft_configfs = fabric;
610 static int __init ft_init(
void)
623 static void __exit ft_exit(
void)