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 /include/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 'include/target')
-rw-r--r-- | include/target/target_core_base.h | 4 | ||||
-rw-r--r-- | include/target/target_core_configfs.h | 6 | ||||
-rw-r--r-- | include/target/target_core_fabric.h | 24 |
3 files changed, 23 insertions, 11 deletions
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 71699cf3cc71..383110d608a0 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h | |||
@@ -519,7 +519,7 @@ struct se_cmd { | |||
519 | struct list_head se_cmd_list; | 519 | struct list_head se_cmd_list; |
520 | struct completion cmd_wait_comp; | 520 | struct completion cmd_wait_comp; |
521 | struct kref cmd_kref; | 521 | struct kref cmd_kref; |
522 | struct target_core_fabric_ops *se_tfo; | 522 | const struct target_core_fabric_ops *se_tfo; |
523 | sense_reason_t (*execute_cmd)(struct se_cmd *); | 523 | sense_reason_t (*execute_cmd)(struct se_cmd *); |
524 | sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *, | 524 | sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *, |
525 | u32, enum dma_data_direction); | 525 | u32, enum dma_data_direction); |
@@ -890,7 +890,7 @@ struct se_portal_group { | |||
890 | /* List of TCM sessions associated wth this TPG */ | 890 | /* List of TCM sessions associated wth this TPG */ |
891 | struct list_head tpg_sess_list; | 891 | struct list_head tpg_sess_list; |
892 | /* Pointer to $FABRIC_MOD dependent code */ | 892 | /* Pointer to $FABRIC_MOD dependent code */ |
893 | struct target_core_fabric_ops *se_tpg_tfo; | 893 | const struct target_core_fabric_ops *se_tpg_tfo; |
894 | struct se_wwn *se_tpg_wwn; | 894 | struct se_wwn *se_tpg_wwn; |
895 | struct config_group tpg_group; | 895 | struct config_group tpg_group; |
896 | struct config_group *tpg_default_groups[7]; | 896 | struct config_group *tpg_default_groups[7]; |
diff --git a/include/target/target_core_configfs.h b/include/target/target_core_configfs.h index e0801386e4dc..25bb04c4209e 100644 --- a/include/target/target_core_configfs.h +++ b/include/target/target_core_configfs.h | |||
@@ -5,12 +5,6 @@ | |||
5 | #define TARGET_CORE_NAME_MAX_LEN 64 | 5 | #define TARGET_CORE_NAME_MAX_LEN 64 |
6 | #define TARGET_FABRIC_NAME_SIZE 32 | 6 | #define TARGET_FABRIC_NAME_SIZE 32 |
7 | 7 | ||
8 | extern struct target_fabric_configfs *target_fabric_configfs_init( | ||
9 | struct module *, const char *); | ||
10 | extern void target_fabric_configfs_free(struct target_fabric_configfs *); | ||
11 | extern int target_fabric_configfs_register(struct target_fabric_configfs *); | ||
12 | extern void target_fabric_configfs_deregister(struct target_fabric_configfs *); | ||
13 | |||
14 | struct target_fabric_configfs_template { | 8 | struct target_fabric_configfs_template { |
15 | struct config_item_type tfc_discovery_cit; | 9 | struct config_item_type tfc_discovery_cit; |
16 | struct config_item_type tfc_wwn_cit; | 10 | struct config_item_type tfc_wwn_cit; |
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index c93cfdf0d8e5..17c7f5ac7ea0 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h | |||
@@ -2,6 +2,8 @@ | |||
2 | #define TARGET_CORE_FABRIC_H | 2 | #define TARGET_CORE_FABRIC_H |
3 | 3 | ||
4 | struct target_core_fabric_ops { | 4 | struct target_core_fabric_ops { |
5 | struct module *module; | ||
6 | const char *name; | ||
5 | struct configfs_subsystem *tf_subsys; | 7 | struct configfs_subsystem *tf_subsys; |
6 | char *(*get_fabric_name)(void); | 8 | char *(*get_fabric_name)(void); |
7 | u8 (*get_fabric_proto_ident)(struct se_portal_group *); | 9 | u8 (*get_fabric_proto_ident)(struct se_portal_group *); |
@@ -90,8 +92,23 @@ struct target_core_fabric_ops { | |||
90 | struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *, | 92 | struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *, |
91 | struct config_group *, const char *); | 93 | struct config_group *, const char *); |
92 | void (*fabric_drop_nodeacl)(struct se_node_acl *); | 94 | void (*fabric_drop_nodeacl)(struct se_node_acl *); |
95 | |||
96 | struct configfs_attribute **tfc_discovery_attrs; | ||
97 | struct configfs_attribute **tfc_wwn_attrs; | ||
98 | struct configfs_attribute **tfc_tpg_base_attrs; | ||
99 | struct configfs_attribute **tfc_tpg_np_base_attrs; | ||
100 | struct configfs_attribute **tfc_tpg_attrib_attrs; | ||
101 | struct configfs_attribute **tfc_tpg_auth_attrs; | ||
102 | struct configfs_attribute **tfc_tpg_param_attrs; | ||
103 | struct configfs_attribute **tfc_tpg_nacl_base_attrs; | ||
104 | struct configfs_attribute **tfc_tpg_nacl_attrib_attrs; | ||
105 | struct configfs_attribute **tfc_tpg_nacl_auth_attrs; | ||
106 | struct configfs_attribute **tfc_tpg_nacl_param_attrs; | ||
93 | }; | 107 | }; |
94 | 108 | ||
109 | int target_register_template(const struct target_core_fabric_ops *fo); | ||
110 | void target_unregister_template(const struct target_core_fabric_ops *fo); | ||
111 | |||
95 | struct se_session *transport_init_session(enum target_prot_op); | 112 | struct se_session *transport_init_session(enum target_prot_op); |
96 | int transport_alloc_session_tags(struct se_session *, unsigned int, | 113 | int transport_alloc_session_tags(struct se_session *, unsigned int, |
97 | unsigned int); | 114 | unsigned int); |
@@ -110,7 +127,8 @@ void transport_deregister_session_configfs(struct se_session *); | |||
110 | void transport_deregister_session(struct se_session *); | 127 | void transport_deregister_session(struct se_session *); |
111 | 128 | ||
112 | 129 | ||
113 | void transport_init_se_cmd(struct se_cmd *, struct target_core_fabric_ops *, | 130 | void transport_init_se_cmd(struct se_cmd *, |
131 | const struct target_core_fabric_ops *, | ||
114 | struct se_session *, u32, int, int, unsigned char *); | 132 | struct se_session *, u32, int, int, unsigned char *); |
115 | sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32); | 133 | sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32); |
116 | sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); | 134 | sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); |
@@ -162,8 +180,8 @@ int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *, | |||
162 | unsigned char *, u32, int); | 180 | unsigned char *, u32, int); |
163 | int core_tpg_set_initiator_node_tag(struct se_portal_group *, | 181 | int core_tpg_set_initiator_node_tag(struct se_portal_group *, |
164 | struct se_node_acl *, const char *); | 182 | struct se_node_acl *, const char *); |
165 | int core_tpg_register(struct target_core_fabric_ops *, struct se_wwn *, | 183 | int core_tpg_register(const struct target_core_fabric_ops *, |
166 | struct se_portal_group *, void *, int); | 184 | struct se_wwn *, struct se_portal_group *, void *, int); |
167 | int core_tpg_deregister(struct se_portal_group *); | 185 | int core_tpg_deregister(struct se_portal_group *); |
168 | 186 | ||
169 | /* SAS helpers */ | 187 | /* SAS helpers */ |