diff options
author | Christoph Hellwig <hch@lst.de> | 2015-04-08 14:01:35 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-04-14 15:28:41 -0400 |
commit | 9ac8928e6a3e1ed02e632e45aa766129fe6b1802 (patch) | |
tree | ea516680cc5f811df862966bb43cfbe3e34dfb26 /drivers/target | |
parent | 2c336e3a2e1728d9b3116422655832184dc7046c (diff) |
target: simplify the target template registration API
Instead of calling target_fabric_configfs_init() +
target_fabric_configfs_register() / target_fabric_configfs_deregister()
target_fabric_configfs_free() from every target driver, rewrite the API
so that we have simple register/unregister functions that operate on
a const operations vector.
This patch also fixes a memory leak in several target drivers. Several
target drivers namely called target_fabric_configfs_deregister()
without calling target_fabric_configfs_free().
A large part of this patch is based on earlier changes from
Bart Van Assche <bart.vanassche@sandisk.com>.
(v2: Add a new TF_CIT_SETUP_DRV macro so that the core configfs code
can declare attributes as either core only or for drivers)
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/iscsi/iscsi_target.c | 23 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target.h | 2 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_configfs.c | 180 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_configfs.h | 7 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_tpg.c | 6 | ||||
-rw-r--r-- | drivers/target/loopback/tcm_loop.c | 178 | ||||
-rw-r--r-- | drivers/target/sbp/sbp_target.c | 68 | ||||
-rw-r--r-- | drivers/target/target_core_configfs.c | 176 | ||||
-rw-r--r-- | drivers/target/target_core_fabric_configfs.c | 38 | ||||
-rw-r--r-- | drivers/target/target_core_pr.c | 16 | ||||
-rw-r--r-- | drivers/target/target_core_tpg.c | 2 | ||||
-rw-r--r-- | drivers/target/target_core_transport.c | 6 | ||||
-rw-r--r-- | drivers/target/target_core_xcopy.c | 2 | ||||
-rw-r--r-- | drivers/target/tcm_fc/tcm_fc.h | 1 | ||||
-rw-r--r-- | drivers/target/tcm_fc/tfc_conf.c | 89 |
15 files changed, 246 insertions, 548 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index cd611e740de7..5d75bb418696 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c | |||
@@ -33,7 +33,6 @@ | |||
33 | #include <target/iscsi/iscsi_target_core.h> | 33 | #include <target/iscsi/iscsi_target_core.h> |
34 | #include "iscsi_target_parameters.h" | 34 | #include "iscsi_target_parameters.h" |
35 | #include "iscsi_target_seq_pdu_list.h" | 35 | #include "iscsi_target_seq_pdu_list.h" |
36 | #include "iscsi_target_configfs.h" | ||
37 | #include "iscsi_target_datain_values.h" | 36 | #include "iscsi_target_datain_values.h" |
38 | #include "iscsi_target_erl0.h" | 37 | #include "iscsi_target_erl0.h" |
39 | #include "iscsi_target_erl1.h" | 38 | #include "iscsi_target_erl1.h" |
@@ -551,8 +550,8 @@ static int __init iscsi_target_init_module(void) | |||
551 | idr_init(&tiqn_idr); | 550 | idr_init(&tiqn_idr); |
552 | idr_init(&sess_idr); | 551 | idr_init(&sess_idr); |
553 | 552 | ||
554 | ret = iscsi_target_register_configfs(); | 553 | ret = target_register_template(&iscsi_ops); |
555 | if (ret < 0) | 554 | if (ret) |
556 | goto out; | 555 | goto out; |
557 | 556 | ||
558 | size = BITS_TO_LONGS(ISCSIT_BITMAP_BITS) * sizeof(long); | 557 | size = BITS_TO_LONGS(ISCSIT_BITMAP_BITS) * sizeof(long); |
@@ -616,7 +615,10 @@ qr_out: | |||
616 | bitmap_out: | 615 | bitmap_out: |
617 | vfree(iscsit_global->ts_bitmap); | 616 | vfree(iscsit_global->ts_bitmap); |
618 | configfs_out: | 617 | configfs_out: |
619 | iscsi_target_deregister_configfs(); | 618 | /* XXX: this probably wants it to be it's own unwind step.. */ |
619 | if (iscsit_global->discovery_tpg) | ||
620 | iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); | ||
621 | target_unregister_template(&iscsi_ops); | ||
620 | out: | 622 | out: |
621 | kfree(iscsit_global); | 623 | kfree(iscsit_global); |
622 | return -ENOMEM; | 624 | return -ENOMEM; |
@@ -631,7 +633,13 @@ static void __exit iscsi_target_cleanup_module(void) | |||
631 | kmem_cache_destroy(lio_ooo_cache); | 633 | kmem_cache_destroy(lio_ooo_cache); |
632 | kmem_cache_destroy(lio_r2t_cache); | 634 | kmem_cache_destroy(lio_r2t_cache); |
633 | 635 | ||
634 | iscsi_target_deregister_configfs(); | 636 | /* |
637 | * Shutdown discovery sessions and disable discovery TPG | ||
638 | */ | ||
639 | if (iscsit_global->discovery_tpg) | ||
640 | iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); | ||
641 | |||
642 | target_unregister_template(&iscsi_ops); | ||
635 | 643 | ||
636 | vfree(iscsit_global->ts_bitmap); | 644 | vfree(iscsit_global->ts_bitmap); |
637 | kfree(iscsit_global); | 645 | kfree(iscsit_global); |
@@ -983,7 +991,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
983 | /* | 991 | /* |
984 | * Initialize struct se_cmd descriptor from target_core_mod infrastructure | 992 | * Initialize struct se_cmd descriptor from target_core_mod infrastructure |
985 | */ | 993 | */ |
986 | transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops, | 994 | transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops, |
987 | conn->sess->se_sess, be32_to_cpu(hdr->data_length), | 995 | conn->sess->se_sess, be32_to_cpu(hdr->data_length), |
988 | cmd->data_direction, sam_task_attr, | 996 | cmd->data_direction, sam_task_attr, |
989 | cmd->sense_buffer + 2); | 997 | cmd->sense_buffer + 2); |
@@ -1798,8 +1806,7 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
1798 | u8 tcm_function; | 1806 | u8 tcm_function; |
1799 | int ret; | 1807 | int ret; |
1800 | 1808 | ||
1801 | transport_init_se_cmd(&cmd->se_cmd, | 1809 | transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops, |
1802 | &lio_target_fabric_configfs->tf_ops, | ||
1803 | conn->sess->se_sess, 0, DMA_NONE, | 1810 | conn->sess->se_sess, 0, DMA_NONE, |
1804 | TCM_SIMPLE_TAG, cmd->sense_buffer + 2); | 1811 | TCM_SIMPLE_TAG, cmd->sense_buffer + 2); |
1805 | 1812 | ||
diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h index e936d56fb523..7d0f9c00d9c2 100644 --- a/drivers/target/iscsi/iscsi_target.h +++ b/drivers/target/iscsi/iscsi_target.h | |||
@@ -35,7 +35,7 @@ extern void iscsit_stop_session(struct iscsi_session *, int, int); | |||
35 | extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int); | 35 | extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int); |
36 | 36 | ||
37 | extern struct iscsit_global *iscsit_global; | 37 | extern struct iscsit_global *iscsit_global; |
38 | extern struct target_fabric_configfs *lio_target_fabric_configfs; | 38 | extern const struct target_core_fabric_ops iscsi_ops; |
39 | 39 | ||
40 | extern struct kmem_cache *lio_dr_cache; | 40 | extern struct kmem_cache *lio_dr_cache; |
41 | extern struct kmem_cache *lio_ooo_cache; | 41 | extern struct kmem_cache *lio_ooo_cache; |
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 9cb5ab472a52..469fce44ebad 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c | |||
@@ -37,9 +37,6 @@ | |||
37 | #include "iscsi_target_util.h" | 37 | #include "iscsi_target_util.h" |
38 | #include "iscsi_target.h" | 38 | #include "iscsi_target.h" |
39 | #include <target/iscsi/iscsi_target_stat.h> | 39 | #include <target/iscsi/iscsi_target_stat.h> |
40 | #include "iscsi_target_configfs.h" | ||
41 | |||
42 | struct target_fabric_configfs *lio_target_fabric_configfs; | ||
43 | 40 | ||
44 | struct lio_target_configfs_attribute { | 41 | struct lio_target_configfs_attribute { |
45 | struct configfs_attribute attr; | 42 | struct configfs_attribute attr; |
@@ -1466,10 +1463,8 @@ static struct se_portal_group *lio_target_tiqn_addtpg( | |||
1466 | if (!tpg) | 1463 | if (!tpg) |
1467 | return NULL; | 1464 | return NULL; |
1468 | 1465 | ||
1469 | ret = core_tpg_register( | 1466 | ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg, |
1470 | &lio_target_fabric_configfs->tf_ops, | 1467 | tpg, TRANSPORT_TPG_TYPE_NORMAL); |
1471 | wwn, &tpg->tpg_se_tpg, tpg, | ||
1472 | TRANSPORT_TPG_TYPE_NORMAL); | ||
1473 | if (ret < 0) | 1468 | if (ret < 0) |
1474 | return NULL; | 1469 | return NULL; |
1475 | 1470 | ||
@@ -1983,117 +1978,60 @@ static void lio_release_cmd(struct se_cmd *se_cmd) | |||
1983 | iscsit_release_cmd(cmd); | 1978 | iscsit_release_cmd(cmd); |
1984 | } | 1979 | } |
1985 | 1980 | ||
1986 | /* End functions for target_core_fabric_ops */ | 1981 | const struct target_core_fabric_ops iscsi_ops = { |
1987 | 1982 | .module = THIS_MODULE, | |
1988 | int iscsi_target_register_configfs(void) | 1983 | .name = "iscsi", |
1989 | { | 1984 | .get_fabric_name = iscsi_get_fabric_name, |
1990 | struct target_fabric_configfs *fabric; | 1985 | .get_fabric_proto_ident = iscsi_get_fabric_proto_ident, |
1991 | int ret; | 1986 | .tpg_get_wwn = lio_tpg_get_endpoint_wwn, |
1992 | 1987 | .tpg_get_tag = lio_tpg_get_tag, | |
1993 | lio_target_fabric_configfs = NULL; | 1988 | .tpg_get_default_depth = lio_tpg_get_default_depth, |
1994 | fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi"); | 1989 | .tpg_get_pr_transport_id = iscsi_get_pr_transport_id, |
1995 | if (IS_ERR(fabric)) { | 1990 | .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len, |
1996 | pr_err("target_fabric_configfs_init() for" | 1991 | .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id, |
1997 | " LIO-Target failed!\n"); | 1992 | .tpg_check_demo_mode = lio_tpg_check_demo_mode, |
1998 | return PTR_ERR(fabric); | 1993 | .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, |
1999 | } | 1994 | .tpg_check_demo_mode_write_protect = |
2000 | /* | 1995 | lio_tpg_check_demo_mode_write_protect, |
2001 | * Setup the fabric API of function pointers used by target_core_mod.. | 1996 | .tpg_check_prod_mode_write_protect = |
2002 | */ | 1997 | lio_tpg_check_prod_mode_write_protect, |
2003 | fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; | 1998 | .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, |
2004 | fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; | 1999 | .tpg_alloc_fabric_acl = lio_tpg_alloc_fabric_acl, |
2005 | fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; | 2000 | .tpg_release_fabric_acl = lio_tpg_release_fabric_acl, |
2006 | fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; | 2001 | .tpg_get_inst_index = lio_tpg_get_inst_index, |
2007 | fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; | 2002 | .check_stop_free = lio_check_stop_free, |
2008 | fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; | 2003 | .release_cmd = lio_release_cmd, |
2009 | fabric->tf_ops.tpg_get_pr_transport_id_len = | 2004 | .shutdown_session = lio_tpg_shutdown_session, |
2010 | &iscsi_get_pr_transport_id_len; | 2005 | .close_session = lio_tpg_close_session, |
2011 | fabric->tf_ops.tpg_parse_pr_out_transport_id = | 2006 | .sess_get_index = lio_sess_get_index, |
2012 | &iscsi_parse_pr_out_transport_id; | 2007 | .sess_get_initiator_sid = lio_sess_get_initiator_sid, |
2013 | fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; | 2008 | .write_pending = lio_write_pending, |
2014 | fabric->tf_ops.tpg_check_demo_mode_cache = | 2009 | .write_pending_status = lio_write_pending_status, |
2015 | &lio_tpg_check_demo_mode_cache; | 2010 | .set_default_node_attributes = lio_set_default_node_attributes, |
2016 | fabric->tf_ops.tpg_check_demo_mode_write_protect = | 2011 | .get_task_tag = iscsi_get_task_tag, |
2017 | &lio_tpg_check_demo_mode_write_protect; | 2012 | .get_cmd_state = iscsi_get_cmd_state, |
2018 | fabric->tf_ops.tpg_check_prod_mode_write_protect = | 2013 | .queue_data_in = lio_queue_data_in, |
2019 | &lio_tpg_check_prod_mode_write_protect; | 2014 | .queue_status = lio_queue_status, |
2020 | fabric->tf_ops.tpg_check_prot_fabric_only = | 2015 | .queue_tm_rsp = lio_queue_tm_rsp, |
2021 | &lio_tpg_check_prot_fabric_only; | 2016 | .aborted_task = lio_aborted_task, |
2022 | fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; | 2017 | .fabric_make_wwn = lio_target_call_coreaddtiqn, |
2023 | fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; | 2018 | .fabric_drop_wwn = lio_target_call_coredeltiqn, |
2024 | fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; | 2019 | .fabric_make_tpg = lio_target_tiqn_addtpg, |
2025 | fabric->tf_ops.check_stop_free = &lio_check_stop_free, | 2020 | .fabric_drop_tpg = lio_target_tiqn_deltpg, |
2026 | fabric->tf_ops.release_cmd = &lio_release_cmd; | 2021 | .fabric_make_np = lio_target_call_addnptotpg, |
2027 | fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; | 2022 | .fabric_drop_np = lio_target_call_delnpfromtpg, |
2028 | fabric->tf_ops.close_session = &lio_tpg_close_session; | 2023 | .fabric_make_nodeacl = lio_target_make_nodeacl, |
2029 | fabric->tf_ops.sess_get_index = &lio_sess_get_index; | 2024 | .fabric_drop_nodeacl = lio_target_drop_nodeacl, |
2030 | fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; | 2025 | |
2031 | fabric->tf_ops.write_pending = &lio_write_pending; | 2026 | .tfc_discovery_attrs = lio_target_discovery_auth_attrs, |
2032 | fabric->tf_ops.write_pending_status = &lio_write_pending_status; | 2027 | .tfc_wwn_attrs = lio_target_wwn_attrs, |
2033 | fabric->tf_ops.set_default_node_attributes = | 2028 | .tfc_tpg_base_attrs = lio_target_tpg_attrs, |
2034 | &lio_set_default_node_attributes; | 2029 | .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs, |
2035 | fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; | 2030 | .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs, |
2036 | fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; | 2031 | .tfc_tpg_param_attrs = lio_target_tpg_param_attrs, |
2037 | fabric->tf_ops.queue_data_in = &lio_queue_data_in; | 2032 | .tfc_tpg_np_base_attrs = lio_target_portal_attrs, |
2038 | fabric->tf_ops.queue_status = &lio_queue_status; | 2033 | .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs, |
2039 | fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; | 2034 | .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, |
2040 | fabric->tf_ops.aborted_task = &lio_aborted_task; | 2035 | .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, |
2041 | /* | 2036 | .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, |
2042 | * Setup function pointers for generic logic in target_core_fabric_configfs.c | 2037 | }; |
2043 | */ | ||
2044 | fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn; | ||
2045 | fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn; | ||
2046 | fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg; | ||
2047 | fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg; | ||
2048 | fabric->tf_ops.fabric_post_link = NULL; | ||
2049 | fabric->tf_ops.fabric_pre_unlink = NULL; | ||
2050 | fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg; | ||
2051 | fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg; | ||
2052 | fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl; | ||
2053 | fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl; | ||
2054 | /* | ||
2055 | * Setup default attribute lists for various fabric->tf_cit_tmpl | ||
2056 | * sturct config_item_type's | ||
2057 | */ | ||
2058 | fabric->tf_cit_tmpl.tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs; | ||
2059 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs; | ||
2060 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs; | ||
2061 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs; | ||
2062 | fabric->tf_cit_tmpl.tfc_tpg_auth_cit.ct_attrs = lio_target_tpg_auth_attrs; | ||
2063 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs; | ||
2064 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs; | ||
2065 | fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs; | ||
2066 | fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs; | ||
2067 | fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs; | ||
2068 | fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs; | ||
2069 | |||
2070 | ret = target_fabric_configfs_register(fabric); | ||
2071 | if (ret < 0) { | ||
2072 | pr_err("target_fabric_configfs_register() for" | ||
2073 | " LIO-Target failed!\n"); | ||
2074 | target_fabric_configfs_free(fabric); | ||
2075 | return ret; | ||
2076 | } | ||
2077 | |||
2078 | lio_target_fabric_configfs = fabric; | ||
2079 | pr_debug("LIO_TARGET[0] - Set fabric ->" | ||
2080 | " lio_target_fabric_configfs\n"); | ||
2081 | return 0; | ||
2082 | } | ||
2083 | |||
2084 | |||
2085 | void iscsi_target_deregister_configfs(void) | ||
2086 | { | ||
2087 | if (!lio_target_fabric_configfs) | ||
2088 | return; | ||
2089 | /* | ||
2090 | * Shutdown discovery sessions and disable discovery TPG | ||
2091 | */ | ||
2092 | if (iscsit_global->discovery_tpg) | ||
2093 | iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); | ||
2094 | |||
2095 | target_fabric_configfs_deregister(lio_target_fabric_configfs); | ||
2096 | lio_target_fabric_configfs = NULL; | ||
2097 | pr_debug("LIO_TARGET[0] - Cleared" | ||
2098 | " lio_target_fabric_configfs\n"); | ||
2099 | } | ||
diff --git a/drivers/target/iscsi/iscsi_target_configfs.h b/drivers/target/iscsi/iscsi_target_configfs.h deleted file mode 100644 index 8cd5a63c4edc..000000000000 --- a/drivers/target/iscsi/iscsi_target_configfs.h +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | #ifndef ISCSI_TARGET_CONFIGFS_H | ||
2 | #define ISCSI_TARGET_CONFIGFS_H | ||
3 | |||
4 | extern int iscsi_target_register_configfs(void); | ||
5 | extern void iscsi_target_deregister_configfs(void); | ||
6 | |||
7 | #endif /* ISCSI_TARGET_CONFIGFS_H */ | ||
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c index 3076e6f3a831..e8a240818353 100644 --- a/drivers/target/iscsi/iscsi_target_tpg.c +++ b/drivers/target/iscsi/iscsi_target_tpg.c | |||
@@ -68,10 +68,8 @@ int iscsit_load_discovery_tpg(void) | |||
68 | return -1; | 68 | return -1; |
69 | } | 69 | } |
70 | 70 | ||
71 | ret = core_tpg_register( | 71 | ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg, |
72 | &lio_target_fabric_configfs->tf_ops, | 72 | tpg, TRANSPORT_TPG_TYPE_DISCOVERY); |
73 | NULL, &tpg->tpg_se_tpg, tpg, | ||
74 | TRANSPORT_TPG_TYPE_DISCOVERY); | ||
75 | if (ret < 0) { | 73 | if (ret < 0) { |
76 | kfree(tpg); | 74 | kfree(tpg); |
77 | return -1; | 75 | return -1; |
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index 2114c1d2c9de..5b143d2c08f7 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c | |||
@@ -41,8 +41,7 @@ | |||
41 | 41 | ||
42 | #define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev) | 42 | #define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev) |
43 | 43 | ||
44 | /* Local pointer to allocated TCM configfs fabric module */ | 44 | static const struct target_core_fabric_ops loop_ops; |
45 | static struct target_fabric_configfs *tcm_loop_fabric_configfs; | ||
46 | 45 | ||
47 | static struct workqueue_struct *tcm_loop_workqueue; | 46 | static struct workqueue_struct *tcm_loop_workqueue; |
48 | static struct kmem_cache *tcm_loop_cmd_cache; | 47 | static struct kmem_cache *tcm_loop_cmd_cache; |
@@ -1238,8 +1237,7 @@ static struct se_portal_group *tcm_loop_make_naa_tpg( | |||
1238 | /* | 1237 | /* |
1239 | * Register the tl_tpg as a emulated SAS TCM Target Endpoint | 1238 | * Register the tl_tpg as a emulated SAS TCM Target Endpoint |
1240 | */ | 1239 | */ |
1241 | ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops, | 1240 | ret = core_tpg_register(&loop_ops, wwn, &tl_tpg->tl_se_tpg, tl_tpg, |
1242 | wwn, &tl_tpg->tl_se_tpg, tl_tpg, | ||
1243 | TRANSPORT_TPG_TYPE_NORMAL); | 1241 | TRANSPORT_TPG_TYPE_NORMAL); |
1244 | if (ret < 0) | 1242 | if (ret < 0) |
1245 | return ERR_PTR(-ENOMEM); | 1243 | return ERR_PTR(-ENOMEM); |
@@ -1387,129 +1385,51 @@ static struct configfs_attribute *tcm_loop_wwn_attrs[] = { | |||
1387 | 1385 | ||
1388 | /* End items for tcm_loop_cit */ | 1386 | /* End items for tcm_loop_cit */ |
1389 | 1387 | ||
1390 | static int tcm_loop_register_configfs(void) | 1388 | static const struct target_core_fabric_ops loop_ops = { |
1391 | { | 1389 | .module = THIS_MODULE, |
1392 | struct target_fabric_configfs *fabric; | 1390 | .name = "loopback", |
1393 | int ret; | 1391 | .get_fabric_name = tcm_loop_get_fabric_name, |
1394 | /* | 1392 | .get_fabric_proto_ident = tcm_loop_get_fabric_proto_ident, |
1395 | * Set the TCM Loop HBA counter to zero | 1393 | .tpg_get_wwn = tcm_loop_get_endpoint_wwn, |
1396 | */ | 1394 | .tpg_get_tag = tcm_loop_get_tag, |
1397 | tcm_loop_hba_no_cnt = 0; | 1395 | .tpg_get_default_depth = tcm_loop_get_default_depth, |
1398 | /* | 1396 | .tpg_get_pr_transport_id = tcm_loop_get_pr_transport_id, |
1399 | * Register the top level struct config_item_type with TCM core | 1397 | .tpg_get_pr_transport_id_len = tcm_loop_get_pr_transport_id_len, |
1400 | */ | 1398 | .tpg_parse_pr_out_transport_id = tcm_loop_parse_pr_out_transport_id, |
1401 | fabric = target_fabric_configfs_init(THIS_MODULE, "loopback"); | 1399 | .tpg_check_demo_mode = tcm_loop_check_demo_mode, |
1402 | if (IS_ERR(fabric)) { | 1400 | .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache, |
1403 | pr_err("tcm_loop_register_configfs() failed!\n"); | 1401 | .tpg_check_demo_mode_write_protect = |
1404 | return PTR_ERR(fabric); | 1402 | tcm_loop_check_demo_mode_write_protect, |
1405 | } | 1403 | .tpg_check_prod_mode_write_protect = |
1406 | /* | 1404 | tcm_loop_check_prod_mode_write_protect, |
1407 | * Setup the fabric API of function pointers used by target_core_mod | 1405 | .tpg_check_prot_fabric_only = tcm_loop_check_prot_fabric_only, |
1408 | */ | 1406 | .tpg_alloc_fabric_acl = tcm_loop_tpg_alloc_fabric_acl, |
1409 | fabric->tf_ops.get_fabric_name = &tcm_loop_get_fabric_name; | 1407 | .tpg_release_fabric_acl = tcm_loop_tpg_release_fabric_acl, |
1410 | fabric->tf_ops.get_fabric_proto_ident = &tcm_loop_get_fabric_proto_ident; | 1408 | .tpg_get_inst_index = tcm_loop_get_inst_index, |
1411 | fabric->tf_ops.tpg_get_wwn = &tcm_loop_get_endpoint_wwn; | 1409 | .check_stop_free = tcm_loop_check_stop_free, |
1412 | fabric->tf_ops.tpg_get_tag = &tcm_loop_get_tag; | 1410 | .release_cmd = tcm_loop_release_cmd, |
1413 | fabric->tf_ops.tpg_get_default_depth = &tcm_loop_get_default_depth; | 1411 | .shutdown_session = tcm_loop_shutdown_session, |
1414 | fabric->tf_ops.tpg_get_pr_transport_id = &tcm_loop_get_pr_transport_id; | 1412 | .close_session = tcm_loop_close_session, |
1415 | fabric->tf_ops.tpg_get_pr_transport_id_len = | 1413 | .sess_get_index = tcm_loop_sess_get_index, |
1416 | &tcm_loop_get_pr_transport_id_len; | 1414 | .write_pending = tcm_loop_write_pending, |
1417 | fabric->tf_ops.tpg_parse_pr_out_transport_id = | 1415 | .write_pending_status = tcm_loop_write_pending_status, |
1418 | &tcm_loop_parse_pr_out_transport_id; | 1416 | .set_default_node_attributes = tcm_loop_set_default_node_attributes, |
1419 | fabric->tf_ops.tpg_check_demo_mode = &tcm_loop_check_demo_mode; | 1417 | .get_task_tag = tcm_loop_get_task_tag, |
1420 | fabric->tf_ops.tpg_check_demo_mode_cache = | 1418 | .get_cmd_state = tcm_loop_get_cmd_state, |
1421 | &tcm_loop_check_demo_mode_cache; | 1419 | .queue_data_in = tcm_loop_queue_data_in, |
1422 | fabric->tf_ops.tpg_check_demo_mode_write_protect = | 1420 | .queue_status = tcm_loop_queue_status, |
1423 | &tcm_loop_check_demo_mode_write_protect; | 1421 | .queue_tm_rsp = tcm_loop_queue_tm_rsp, |
1424 | fabric->tf_ops.tpg_check_prod_mode_write_protect = | 1422 | .aborted_task = tcm_loop_aborted_task, |
1425 | &tcm_loop_check_prod_mode_write_protect; | 1423 | .fabric_make_wwn = tcm_loop_make_scsi_hba, |
1426 | fabric->tf_ops.tpg_check_prot_fabric_only = | 1424 | .fabric_drop_wwn = tcm_loop_drop_scsi_hba, |
1427 | &tcm_loop_check_prot_fabric_only; | 1425 | .fabric_make_tpg = tcm_loop_make_naa_tpg, |
1428 | /* | 1426 | .fabric_drop_tpg = tcm_loop_drop_naa_tpg, |
1429 | * The TCM loopback fabric module runs in demo-mode to a local | 1427 | .fabric_post_link = tcm_loop_port_link, |
1430 | * virtual SCSI device, so fabric dependent initator ACLs are | 1428 | .fabric_pre_unlink = tcm_loop_port_unlink, |
1431 | * not required. | 1429 | .tfc_wwn_attrs = tcm_loop_wwn_attrs, |
1432 | */ | 1430 | .tfc_tpg_base_attrs = tcm_loop_tpg_attrs, |
1433 | fabric->tf_ops.tpg_alloc_fabric_acl = &tcm_loop_tpg_alloc_fabric_acl; | 1431 | .tfc_tpg_attrib_attrs = tcm_loop_tpg_attrib_attrs, |
1434 | fabric->tf_ops.tpg_release_fabric_acl = | 1432 | }; |
1435 | &tcm_loop_tpg_release_fabric_acl; | ||
1436 | fabric->tf_ops.tpg_get_inst_index = &tcm_loop_get_inst_index; | ||
1437 | /* | ||
1438 | * Used for setting up remaining TCM resources in process context | ||
1439 | */ | ||
1440 | fabric->tf_ops.check_stop_free = &tcm_loop_check_stop_free; | ||
1441 | fabric->tf_ops.release_cmd = &tcm_loop_release_cmd; | ||
1442 | fabric->tf_ops.shutdown_session = &tcm_loop_shutdown_session; | ||
1443 | fabric->tf_ops.close_session = &tcm_loop_close_session; | ||
1444 | fabric->tf_ops.sess_get_index = &tcm_loop_sess_get_index; | ||
1445 | fabric->tf_ops.sess_get_initiator_sid = NULL; | ||
1446 | fabric->tf_ops.write_pending = &tcm_loop_write_pending; | ||
1447 | fabric->tf_ops.write_pending_status = &tcm_loop_write_pending_status; | ||
1448 | /* | ||
1449 | * Not used for TCM loopback | ||
1450 | */ | ||
1451 | fabric->tf_ops.set_default_node_attributes = | ||
1452 | &tcm_loop_set_default_node_attributes; | ||
1453 | fabric->tf_ops.get_task_tag = &tcm_loop_get_task_tag; | ||
1454 | fabric->tf_ops.get_cmd_state = &tcm_loop_get_cmd_state; | ||
1455 | fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in; | ||
1456 | fabric->tf_ops.queue_status = &tcm_loop_queue_status; | ||
1457 | fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp; | ||
1458 | fabric->tf_ops.aborted_task = &tcm_loop_aborted_task; | ||
1459 | |||
1460 | /* | ||
1461 | * Setup function pointers for generic logic in target_core_fabric_configfs.c | ||
1462 | */ | ||
1463 | fabric->tf_ops.fabric_make_wwn = &tcm_loop_make_scsi_hba; | ||
1464 | fabric->tf_ops.fabric_drop_wwn = &tcm_loop_drop_scsi_hba; | ||
1465 | fabric->tf_ops.fabric_make_tpg = &tcm_loop_make_naa_tpg; | ||
1466 | fabric->tf_ops.fabric_drop_tpg = &tcm_loop_drop_naa_tpg; | ||
1467 | /* | ||
1468 | * fabric_post_link() and fabric_pre_unlink() are used for | ||
1469 | * registration and release of TCM Loop Virtual SCSI LUNs. | ||
1470 | */ | ||
1471 | fabric->tf_ops.fabric_post_link = &tcm_loop_port_link; | ||
1472 | fabric->tf_ops.fabric_pre_unlink = &tcm_loop_port_unlink; | ||
1473 | fabric->tf_ops.fabric_make_np = NULL; | ||
1474 | fabric->tf_ops.fabric_drop_np = NULL; | ||
1475 | /* | ||
1476 | * Setup default attribute lists for various fabric->tf_cit_tmpl | ||
1477 | */ | ||
1478 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_loop_wwn_attrs; | ||
1479 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = tcm_loop_tpg_attrs; | ||
1480 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = tcm_loop_tpg_attrib_attrs; | ||
1481 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; | ||
1482 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
1483 | /* | ||
1484 | * Once fabric->tf_ops has been setup, now register the fabric for | ||
1485 | * use within TCM | ||
1486 | */ | ||
1487 | ret = target_fabric_configfs_register(fabric); | ||
1488 | if (ret < 0) { | ||
1489 | pr_err("target_fabric_configfs_register() for" | ||
1490 | " TCM_Loop failed!\n"); | ||
1491 | target_fabric_configfs_free(fabric); | ||
1492 | return -1; | ||
1493 | } | ||
1494 | /* | ||
1495 | * Setup our local pointer to *fabric. | ||
1496 | */ | ||
1497 | tcm_loop_fabric_configfs = fabric; | ||
1498 | pr_debug("TCM_LOOP[0] - Set fabric ->" | ||
1499 | " tcm_loop_fabric_configfs\n"); | ||
1500 | return 0; | ||
1501 | } | ||
1502 | |||
1503 | static void tcm_loop_deregister_configfs(void) | ||
1504 | { | ||
1505 | if (!tcm_loop_fabric_configfs) | ||
1506 | return; | ||
1507 | |||
1508 | target_fabric_configfs_deregister(tcm_loop_fabric_configfs); | ||
1509 | tcm_loop_fabric_configfs = NULL; | ||
1510 | pr_debug("TCM_LOOP[0] - Cleared" | ||
1511 | " tcm_loop_fabric_configfs\n"); | ||
1512 | } | ||
1513 | 1433 | ||
1514 | static int __init tcm_loop_fabric_init(void) | 1434 | static int __init tcm_loop_fabric_init(void) |
1515 | { | 1435 | { |
@@ -1533,7 +1453,7 @@ static int __init tcm_loop_fabric_init(void) | |||
1533 | if (ret) | 1453 | if (ret) |
1534 | goto out_destroy_cache; | 1454 | goto out_destroy_cache; |
1535 | 1455 | ||
1536 | ret = tcm_loop_register_configfs(); | 1456 | ret = target_register_template(&loop_ops); |
1537 | if (ret) | 1457 | if (ret) |
1538 | goto out_release_core_bus; | 1458 | goto out_release_core_bus; |
1539 | 1459 | ||
@@ -1551,7 +1471,7 @@ out: | |||
1551 | 1471 | ||
1552 | static void __exit tcm_loop_fabric_exit(void) | 1472 | static void __exit tcm_loop_fabric_exit(void) |
1553 | { | 1473 | { |
1554 | tcm_loop_deregister_configfs(); | 1474 | target_unregister_template(&loop_ops); |
1555 | tcm_loop_release_core_bus(); | 1475 | tcm_loop_release_core_bus(); |
1556 | kmem_cache_destroy(tcm_loop_cmd_cache); | 1476 | kmem_cache_destroy(tcm_loop_cmd_cache); |
1557 | destroy_workqueue(tcm_loop_workqueue); | 1477 | destroy_workqueue(tcm_loop_workqueue); |
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c index 9512af6a8114..18b0f9703ff2 100644 --- a/drivers/target/sbp/sbp_target.c +++ b/drivers/target/sbp/sbp_target.c | |||
@@ -42,8 +42,7 @@ | |||
42 | 42 | ||
43 | #include "sbp_target.h" | 43 | #include "sbp_target.h" |
44 | 44 | ||
45 | /* Local pointer to allocated TCM configfs fabric module */ | 45 | static const struct target_core_fabric_ops sbp_ops; |
46 | static struct target_fabric_configfs *sbp_fabric_configfs; | ||
47 | 46 | ||
48 | /* FireWire address region for management and command block address handlers */ | 47 | /* FireWire address region for management and command block address handlers */ |
49 | static const struct fw_address_region sbp_register_region = { | 48 | static const struct fw_address_region sbp_register_region = { |
@@ -2215,8 +2214,7 @@ static struct se_portal_group *sbp_make_tpg( | |||
2215 | goto out_free_tpg; | 2214 | goto out_free_tpg; |
2216 | } | 2215 | } |
2217 | 2216 | ||
2218 | ret = core_tpg_register(&sbp_fabric_configfs->tf_ops, wwn, | 2217 | ret = core_tpg_register(&sbp_ops, wwn, &tpg->se_tpg, tpg, |
2219 | &tpg->se_tpg, (void *)tpg, | ||
2220 | TRANSPORT_TPG_TYPE_NORMAL); | 2218 | TRANSPORT_TPG_TYPE_NORMAL); |
2221 | if (ret < 0) | 2219 | if (ret < 0) |
2222 | goto out_unreg_mgt_agt; | 2220 | goto out_unreg_mgt_agt; |
@@ -2503,7 +2501,9 @@ static struct configfs_attribute *sbp_tpg_attrib_attrs[] = { | |||
2503 | NULL, | 2501 | NULL, |
2504 | }; | 2502 | }; |
2505 | 2503 | ||
2506 | static struct target_core_fabric_ops sbp_ops = { | 2504 | static const struct target_core_fabric_ops sbp_ops = { |
2505 | .module = THIS_MODULE, | ||
2506 | .name = "sbp", | ||
2507 | .get_fabric_name = sbp_get_fabric_name, | 2507 | .get_fabric_name = sbp_get_fabric_name, |
2508 | .get_fabric_proto_ident = sbp_get_fabric_proto_ident, | 2508 | .get_fabric_proto_ident = sbp_get_fabric_proto_ident, |
2509 | .tpg_get_wwn = sbp_get_fabric_wwn, | 2509 | .tpg_get_wwn = sbp_get_fabric_wwn, |
@@ -2544,68 +2544,20 @@ static struct target_core_fabric_ops sbp_ops = { | |||
2544 | .fabric_drop_np = NULL, | 2544 | .fabric_drop_np = NULL, |
2545 | .fabric_make_nodeacl = sbp_make_nodeacl, | 2545 | .fabric_make_nodeacl = sbp_make_nodeacl, |
2546 | .fabric_drop_nodeacl = sbp_drop_nodeacl, | 2546 | .fabric_drop_nodeacl = sbp_drop_nodeacl, |
2547 | }; | ||
2548 | |||
2549 | static int sbp_register_configfs(void) | ||
2550 | { | ||
2551 | struct target_fabric_configfs *fabric; | ||
2552 | int ret; | ||
2553 | |||
2554 | fabric = target_fabric_configfs_init(THIS_MODULE, "sbp"); | ||
2555 | if (IS_ERR(fabric)) { | ||
2556 | pr_err("target_fabric_configfs_init() failed\n"); | ||
2557 | return PTR_ERR(fabric); | ||
2558 | } | ||
2559 | |||
2560 | fabric->tf_ops = sbp_ops; | ||
2561 | |||
2562 | /* | ||
2563 | * Setup default attribute lists for various fabric->tf_cit_tmpl | ||
2564 | */ | ||
2565 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = sbp_wwn_attrs; | ||
2566 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = sbp_tpg_base_attrs; | ||
2567 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = sbp_tpg_attrib_attrs; | ||
2568 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; | ||
2569 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
2570 | fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL; | ||
2571 | fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; | ||
2572 | fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL; | ||
2573 | fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL; | ||
2574 | |||
2575 | ret = target_fabric_configfs_register(fabric); | ||
2576 | if (ret < 0) { | ||
2577 | pr_err("target_fabric_configfs_register() failed for SBP\n"); | ||
2578 | return ret; | ||
2579 | } | ||
2580 | 2547 | ||
2581 | sbp_fabric_configfs = fabric; | 2548 | .tfc_wwn_attrs = sbp_wwn_attrs, |
2582 | 2549 | .tfc_tpg_base_attrs = sbp_tpg_base_attrs, | |
2583 | return 0; | 2550 | .tfc_tpg_attrib_attrs = sbp_tpg_attrib_attrs, |
2584 | }; | ||
2585 | |||
2586 | static void sbp_deregister_configfs(void) | ||
2587 | { | ||
2588 | if (!sbp_fabric_configfs) | ||
2589 | return; | ||
2590 | |||
2591 | target_fabric_configfs_deregister(sbp_fabric_configfs); | ||
2592 | sbp_fabric_configfs = NULL; | ||
2593 | }; | 2551 | }; |
2594 | 2552 | ||
2595 | static int __init sbp_init(void) | 2553 | static int __init sbp_init(void) |
2596 | { | 2554 | { |
2597 | int ret; | 2555 | return target_register_template(&sbp_ops); |
2598 | |||
2599 | ret = sbp_register_configfs(); | ||
2600 | if (ret < 0) | ||
2601 | return ret; | ||
2602 | |||
2603 | return 0; | ||
2604 | }; | 2556 | }; |
2605 | 2557 | ||
2606 | static void __exit sbp_exit(void) | 2558 | static void __exit sbp_exit(void) |
2607 | { | 2559 | { |
2608 | sbp_deregister_configfs(); | 2560 | target_unregister_template(&sbp_ops); |
2609 | }; | 2561 | }; |
2610 | 2562 | ||
2611 | MODULE_DESCRIPTION("FireWire SBP fabric driver"); | 2563 | MODULE_DESCRIPTION("FireWire SBP fabric driver"); |
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 69baf1c53d99..ddaf76a4ac2a 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c | |||
@@ -300,81 +300,17 @@ struct configfs_subsystem *target_core_subsystem[] = { | |||
300 | // Start functions called by external Target Fabrics Modules | 300 | // Start functions called by external Target Fabrics Modules |
301 | //############################################################################*/ | 301 | //############################################################################*/ |
302 | 302 | ||
303 | /* | 303 | static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo) |
304 | * First function called by fabric modules to: | ||
305 | * | ||
306 | * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer. | ||
307 | * 2) Add struct target_fabric_configfs to g_tf_list | ||
308 | * 3) Return struct target_fabric_configfs to fabric module to be passed | ||
309 | * into target_fabric_configfs_register(). | ||
310 | */ | ||
311 | struct target_fabric_configfs *target_fabric_configfs_init( | ||
312 | struct module *fabric_mod, | ||
313 | const char *name) | ||
314 | { | 304 | { |
315 | struct target_fabric_configfs *tf; | 305 | if (!tfo->name) { |
316 | 306 | pr_err("Missing tfo->name\n"); | |
317 | if (!(name)) { | 307 | return -EINVAL; |
318 | pr_err("Unable to locate passed fabric name\n"); | ||
319 | return ERR_PTR(-EINVAL); | ||
320 | } | 308 | } |
321 | if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) { | 309 | if (strlen(tfo->name) >= TARGET_FABRIC_NAME_SIZE) { |
322 | pr_err("Passed name: %s exceeds TARGET_FABRIC" | 310 | pr_err("Passed name: %s exceeds TARGET_FABRIC" |
323 | "_NAME_SIZE\n", name); | 311 | "_NAME_SIZE\n", tfo->name); |
324 | return ERR_PTR(-EINVAL); | 312 | return -EINVAL; |
325 | } | 313 | } |
326 | |||
327 | tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); | ||
328 | if (!tf) | ||
329 | return ERR_PTR(-ENOMEM); | ||
330 | |||
331 | INIT_LIST_HEAD(&tf->tf_list); | ||
332 | atomic_set(&tf->tf_access_cnt, 0); | ||
333 | /* | ||
334 | * Setup the default generic struct config_item_type's (cits) in | ||
335 | * struct target_fabric_configfs->tf_cit_tmpl | ||
336 | */ | ||
337 | tf->tf_module = fabric_mod; | ||
338 | target_fabric_setup_cits(tf); | ||
339 | |||
340 | tf->tf_subsys = target_core_subsystem[0]; | ||
341 | snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name); | ||
342 | |||
343 | mutex_lock(&g_tf_lock); | ||
344 | list_add_tail(&tf->tf_list, &g_tf_list); | ||
345 | mutex_unlock(&g_tf_lock); | ||
346 | |||
347 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>" | ||
348 | ">>>>>>>>>>>>>>\n"); | ||
349 | pr_debug("Initialized struct target_fabric_configfs: %p for" | ||
350 | " %s\n", tf, tf->tf_name); | ||
351 | return tf; | ||
352 | } | ||
353 | EXPORT_SYMBOL(target_fabric_configfs_init); | ||
354 | |||
355 | /* | ||
356 | * Called by fabric plugins after FAILED target_fabric_configfs_register() call. | ||
357 | */ | ||
358 | void target_fabric_configfs_free( | ||
359 | struct target_fabric_configfs *tf) | ||
360 | { | ||
361 | mutex_lock(&g_tf_lock); | ||
362 | list_del(&tf->tf_list); | ||
363 | mutex_unlock(&g_tf_lock); | ||
364 | |||
365 | kfree(tf); | ||
366 | } | ||
367 | EXPORT_SYMBOL(target_fabric_configfs_free); | ||
368 | |||
369 | /* | ||
370 | * Perform a sanity check of the passed tf->tf_ops before completing | ||
371 | * TCM fabric module registration. | ||
372 | */ | ||
373 | static int target_fabric_tf_ops_check( | ||
374 | struct target_fabric_configfs *tf) | ||
375 | { | ||
376 | struct target_core_fabric_ops *tfo = &tf->tf_ops; | ||
377 | |||
378 | if (!tfo->get_fabric_name) { | 314 | if (!tfo->get_fabric_name) { |
379 | pr_err("Missing tfo->get_fabric_name()\n"); | 315 | pr_err("Missing tfo->get_fabric_name()\n"); |
380 | return -EINVAL; | 316 | return -EINVAL; |
@@ -508,77 +444,59 @@ static int target_fabric_tf_ops_check( | |||
508 | return 0; | 444 | return 0; |
509 | } | 445 | } |
510 | 446 | ||
511 | /* | 447 | int target_register_template(const struct target_core_fabric_ops *fo) |
512 | * Called 2nd from fabric module with returned parameter of | ||
513 | * struct target_fabric_configfs * from target_fabric_configfs_init(). | ||
514 | * | ||
515 | * Upon a successful registration, the new fabric's struct config_item is | ||
516 | * return. Also, a pointer to this struct is set in the passed | ||
517 | * struct target_fabric_configfs. | ||
518 | */ | ||
519 | int target_fabric_configfs_register( | ||
520 | struct target_fabric_configfs *tf) | ||
521 | { | 448 | { |
449 | struct target_fabric_configfs *tf; | ||
522 | int ret; | 450 | int ret; |
523 | 451 | ||
452 | ret = target_fabric_tf_ops_check(fo); | ||
453 | if (ret) | ||
454 | return ret; | ||
455 | |||
456 | tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); | ||
524 | if (!tf) { | 457 | if (!tf) { |
525 | pr_err("Unable to locate target_fabric_configfs" | 458 | pr_err("%s: could not allocate memory!\n", __func__); |
526 | " pointer\n"); | 459 | return -ENOMEM; |
527 | return -EINVAL; | ||
528 | } | ||
529 | if (!tf->tf_subsys) { | ||
530 | pr_err("Unable to target struct config_subsystem" | ||
531 | " pointer\n"); | ||
532 | return -EINVAL; | ||
533 | } | 460 | } |
534 | ret = target_fabric_tf_ops_check(tf); | ||
535 | if (ret < 0) | ||
536 | return ret; | ||
537 | 461 | ||
538 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>" | 462 | INIT_LIST_HEAD(&tf->tf_list); |
539 | ">>>>>>>>>>\n"); | 463 | atomic_set(&tf->tf_access_cnt, 0); |
464 | |||
465 | /* | ||
466 | * Setup the default generic struct config_item_type's (cits) in | ||
467 | * struct target_fabric_configfs->tf_cit_tmpl | ||
468 | */ | ||
469 | tf->tf_module = fo->module; | ||
470 | tf->tf_subsys = target_core_subsystem[0]; | ||
471 | snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", fo->name); | ||
472 | |||
473 | tf->tf_ops = *fo; | ||
474 | target_fabric_setup_cits(tf); | ||
475 | |||
476 | mutex_lock(&g_tf_lock); | ||
477 | list_add_tail(&tf->tf_list, &g_tf_list); | ||
478 | mutex_unlock(&g_tf_lock); | ||
479 | |||
540 | return 0; | 480 | return 0; |
541 | } | 481 | } |
542 | EXPORT_SYMBOL(target_fabric_configfs_register); | 482 | EXPORT_SYMBOL(target_register_template); |
543 | 483 | ||
544 | void target_fabric_configfs_deregister( | 484 | void target_unregister_template(const struct target_core_fabric_ops *fo) |
545 | struct target_fabric_configfs *tf) | ||
546 | { | 485 | { |
547 | struct configfs_subsystem *su; | 486 | struct target_fabric_configfs *t; |
548 | 487 | ||
549 | if (!tf) { | ||
550 | pr_err("Unable to locate passed target_fabric_" | ||
551 | "configfs\n"); | ||
552 | return; | ||
553 | } | ||
554 | su = tf->tf_subsys; | ||
555 | if (!su) { | ||
556 | pr_err("Unable to locate passed tf->tf_subsys" | ||
557 | " pointer\n"); | ||
558 | return; | ||
559 | } | ||
560 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>" | ||
561 | ">>>>>>>>>>>>\n"); | ||
562 | mutex_lock(&g_tf_lock); | 488 | mutex_lock(&g_tf_lock); |
563 | if (atomic_read(&tf->tf_access_cnt)) { | 489 | list_for_each_entry(t, &g_tf_list, tf_list) { |
564 | mutex_unlock(&g_tf_lock); | 490 | if (!strcmp(t->tf_name, fo->name)) { |
565 | pr_err("Non zero tf->tf_access_cnt for fabric %s\n", | 491 | BUG_ON(atomic_read(&t->tf_access_cnt)); |
566 | tf->tf_name); | 492 | list_del(&t->tf_list); |
567 | BUG(); | 493 | kfree(t); |
494 | break; | ||
495 | } | ||
568 | } | 496 | } |
569 | list_del(&tf->tf_list); | ||
570 | mutex_unlock(&g_tf_lock); | 497 | mutex_unlock(&g_tf_lock); |
571 | |||
572 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:" | ||
573 | " %s\n", tf->tf_name); | ||
574 | tf->tf_module = NULL; | ||
575 | tf->tf_subsys = NULL; | ||
576 | kfree(tf); | ||
577 | |||
578 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>" | ||
579 | ">>>>>\n"); | ||
580 | } | 498 | } |
581 | EXPORT_SYMBOL(target_fabric_configfs_deregister); | 499 | EXPORT_SYMBOL(target_unregister_template); |
582 | 500 | ||
583 | /*############################################################################## | 501 | /*############################################################################## |
584 | // Stop functions called by external Target Fabrics Modules | 502 | // Stop functions called by external Target Fabrics Modules |
@@ -945,7 +863,7 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port( | |||
945 | struct se_lun *lun; | 863 | struct se_lun *lun; |
946 | struct se_portal_group *se_tpg; | 864 | struct se_portal_group *se_tpg; |
947 | struct t10_pr_registration *pr_reg; | 865 | struct t10_pr_registration *pr_reg; |
948 | struct target_core_fabric_ops *tfo; | 866 | const struct target_core_fabric_ops *tfo; |
949 | ssize_t len = 0; | 867 | ssize_t len = 0; |
950 | 868 | ||
951 | spin_lock(&dev->dev_reservation_lock); | 869 | spin_lock(&dev->dev_reservation_lock); |
@@ -979,7 +897,7 @@ SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port); | |||
979 | static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( | 897 | static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( |
980 | struct se_device *dev, char *page) | 898 | struct se_device *dev, char *page) |
981 | { | 899 | { |
982 | struct target_core_fabric_ops *tfo; | 900 | const struct target_core_fabric_ops *tfo; |
983 | struct t10_pr_registration *pr_reg; | 901 | struct t10_pr_registration *pr_reg; |
984 | unsigned char buf[384]; | 902 | unsigned char buf[384]; |
985 | char i_buf[PR_REG_ISID_ID_LEN]; | 903 | char i_buf[PR_REG_ISID_ID_LEN]; |
diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c index 0c3f90130b7d..1f7886bb16bf 100644 --- a/drivers/target/target_core_fabric_configfs.c +++ b/drivers/target/target_core_fabric_configfs.c | |||
@@ -56,6 +56,20 @@ static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) | |||
56 | pr_debug("Setup generic %s\n", __stringify(_name)); \ | 56 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
57 | } | 57 | } |
58 | 58 | ||
59 | #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ | ||
60 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ | ||
61 | { \ | ||
62 | struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ | ||
63 | struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ | ||
64 | struct configfs_attribute **attrs = tf->tf_ops.tfc_##_name##_attrs; \ | ||
65 | \ | ||
66 | cit->ct_item_ops = _item_ops; \ | ||
67 | cit->ct_group_ops = _group_ops; \ | ||
68 | cit->ct_attrs = attrs; \ | ||
69 | cit->ct_owner = tf->tf_module; \ | ||
70 | pr_debug("Setup generic %s\n", __stringify(_name)); \ | ||
71 | } | ||
72 | |||
59 | /* Start of tfc_tpg_mappedlun_cit */ | 73 | /* Start of tfc_tpg_mappedlun_cit */ |
60 | 74 | ||
61 | static int target_fabric_mappedlun_link( | 75 | static int target_fabric_mappedlun_link( |
@@ -278,7 +292,7 @@ static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = { | |||
278 | .store_attribute = target_fabric_nacl_attrib_attr_store, | 292 | .store_attribute = target_fabric_nacl_attrib_attr_store, |
279 | }; | 293 | }; |
280 | 294 | ||
281 | TF_CIT_SETUP(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL, NULL); | 295 | TF_CIT_SETUP_DRV(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL); |
282 | 296 | ||
283 | /* End of tfc_tpg_nacl_attrib_cit */ | 297 | /* End of tfc_tpg_nacl_attrib_cit */ |
284 | 298 | ||
@@ -291,7 +305,7 @@ static struct configfs_item_operations target_fabric_nacl_auth_item_ops = { | |||
291 | .store_attribute = target_fabric_nacl_auth_attr_store, | 305 | .store_attribute = target_fabric_nacl_auth_attr_store, |
292 | }; | 306 | }; |
293 | 307 | ||
294 | TF_CIT_SETUP(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL, NULL); | 308 | TF_CIT_SETUP_DRV(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL); |
295 | 309 | ||
296 | /* End of tfc_tpg_nacl_auth_cit */ | 310 | /* End of tfc_tpg_nacl_auth_cit */ |
297 | 311 | ||
@@ -304,7 +318,7 @@ static struct configfs_item_operations target_fabric_nacl_param_item_ops = { | |||
304 | .store_attribute = target_fabric_nacl_param_attr_store, | 318 | .store_attribute = target_fabric_nacl_param_attr_store, |
305 | }; | 319 | }; |
306 | 320 | ||
307 | TF_CIT_SETUP(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL, NULL); | 321 | TF_CIT_SETUP_DRV(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL); |
308 | 322 | ||
309 | /* End of tfc_tpg_nacl_param_cit */ | 323 | /* End of tfc_tpg_nacl_param_cit */ |
310 | 324 | ||
@@ -461,8 +475,8 @@ static struct configfs_group_operations target_fabric_nacl_base_group_ops = { | |||
461 | .drop_item = target_fabric_drop_mappedlun, | 475 | .drop_item = target_fabric_drop_mappedlun, |
462 | }; | 476 | }; |
463 | 477 | ||
464 | TF_CIT_SETUP(tpg_nacl_base, &target_fabric_nacl_base_item_ops, | 478 | TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops, |
465 | &target_fabric_nacl_base_group_ops, NULL); | 479 | &target_fabric_nacl_base_group_ops); |
466 | 480 | ||
467 | /* End of tfc_tpg_nacl_base_cit */ | 481 | /* End of tfc_tpg_nacl_base_cit */ |
468 | 482 | ||
@@ -570,7 +584,7 @@ static struct configfs_item_operations target_fabric_np_base_item_ops = { | |||
570 | .store_attribute = target_fabric_np_base_attr_store, | 584 | .store_attribute = target_fabric_np_base_attr_store, |
571 | }; | 585 | }; |
572 | 586 | ||
573 | TF_CIT_SETUP(tpg_np_base, &target_fabric_np_base_item_ops, NULL, NULL); | 587 | TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL); |
574 | 588 | ||
575 | /* End of tfc_tpg_np_base_cit */ | 589 | /* End of tfc_tpg_np_base_cit */ |
576 | 590 | ||
@@ -966,7 +980,7 @@ static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = { | |||
966 | .store_attribute = target_fabric_tpg_attrib_attr_store, | 980 | .store_attribute = target_fabric_tpg_attrib_attr_store, |
967 | }; | 981 | }; |
968 | 982 | ||
969 | TF_CIT_SETUP(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL, NULL); | 983 | TF_CIT_SETUP_DRV(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL); |
970 | 984 | ||
971 | /* End of tfc_tpg_attrib_cit */ | 985 | /* End of tfc_tpg_attrib_cit */ |
972 | 986 | ||
@@ -979,7 +993,7 @@ static struct configfs_item_operations target_fabric_tpg_auth_item_ops = { | |||
979 | .store_attribute = target_fabric_tpg_auth_attr_store, | 993 | .store_attribute = target_fabric_tpg_auth_attr_store, |
980 | }; | 994 | }; |
981 | 995 | ||
982 | TF_CIT_SETUP(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL, NULL); | 996 | TF_CIT_SETUP_DRV(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL); |
983 | 997 | ||
984 | /* End of tfc_tpg_attrib_cit */ | 998 | /* End of tfc_tpg_attrib_cit */ |
985 | 999 | ||
@@ -992,7 +1006,7 @@ static struct configfs_item_operations target_fabric_tpg_param_item_ops = { | |||
992 | .store_attribute = target_fabric_tpg_param_attr_store, | 1006 | .store_attribute = target_fabric_tpg_param_attr_store, |
993 | }; | 1007 | }; |
994 | 1008 | ||
995 | TF_CIT_SETUP(tpg_param, &target_fabric_tpg_param_item_ops, NULL, NULL); | 1009 | TF_CIT_SETUP_DRV(tpg_param, &target_fabric_tpg_param_item_ops, NULL); |
996 | 1010 | ||
997 | /* End of tfc_tpg_param_cit */ | 1011 | /* End of tfc_tpg_param_cit */ |
998 | 1012 | ||
@@ -1018,7 +1032,7 @@ static struct configfs_item_operations target_fabric_tpg_base_item_ops = { | |||
1018 | .store_attribute = target_fabric_tpg_attr_store, | 1032 | .store_attribute = target_fabric_tpg_attr_store, |
1019 | }; | 1033 | }; |
1020 | 1034 | ||
1021 | TF_CIT_SETUP(tpg_base, &target_fabric_tpg_base_item_ops, NULL, NULL); | 1035 | TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL); |
1022 | 1036 | ||
1023 | /* End of tfc_tpg_base_cit */ | 1037 | /* End of tfc_tpg_base_cit */ |
1024 | 1038 | ||
@@ -1192,7 +1206,7 @@ static struct configfs_item_operations target_fabric_wwn_item_ops = { | |||
1192 | .store_attribute = target_fabric_wwn_attr_store, | 1206 | .store_attribute = target_fabric_wwn_attr_store, |
1193 | }; | 1207 | }; |
1194 | 1208 | ||
1195 | TF_CIT_SETUP(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops, NULL); | 1209 | TF_CIT_SETUP_DRV(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops); |
1196 | 1210 | ||
1197 | /* End of tfc_wwn_cit */ | 1211 | /* End of tfc_wwn_cit */ |
1198 | 1212 | ||
@@ -1206,7 +1220,7 @@ static struct configfs_item_operations target_fabric_discovery_item_ops = { | |||
1206 | .store_attribute = target_fabric_discovery_attr_store, | 1220 | .store_attribute = target_fabric_discovery_attr_store, |
1207 | }; | 1221 | }; |
1208 | 1222 | ||
1209 | TF_CIT_SETUP(discovery, &target_fabric_discovery_item_ops, NULL, NULL); | 1223 | TF_CIT_SETUP_DRV(discovery, &target_fabric_discovery_item_ops, NULL); |
1210 | 1224 | ||
1211 | /* End of tfc_discovery_cit */ | 1225 | /* End of tfc_discovery_cit */ |
1212 | 1226 | ||
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 7436fdaaad12..963a67729b65 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c | |||
@@ -680,7 +680,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration( | |||
680 | struct se_dev_entry *deve_tmp; | 680 | struct se_dev_entry *deve_tmp; |
681 | struct se_node_acl *nacl_tmp; | 681 | struct se_node_acl *nacl_tmp; |
682 | struct se_port *port, *port_tmp; | 682 | struct se_port *port, *port_tmp; |
683 | struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; | 683 | const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; |
684 | struct t10_pr_registration *pr_reg, *pr_reg_atp, *pr_reg_tmp, *pr_reg_tmp_safe; | 684 | struct t10_pr_registration *pr_reg, *pr_reg_atp, *pr_reg_tmp, *pr_reg_tmp_safe; |
685 | int ret; | 685 | int ret; |
686 | /* | 686 | /* |
@@ -979,7 +979,7 @@ int core_scsi3_check_aptpl_registration( | |||
979 | } | 979 | } |
980 | 980 | ||
981 | static void __core_scsi3_dump_registration( | 981 | static void __core_scsi3_dump_registration( |
982 | struct target_core_fabric_ops *tfo, | 982 | const struct target_core_fabric_ops *tfo, |
983 | struct se_device *dev, | 983 | struct se_device *dev, |
984 | struct se_node_acl *nacl, | 984 | struct se_node_acl *nacl, |
985 | struct t10_pr_registration *pr_reg, | 985 | struct t10_pr_registration *pr_reg, |
@@ -1020,7 +1020,7 @@ static void __core_scsi3_add_registration( | |||
1020 | enum register_type register_type, | 1020 | enum register_type register_type, |
1021 | int register_move) | 1021 | int register_move) |
1022 | { | 1022 | { |
1023 | struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; | 1023 | const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; |
1024 | struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; | 1024 | struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; |
1025 | struct t10_reservation *pr_tmpl = &dev->t10_pr; | 1025 | struct t10_reservation *pr_tmpl = &dev->t10_pr; |
1026 | 1026 | ||
@@ -1237,7 +1237,7 @@ static void __core_scsi3_free_registration( | |||
1237 | struct list_head *preempt_and_abort_list, | 1237 | struct list_head *preempt_and_abort_list, |
1238 | int dec_holders) | 1238 | int dec_holders) |
1239 | { | 1239 | { |
1240 | struct target_core_fabric_ops *tfo = | 1240 | const struct target_core_fabric_ops *tfo = |
1241 | pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; | 1241 | pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; |
1242 | struct t10_reservation *pr_tmpl = &dev->t10_pr; | 1242 | struct t10_reservation *pr_tmpl = &dev->t10_pr; |
1243 | char i_buf[PR_REG_ISID_ID_LEN]; | 1243 | char i_buf[PR_REG_ISID_ID_LEN]; |
@@ -1461,7 +1461,7 @@ core_scsi3_decode_spec_i_port( | |||
1461 | struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; | 1461 | struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; |
1462 | LIST_HEAD(tid_dest_list); | 1462 | LIST_HEAD(tid_dest_list); |
1463 | struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; | 1463 | struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; |
1464 | struct target_core_fabric_ops *tmp_tf_ops; | 1464 | const struct target_core_fabric_ops *tmp_tf_ops; |
1465 | unsigned char *buf; | 1465 | unsigned char *buf; |
1466 | unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; | 1466 | unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; |
1467 | char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; | 1467 | char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; |
@@ -2422,7 +2422,7 @@ static void __core_scsi3_complete_pro_release( | |||
2422 | int explicit, | 2422 | int explicit, |
2423 | int unreg) | 2423 | int unreg) |
2424 | { | 2424 | { |
2425 | struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo; | 2425 | const struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo; |
2426 | char i_buf[PR_REG_ISID_ID_LEN]; | 2426 | char i_buf[PR_REG_ISID_ID_LEN]; |
2427 | int pr_res_type = 0, pr_res_scope = 0; | 2427 | int pr_res_type = 0, pr_res_scope = 0; |
2428 | 2428 | ||
@@ -2734,7 +2734,7 @@ static void __core_scsi3_complete_pro_preempt( | |||
2734 | enum preempt_type preempt_type) | 2734 | enum preempt_type preempt_type) |
2735 | { | 2735 | { |
2736 | struct se_node_acl *nacl = pr_reg->pr_reg_nacl; | 2736 | struct se_node_acl *nacl = pr_reg->pr_reg_nacl; |
2737 | struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; | 2737 | const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; |
2738 | char i_buf[PR_REG_ISID_ID_LEN]; | 2738 | char i_buf[PR_REG_ISID_ID_LEN]; |
2739 | 2739 | ||
2740 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); | 2740 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
@@ -3119,7 +3119,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key, | |||
3119 | struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL; | 3119 | struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL; |
3120 | struct se_port *se_port; | 3120 | struct se_port *se_port; |
3121 | struct se_portal_group *se_tpg, *dest_se_tpg = NULL; | 3121 | struct se_portal_group *se_tpg, *dest_se_tpg = NULL; |
3122 | struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops; | 3122 | const struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops; |
3123 | struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; | 3123 | struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; |
3124 | struct t10_reservation *pr_tmpl = &dev->t10_pr; | 3124 | struct t10_reservation *pr_tmpl = &dev->t10_pr; |
3125 | unsigned char *buf; | 3125 | unsigned char *buf; |
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 0696de9553d3..47f064415bf6 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c | |||
@@ -672,7 +672,7 @@ static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg) | |||
672 | } | 672 | } |
673 | 673 | ||
674 | int core_tpg_register( | 674 | int core_tpg_register( |
675 | struct target_core_fabric_ops *tfo, | 675 | const struct target_core_fabric_ops *tfo, |
676 | struct se_wwn *se_wwn, | 676 | struct se_wwn *se_wwn, |
677 | struct se_portal_group *se_tpg, | 677 | struct se_portal_group *se_tpg, |
678 | void *tpg_fabric_ptr, | 678 | void *tpg_fabric_ptr, |
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index b671ebbe1df6..f884198a8511 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -322,7 +322,7 @@ void __transport_register_session( | |||
322 | struct se_session *se_sess, | 322 | struct se_session *se_sess, |
323 | void *fabric_sess_ptr) | 323 | void *fabric_sess_ptr) |
324 | { | 324 | { |
325 | struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo; | 325 | const struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo; |
326 | unsigned char buf[PR_REG_ISID_LEN]; | 326 | unsigned char buf[PR_REG_ISID_LEN]; |
327 | 327 | ||
328 | se_sess->se_tpg = se_tpg; | 328 | se_sess->se_tpg = se_tpg; |
@@ -494,7 +494,7 @@ EXPORT_SYMBOL(transport_free_session); | |||
494 | void transport_deregister_session(struct se_session *se_sess) | 494 | void transport_deregister_session(struct se_session *se_sess) |
495 | { | 495 | { |
496 | struct se_portal_group *se_tpg = se_sess->se_tpg; | 496 | struct se_portal_group *se_tpg = se_sess->se_tpg; |
497 | struct target_core_fabric_ops *se_tfo; | 497 | const struct target_core_fabric_ops *se_tfo; |
498 | struct se_node_acl *se_nacl; | 498 | struct se_node_acl *se_nacl; |
499 | unsigned long flags; | 499 | unsigned long flags; |
500 | bool comp_nacl = true; | 500 | bool comp_nacl = true; |
@@ -1150,7 +1150,7 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size) | |||
1150 | */ | 1150 | */ |
1151 | void transport_init_se_cmd( | 1151 | void transport_init_se_cmd( |
1152 | struct se_cmd *cmd, | 1152 | struct se_cmd *cmd, |
1153 | struct target_core_fabric_ops *tfo, | 1153 | const struct target_core_fabric_ops *tfo, |
1154 | struct se_session *se_sess, | 1154 | struct se_session *se_sess, |
1155 | u32 data_length, | 1155 | u32 data_length, |
1156 | int data_direction, | 1156 | int data_direction, |
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 8585acba6fc9..a600ff15dcfd 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c | |||
@@ -425,7 +425,7 @@ static int xcopy_pt_queue_status(struct se_cmd *se_cmd) | |||
425 | return 0; | 425 | return 0; |
426 | } | 426 | } |
427 | 427 | ||
428 | static struct target_core_fabric_ops xcopy_pt_tfo = { | 428 | static const struct target_core_fabric_ops xcopy_pt_tfo = { |
429 | .get_fabric_name = xcopy_pt_get_fabric_name, | 429 | .get_fabric_name = xcopy_pt_get_fabric_name, |
430 | .get_task_tag = xcopy_pt_get_tag, | 430 | .get_task_tag = xcopy_pt_get_tag, |
431 | .get_cmd_state = xcopy_pt_get_cmd_state, | 431 | .get_cmd_state = xcopy_pt_get_cmd_state, |
diff --git a/drivers/target/tcm_fc/tcm_fc.h b/drivers/target/tcm_fc/tcm_fc.h index a0bcfd3e7e7d..881deb3d499a 100644 --- a/drivers/target/tcm_fc/tcm_fc.h +++ b/drivers/target/tcm_fc/tcm_fc.h | |||
@@ -129,7 +129,6 @@ struct ft_cmd { | |||
129 | 129 | ||
130 | extern struct mutex ft_lport_lock; | 130 | extern struct mutex ft_lport_lock; |
131 | extern struct fc4_prov ft_prov; | 131 | extern struct fc4_prov ft_prov; |
132 | extern struct target_fabric_configfs *ft_configfs; | ||
133 | extern unsigned int ft_debug_logging; | 132 | extern unsigned int ft_debug_logging; |
134 | 133 | ||
135 | /* | 134 | /* |
diff --git a/drivers/target/tcm_fc/tfc_conf.c b/drivers/target/tcm_fc/tfc_conf.c index efdcb9663a1a..65dce1345966 100644 --- a/drivers/target/tcm_fc/tfc_conf.c +++ b/drivers/target/tcm_fc/tfc_conf.c | |||
@@ -48,7 +48,7 @@ | |||
48 | 48 | ||
49 | #include "tcm_fc.h" | 49 | #include "tcm_fc.h" |
50 | 50 | ||
51 | struct target_fabric_configfs *ft_configfs; | 51 | static const struct target_core_fabric_ops ft_fabric_ops; |
52 | 52 | ||
53 | static LIST_HEAD(ft_wwn_list); | 53 | static LIST_HEAD(ft_wwn_list); |
54 | DEFINE_MUTEX(ft_lport_lock); | 54 | DEFINE_MUTEX(ft_lport_lock); |
@@ -337,7 +337,7 @@ static struct se_portal_group *ft_add_tpg( | |||
337 | return NULL; | 337 | return NULL; |
338 | } | 338 | } |
339 | 339 | ||
340 | ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg, | 340 | ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg, |
341 | tpg, TRANSPORT_TPG_TYPE_NORMAL); | 341 | tpg, TRANSPORT_TPG_TYPE_NORMAL); |
342 | if (ret < 0) { | 342 | if (ret < 0) { |
343 | destroy_workqueue(wq); | 343 | destroy_workqueue(wq); |
@@ -507,7 +507,9 @@ static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg) | |||
507 | return tpg->index; | 507 | return tpg->index; |
508 | } | 508 | } |
509 | 509 | ||
510 | static struct target_core_fabric_ops ft_fabric_ops = { | 510 | static const struct target_core_fabric_ops ft_fabric_ops = { |
511 | .module = THIS_MODULE, | ||
512 | .name = "fc", | ||
511 | .get_fabric_name = ft_get_fabric_name, | 513 | .get_fabric_name = ft_get_fabric_name, |
512 | .get_fabric_proto_ident = fc_get_fabric_proto_ident, | 514 | .get_fabric_proto_ident = fc_get_fabric_proto_ident, |
513 | .tpg_get_wwn = ft_get_fabric_wwn, | 515 | .tpg_get_wwn = ft_get_fabric_wwn, |
@@ -552,62 +554,10 @@ static struct target_core_fabric_ops ft_fabric_ops = { | |||
552 | .fabric_drop_np = NULL, | 554 | .fabric_drop_np = NULL, |
553 | .fabric_make_nodeacl = &ft_add_acl, | 555 | .fabric_make_nodeacl = &ft_add_acl, |
554 | .fabric_drop_nodeacl = &ft_del_acl, | 556 | .fabric_drop_nodeacl = &ft_del_acl, |
555 | }; | ||
556 | |||
557 | static int ft_register_configfs(void) | ||
558 | { | ||
559 | struct target_fabric_configfs *fabric; | ||
560 | int ret; | ||
561 | |||
562 | /* | ||
563 | * Register the top level struct config_item_type with TCM core | ||
564 | */ | ||
565 | fabric = target_fabric_configfs_init(THIS_MODULE, "fc"); | ||
566 | if (IS_ERR(fabric)) { | ||
567 | pr_err("%s: target_fabric_configfs_init() failed!\n", | ||
568 | __func__); | ||
569 | return PTR_ERR(fabric); | ||
570 | } | ||
571 | fabric->tf_ops = ft_fabric_ops; | ||
572 | |||
573 | /* | ||
574 | * Setup default attribute lists for various fabric->tf_cit_tmpl | ||
575 | */ | ||
576 | fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = ft_wwn_attrs; | ||
577 | fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL; | ||
578 | fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; | ||
579 | fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; | ||
580 | fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; | ||
581 | fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = | ||
582 | ft_nacl_base_attrs; | ||
583 | fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; | ||
584 | fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL; | ||
585 | fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL; | ||
586 | /* | ||
587 | * register the fabric for use within TCM | ||
588 | */ | ||
589 | ret = target_fabric_configfs_register(fabric); | ||
590 | if (ret < 0) { | ||
591 | pr_debug("target_fabric_configfs_register() for" | ||
592 | " FC Target failed!\n"); | ||
593 | target_fabric_configfs_free(fabric); | ||
594 | return -1; | ||
595 | } | ||
596 | |||
597 | /* | ||
598 | * Setup our local pointer to *fabric. | ||
599 | */ | ||
600 | ft_configfs = fabric; | ||
601 | return 0; | ||
602 | } | ||
603 | 557 | ||
604 | static void ft_deregister_configfs(void) | 558 | .tfc_wwn_attrs = ft_wwn_attrs, |
605 | { | 559 | .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs, |
606 | if (!ft_configfs) | 560 | }; |
607 | return; | ||
608 | target_fabric_configfs_deregister(ft_configfs); | ||
609 | ft_configfs = NULL; | ||
610 | } | ||
611 | 561 | ||
612 | static struct notifier_block ft_notifier = { | 562 | static struct notifier_block ft_notifier = { |
613 | .notifier_call = ft_lport_notify | 563 | .notifier_call = ft_lport_notify |
@@ -615,15 +565,24 @@ static struct notifier_block ft_notifier = { | |||
615 | 565 | ||
616 | static int __init ft_init(void) | 566 | static int __init ft_init(void) |
617 | { | 567 | { |
618 | if (ft_register_configfs()) | 568 | int ret; |
619 | return -1; | 569 | |
620 | if (fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov)) { | 570 | ret = target_register_template(&ft_fabric_ops); |
621 | ft_deregister_configfs(); | 571 | if (ret) |
622 | return -1; | 572 | goto out; |
623 | } | 573 | |
574 | ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov); | ||
575 | if (ret) | ||
576 | goto out_unregister_template; | ||
577 | |||
624 | blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier); | 578 | blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier); |
625 | fc_lport_iterate(ft_lport_add, NULL); | 579 | fc_lport_iterate(ft_lport_add, NULL); |
626 | return 0; | 580 | return 0; |
581 | |||
582 | out_unregister_template: | ||
583 | target_unregister_template(&ft_fabric_ops); | ||
584 | out: | ||
585 | return ret; | ||
627 | } | 586 | } |
628 | 587 | ||
629 | static void __exit ft_exit(void) | 588 | static void __exit ft_exit(void) |
@@ -632,7 +591,7 @@ static void __exit ft_exit(void) | |||
632 | &ft_notifier); | 591 | &ft_notifier); |
633 | fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov); | 592 | fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov); |
634 | fc_lport_iterate(ft_lport_del, NULL); | 593 | fc_lport_iterate(ft_lport_del, NULL); |
635 | ft_deregister_configfs(); | 594 | target_unregister_template(&ft_fabric_ops); |
636 | synchronize_rcu(); | 595 | synchronize_rcu(); |
637 | } | 596 | } |
638 | 597 | ||