diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-02-27 01:22:10 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-03-10 17:41:53 -0500 |
commit | 41ac82b668177876d5965d5f60956fb0fbcdb514 (patch) | |
tree | 229c299330fa9c3cb4cb5a1903e0559e3e7a5d5b | |
parent | 140854cb72525246745b67300d35101ad2875a39 (diff) |
target: Add se_sess->sess_kref + get/put helpers
This patch adds basic se_session->sess_kref and get/put helpers for fabric
session reference counting. It sets the initial kref in transport_init_session()
and adds a target_release_session() callback to invoke TFO->close_session()
for final session shutdown.
Cc: Roland Dreier <roland@purestorage.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Joern Engel <joern@logfs.org>
Cc: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r-- | drivers/target/target_core_transport.c | 22 | ||||
-rw-r--r-- | include/target/target_core_base.h | 1 | ||||
-rw-r--r-- | include/target/target_core_fabric.h | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index d931edf11c2b..7badc87e4bbe 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -246,6 +246,7 @@ struct se_session *transport_init_session(void) | |||
246 | INIT_LIST_HEAD(&se_sess->sess_cmd_list); | 246 | INIT_LIST_HEAD(&se_sess->sess_cmd_list); |
247 | INIT_LIST_HEAD(&se_sess->sess_wait_list); | 247 | INIT_LIST_HEAD(&se_sess->sess_wait_list); |
248 | spin_lock_init(&se_sess->sess_cmd_lock); | 248 | spin_lock_init(&se_sess->sess_cmd_lock); |
249 | kref_init(&se_sess->sess_kref); | ||
249 | 250 | ||
250 | return se_sess; | 251 | return se_sess; |
251 | } | 252 | } |
@@ -313,6 +314,27 @@ void transport_register_session( | |||
313 | } | 314 | } |
314 | EXPORT_SYMBOL(transport_register_session); | 315 | EXPORT_SYMBOL(transport_register_session); |
315 | 316 | ||
317 | static void target_release_session(struct kref *kref) | ||
318 | { | ||
319 | struct se_session *se_sess = container_of(kref, | ||
320 | struct se_session, sess_kref); | ||
321 | struct se_portal_group *se_tpg = se_sess->se_tpg; | ||
322 | |||
323 | se_tpg->se_tpg_tfo->close_session(se_sess); | ||
324 | } | ||
325 | |||
326 | void target_get_session(struct se_session *se_sess) | ||
327 | { | ||
328 | kref_get(&se_sess->sess_kref); | ||
329 | } | ||
330 | EXPORT_SYMBOL(target_get_session); | ||
331 | |||
332 | int target_put_session(struct se_session *se_sess) | ||
333 | { | ||
334 | return kref_put(&se_sess->sess_kref, target_release_session); | ||
335 | } | ||
336 | EXPORT_SYMBOL(target_put_session); | ||
337 | |||
316 | void transport_deregister_session_configfs(struct se_session *se_sess) | 338 | void transport_deregister_session_configfs(struct se_session *se_sess) |
317 | { | 339 | { |
318 | struct se_node_acl *se_nacl; | 340 | struct se_node_acl *se_nacl; |
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 1641dea0c282..d63079409eff 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h | |||
@@ -654,6 +654,7 @@ struct se_session { | |||
654 | struct list_head sess_cmd_list; | 654 | struct list_head sess_cmd_list; |
655 | struct list_head sess_wait_list; | 655 | struct list_head sess_wait_list; |
656 | spinlock_t sess_cmd_lock; | 656 | spinlock_t sess_cmd_lock; |
657 | struct kref sess_kref; | ||
657 | }; | 658 | }; |
658 | 659 | ||
659 | struct se_device; | 660 | struct se_device; |
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index e5d8c47892b7..7e76aa167009 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h | |||
@@ -105,6 +105,8 @@ void __transport_register_session(struct se_portal_group *, | |||
105 | struct se_node_acl *, struct se_session *, void *); | 105 | struct se_node_acl *, struct se_session *, void *); |
106 | void transport_register_session(struct se_portal_group *, | 106 | void transport_register_session(struct se_portal_group *, |
107 | struct se_node_acl *, struct se_session *, void *); | 107 | struct se_node_acl *, struct se_session *, void *); |
108 | void target_get_session(struct se_session *); | ||
109 | int target_put_session(struct se_session *); | ||
108 | void transport_free_session(struct se_session *); | 110 | void transport_free_session(struct se_session *); |
109 | void transport_deregister_session_configfs(struct se_session *); | 111 | void transport_deregister_session_configfs(struct se_session *); |
110 | void transport_deregister_session(struct se_session *); | 112 | void transport_deregister_session(struct se_session *); |