target: Add se_sess->sess_kref + get/put helpers
authorNicholas Bellinger <nab@linux-iscsi.org>
Mon, 27 Feb 2012 06:22:10 +0000 (22:22 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Sat, 10 Mar 2012 22:41:53 +0000 (14:41 -0800)
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>
drivers/target/target_core_transport.c
include/target/target_core_base.h
include/target/target_core_fabric.h

index d931edf11c2b231f2a0939ed4d9dc959ef36ce57..7badc87e4bbecef437f38544a1c88f903d4331bd 100644 (file)
@@ -246,6 +246,7 @@ struct se_session *transport_init_session(void)
        INIT_LIST_HEAD(&se_sess->sess_cmd_list);
        INIT_LIST_HEAD(&se_sess->sess_wait_list);
        spin_lock_init(&se_sess->sess_cmd_lock);
+       kref_init(&se_sess->sess_kref);
 
        return se_sess;
 }
@@ -313,6 +314,27 @@ void transport_register_session(
 }
 EXPORT_SYMBOL(transport_register_session);
 
+static void target_release_session(struct kref *kref)
+{
+       struct se_session *se_sess = container_of(kref,
+                       struct se_session, sess_kref);
+       struct se_portal_group *se_tpg = se_sess->se_tpg;
+
+       se_tpg->se_tpg_tfo->close_session(se_sess);
+}
+
+void target_get_session(struct se_session *se_sess)
+{
+       kref_get(&se_sess->sess_kref);
+}
+EXPORT_SYMBOL(target_get_session);
+
+int target_put_session(struct se_session *se_sess)
+{
+       return kref_put(&se_sess->sess_kref, target_release_session);
+}
+EXPORT_SYMBOL(target_put_session);
+
 void transport_deregister_session_configfs(struct se_session *se_sess)
 {
        struct se_node_acl *se_nacl;
index 1641dea0c282cb6795518752cf3dcd9313ff7539..d63079409eff44306db9bb8c8bc86e93c8a88d6f 100644 (file)
@@ -654,6 +654,7 @@ struct se_session {
        struct list_head        sess_cmd_list;
        struct list_head        sess_wait_list;
        spinlock_t              sess_cmd_lock;
+       struct kref             sess_kref;
 };
 
 struct se_device;
index e5d8c47892b7975069d3918bdaf27ace65290714..7e76aa16700996a980744d5b772901b157d38d3b 100644 (file)
@@ -105,6 +105,8 @@ void        __transport_register_session(struct se_portal_group *,
                struct se_node_acl *, struct se_session *, void *);
 void   transport_register_session(struct se_portal_group *,
                struct se_node_acl *, struct se_session *, void *);
+void   target_get_session(struct se_session *);
+int    target_put_session(struct se_session *);
 void   transport_free_session(struct se_session *);
 void   transport_deregister_session_configfs(struct se_session *);
 void   transport_deregister_session(struct se_session *);