cregit-Linux how code gets into the kernel

Release 4.7 drivers/target/tcm_fc/tfc_conf.c

/*******************************************************************************
 * Filename:  tcm_fc.c
 *
 * This file contains the configfs implementation for TCM_fc fabric node.
 * Based on tcm_loop_configfs.c
 *
 * Copyright (c) 2010 Cisco Systems, Inc.
 * Copyright (c) 2009,2010 Rising Tide, Inc.
 * Copyright (c) 2009,2010 Linux-iSCSI.org
 *
 * Copyright (c) 2009,2010 Nicholas A. Bellinger <nab@linux-iscsi.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 ****************************************************************************/

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <generated/utsrelease.h>
#include <linux/utsname.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/configfs.h>
#include <linux/kernel.h>
#include <linux/ctype.h>
#include <asm/unaligned.h>
#include <scsi/libfc.h>

#include <target/target_core_base.h>
#include <target/target_core_fabric.h>

#include "tcm_fc.h"

static LIST_HEAD(ft_wwn_list);

DEFINE_MUTEX(ft_lport_lock);


unsigned int ft_debug_logging;
module_param_named(debug_logging, ft_debug_logging, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");

/*
 * Parse WWN.
 * If strict, we require lower-case hex and colon separators to be sure
 * the name is the same as what would be generated by ft_format_wwn()
 * so the name and wwn are mapped one-to-one.
 */

static ssize_t ft_parse_wwn(const char *name, u64 *wwn, int strict) { const char *cp; char c; u32 byte = 0; u32 pos = 0; u32 err; int val; *wwn = 0; for (cp = name; cp < &name[FT_NAMELEN - 1]; cp++) { c = *cp; if (c == '\n' && cp[1] == '\0') continue; if (strict && pos++ == 2 && byte++ < 7) { pos = 0; if (c == ':') continue; err = 1; goto fail; } if (c == '\0') { err = 2; if (strict && byte != 8) goto fail; return cp - name; } err = 3; val = hex_to_bin(c); if (val < 0 || (strict && isupper(c))) goto fail; *wwn = (*wwn << 4) | val; } err = 4; fail: pr_debug("err %u len %zu pos %u byte %u\n", err, cp - name, pos, byte); return -1; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil20093.02%133.33%
andy shevchenkoandy shevchenko146.51%133.33%
andy groverandy grover10.47%133.33%
Total215100.00%3100.00%


ssize_t ft_format_wwn(char *buf, size_t len, u64 wwn) { u8 b[8]; put_unaligned_be64(wwn, b); return snprintf(buf, len, "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil78100.00%1100.00%
Total78100.00%1100.00%


static ssize_t ft_wwn_show(void *arg, char *buf) { u64 *wwn = arg; ssize_t len; len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn); buf[len++] = '\n'; return len; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil48100.00%1100.00%
Total48100.00%1100.00%


static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len) { ssize_t ret; u64 wwn; ret = ft_parse_wwn(buf, &wwn, 0); if (ret > 0) *(u64 *)arg = wwn; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil54100.00%1100.00%
Total54100.00%1100.00%

/* * ACL auth ops. */
static ssize_t ft_nacl_port_name_show(struct config_item *item, char *page) { struct se_node_acl *se_nacl = acl_to_nacl(item); struct ft_node_acl *acl = container_of(se_nacl, struct ft_node_acl, se_node_acl); return ft_wwn_show(&acl->node_auth.port_name, page); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil4075.47%150.00%
christoph hellwigchristoph hellwig1324.53%150.00%
Total53100.00%2100.00%


static ssize_t ft_nacl_port_name_store(struct config_item *item, const char *page, size_t count) { struct se_node_acl *se_nacl = acl_to_nacl(item); struct ft_node_acl *acl = container_of(se_nacl, struct ft_node_acl, se_node_acl); return ft_wwn_store(&acl->node_auth.port_name, page, count); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil4677.97%150.00%
christoph hellwigchristoph hellwig1322.03%150.00%
Total59100.00%2100.00%


static ssize_t ft_nacl_node_name_show(struct config_item *item, char *page) { struct se_node_acl *se_nacl = acl_to_nacl(item); struct ft_node_acl *acl = container_of(se_nacl, struct ft_node_acl, se_node_acl); return ft_wwn_show(&acl->node_auth.node_name, page); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil4075.47%150.00%
christoph hellwigchristoph hellwig1324.53%150.00%
Total53100.00%2100.00%


static ssize_t ft_nacl_node_name_store(struct config_item *item, const char *page, size_t count) { struct se_node_acl *se_nacl = acl_to_nacl(item); struct ft_node_acl *acl = container_of(se_nacl, struct ft_node_acl, se_node_acl); return ft_wwn_store(&acl->node_auth.node_name, page, count); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil4677.97%150.00%
christoph hellwigchristoph hellwig1322.03%150.00%
Total59100.00%2100.00%

CONFIGFS_ATTR(ft_nacl_, node_name); CONFIGFS_ATTR(ft_nacl_, port_name);
static ssize_t ft_nacl_tag_show(struct config_item *item, char *page) { return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); }

Contributors

PersonTokensPropCommitsCommitProp
andy groverandy grover32100.00%1100.00%
Total32100.00%1100.00%


static ssize_t ft_nacl_tag_store(struct config_item *item, const char *page, size_t count) { struct se_node_acl *se_nacl = acl_to_nacl(item); int ret; ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); if (ret < 0) return ret; return count; }

Contributors

PersonTokensPropCommitsCommitProp
andy groverandy grover57100.00%1100.00%
Total57100.00%1100.00%

CONFIGFS_ATTR(ft_nacl_, tag); static struct configfs_attribute *ft_nacl_base_attrs[] = { &ft_nacl_attr_port_name, &ft_nacl_attr_node_name, &ft_nacl_attr_tag, NULL, }; /* * ACL ops. */ /* * Add ACL for an initiator. The ACL is named arbitrarily. * The port_name and/or node_name are attributes. */
static int ft_init_nodeacl(struct se_node_acl *nacl, const char *name) { struct ft_node_acl *acl = container_of(nacl, struct ft_node_acl, se_node_acl); u64 wwpn; if (ft_parse_wwn(name, &wwpn, 1) < 0) return -EINVAL; acl->node_auth.port_name = wwpn; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil5079.37%150.00%
christoph hellwigchristoph hellwig1320.63%150.00%
Total63100.00%2100.00%

/* * local_port port_group (tpg) ops. */
static struct se_portal_group *ft_add_tpg( struct se_wwn *wwn, struct config_group *group, const char *name) { struct ft_lport_wwn *ft_wwn; struct ft_tpg *tpg; struct workqueue_struct *wq; unsigned long index; int ret; pr_debug("tcm_fc: add tpg %s\n", name); /* * Name must be "tpgt_" followed by the index. */ if (strstr(name, "tpgt_") != name) return NULL; ret = kstrtoul(name + 5, 10, &index); if (ret) return NULL; if (index > UINT_MAX) return NULL; if ((index != 1)) { pr_err("Error, a single TPG=1 is used for HW port mappings\n"); return ERR_PTR(-ENOSYS); } ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn); tpg = kzalloc(sizeof(*tpg), GFP_KERNEL); if (!tpg) return NULL; tpg->index = index; tpg->lport_wwn = ft_wwn; INIT_LIST_HEAD(&tpg->lun_list); wq = alloc_workqueue("tcm_fc", 0, 1); if (!wq) { kfree(tpg); return NULL; } ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP); if (ret < 0) { destroy_workqueue(wq); kfree(tpg); return NULL; } tpg->workqueue = wq; mutex_lock(&ft_lport_lock); ft_wwn->tpg = tpg; mutex_unlock(&ft_lport_lock); return &tpg->se_tpg; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil17767.30%112.50%
mark d. rustadmark d. rustad3714.07%112.50%
andy groverandy grover3412.93%337.50%
jingoo hanjingoo han134.94%112.50%
christoph hellwigchristoph hellwig20.76%225.00%
Total263100.00%8100.00%


static void ft_del_tpg(struct se_portal_group *se_tpg) { struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg); struct ft_lport_wwn *ft_wwn = tpg->lport_wwn; pr_debug("del tpg %s\n", config_item_name(&tpg->se_tpg.tpg_group.cg_item)); destroy_workqueue(tpg->workqueue); /* Wait for sessions to be freed thru RCU, for BUG_ON below */ synchronize_rcu(); mutex_lock(&ft_lport_lock); ft_wwn->tpg = NULL; if (tpg->tport) { tpg->tport->tpg = NULL; tpg->tport = NULL; } mutex_unlock(&ft_lport_lock); core_tpg_deregister(se_tpg); kfree(tpg); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil9785.84%120.00%
andy groverandy grover1412.39%360.00%
christoph hellwigchristoph hellwig21.77%120.00%
Total113100.00%5100.00%

/* * Verify that an lport is configured to use the tcm_fc module, and return * the target port group that should be used. * * The caller holds ft_lport_lock. */
struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport) { struct ft_lport_wwn *ft_wwn; list_for_each_entry(ft_wwn, &ft_wwn_list, ft_wwn_node) { if (ft_wwn->wwpn == lport->wwpn) return ft_wwn->tpg; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil3782.22%133.33%
andy groverandy grover817.78%266.67%
Total45100.00%3100.00%

/* * target config instance ops. */ /* * Add lport to allowed config. * The name is the WWPN in lower-case ASCII, colon-separated bytes. */
static struct se_wwn *ft_add_wwn( struct target_fabric_configfs *tf, struct config_group *group, const char *name) { struct ft_lport_wwn *ft_wwn; struct ft_lport_wwn *old_ft_wwn; u64 wwpn; pr_debug("add wwn %s\n", name); if (ft_parse_wwn(name, &wwpn, 1) < 0) return NULL; ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL); if (!ft_wwn) return NULL; ft_wwn->wwpn = wwpn; mutex_lock(&ft_lport_lock); list_for_each_entry(old_ft_wwn, &ft_wwn_list, ft_wwn_node) { if (old_ft_wwn->wwpn == wwpn) { mutex_unlock(&ft_lport_lock); kfree(ft_wwn); return NULL; } } list_add_tail(&ft_wwn->ft_wwn_node, &ft_wwn_list); ft_format_wwn(ft_wwn->name, sizeof(ft_wwn->name), wwpn); mutex_unlock(&ft_lport_lock); return &ft_wwn->se_wwn; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil14386.14%125.00%
andy groverandy grover2313.86%375.00%
Total166100.00%4100.00%


static void ft_del_wwn(struct se_wwn *wwn) { struct ft_lport_wwn *ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn); pr_debug("del wwn %s\n", ft_wwn->name); mutex_lock(&ft_lport_lock); list_del(&ft_wwn->ft_wwn_node); mutex_unlock(&ft_lport_lock); kfree(ft_wwn); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil4880.00%120.00%
andy groverandy grover1118.33%360.00%
nicholas bellingernicholas bellinger11.67%120.00%
Total60100.00%5100.00%


static ssize_t ft_wwn_version_show(struct config_item *item, char *page) { return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on " ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil3592.11%150.00%
christoph hellwigchristoph hellwig37.89%150.00%
Total38100.00%2100.00%

CONFIGFS_ATTR_RO(ft_wwn_, version); static struct configfs_attribute *ft_wwn_attrs[] = { &ft_wwn_attr_version, NULL, };
static inline struct ft_tpg *ft_tpg(struct se_portal_group *se_tpg) { return container_of(se_tpg, struct ft_tpg, se_tpg); }

Contributors

PersonTokensPropCommitsCommitProp
christoph hellwigchristoph hellwig25100.00%1100.00%
Total25100.00%1100.00%


static char *ft_get_fabric_name(void) { return "fc"; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil12100.00%1100.00%
Total12100.00%1100.00%


static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg) { return ft_tpg(se_tpg)->lport_wwn->name; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil1881.82%133.33%
christoph hellwigchristoph hellwig313.64%133.33%
andy groverandy grover14.55%133.33%
Total22100.00%3100.00%


static u16 ft_get_tag(struct se_portal_group *se_tpg) { /* * This tag is used when forming SCSI Name identifier in EVPD=1 0x83 * to represent the SCSI Target Port. */ return ft_tpg(se_tpg)->index; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil1680.00%150.00%
christoph hellwigchristoph hellwig420.00%150.00%
Total20100.00%2100.00%


static int ft_check_false(struct se_portal_group *se_tpg) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil14100.00%1100.00%
Total14100.00%1100.00%


static void ft_set_default_node_attr(struct se_node_acl *se_nacl) { }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil10100.00%1100.00%
Total10100.00%1100.00%


static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg) { return ft_tpg(se_tpg)->index; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil1684.21%150.00%
christoph hellwigchristoph hellwig315.79%150.00%
Total19100.00%2100.00%

static const struct target_core_fabric_ops ft_fabric_ops = { .module = THIS_MODULE, .name = "fc", .node_acl_size = sizeof(struct ft_node_acl), .get_fabric_name = ft_get_fabric_name, .tpg_get_wwn = ft_get_fabric_wwn, .tpg_get_tag = ft_get_tag, .tpg_check_demo_mode = ft_check_false, .tpg_check_demo_mode_cache = ft_check_false, .tpg_check_demo_mode_write_protect = ft_check_false, .tpg_check_prod_mode_write_protect = ft_check_false, .tpg_get_inst_index = ft_tpg_get_inst_index, .check_stop_free = ft_check_stop_free, .release_cmd = ft_release_cmd, .close_session = ft_sess_close, .sess_get_index = ft_sess_get_index, .sess_get_initiator_sid = NULL, .write_pending = ft_write_pending, .write_pending_status = ft_write_pending_status, .set_default_node_attributes = ft_set_default_node_attr, .get_cmd_state = ft_get_cmd_state, .queue_data_in = ft_queue_data_in, .queue_status = ft_queue_status, .queue_tm_rsp = ft_queue_tm_resp, .aborted_task = ft_aborted_task, /* * Setup function pointers for generic logic in * target_core_fabric_configfs.c */ .fabric_make_wwn = &ft_add_wwn, .fabric_drop_wwn = &ft_del_wwn, .fabric_make_tpg = &ft_add_tpg, .fabric_drop_tpg = &ft_del_tpg, .fabric_init_nodeacl = &ft_init_nodeacl, .tfc_wwn_attrs = ft_wwn_attrs, .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs, }; static struct notifier_block ft_notifier = { .notifier_call = ft_lport_notify };
static int __init ft_init(void) { int ret; ret = target_register_template(&ft_fabric_ops); if (ret) goto out; ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov); if (ret) goto out_unregister_template; blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier); fc_lport_iterate(ft_lport_add, NULL); return 0; out_unregister_template: target_unregister_template(&ft_fabric_ops); out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil3951.32%150.00%
christoph hellwigchristoph hellwig3748.68%150.00%
Total76100.00%2100.00%


static void __exit ft_exit(void) { blocking_notifier_chain_unregister(&fc_lport_notifier_head, &ft_notifier); fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov); fc_lport_iterate(ft_lport_del, NULL); target_unregister_template(&ft_fabric_ops); synchronize_rcu(); }

Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil3788.10%150.00%
christoph hellwigchristoph hellwig511.90%150.00%
Total42100.00%2100.00%

MODULE_DESCRIPTION("FC TCM fabric driver " FT_VERSION); MODULE_LICENSE("GPL"); module_init(ft_init); module_exit(ft_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
kiran patilkiran patil160277.80%14.76%
andy groverandy grover1959.47%628.57%
christoph hellwigchristoph hellwig1899.18%942.86%
mark d. rustadmark d. rustad371.80%14.76%
andy shevchenkoandy shevchenko170.83%14.76%
jingoo hanjingoo han130.63%14.76%
nicholas bellingernicholas bellinger60.29%29.52%
Total2059100.00%21100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}