target: Add se_node_acl->acl_kref for ->acl_free_comp usage
Nicholas Bellinger [Fri, 9 Mar 2012 07:45:02 +0000 (23:45 -0800)]
This patch adds se_node_acl->acl_kref for use with ->acl_free_comp
during explict se_node_acl release.  It adds kref_init() during
se_node_acl setup, kref_get() during __transport_register_session()
-> target_put_nacl() with existing transport_deregister_session()
fabric callback usage.

It also moves transport_free_session() to release *se_sess memory
after target_put_nacl() execution in transport_deregister_session()

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_tpg.c
drivers/target/target_core_transport.c
include/target/target_core_base.h
include/target/target_core_fabric.h

index 9cdfd06..bbed260 100644 (file)
@@ -274,6 +274,7 @@ struct se_node_acl *core_tpg_check_initiator_node_acl(
 
        INIT_LIST_HEAD(&acl->acl_list);
        INIT_LIST_HEAD(&acl->acl_sess_list);
+       kref_init(&acl->acl_kref);
        init_completion(&acl->acl_free_comp);
        spin_lock_init(&acl->device_list_lock);
        spin_lock_init(&acl->nacl_sess_lock);
@@ -403,6 +404,7 @@ struct se_node_acl *core_tpg_add_initiator_node_acl(
 
        INIT_LIST_HEAD(&acl->acl_list);
        INIT_LIST_HEAD(&acl->acl_sess_list);
+       kref_init(&acl->acl_kref);
        init_completion(&acl->acl_free_comp);
        spin_lock_init(&acl->device_list_lock);
        spin_lock_init(&acl->nacl_sess_lock);
index 9e61abc..efefbec 100644 (file)
@@ -282,6 +282,8 @@ void __transport_register_session(
                                        &buf[0], PR_REG_ISID_LEN);
                        se_sess->sess_bin_isid = get_unaligned_be64(&buf[0]);
                }
+               kref_get(&se_nacl->acl_kref);
+
                spin_lock_irq(&se_nacl->nacl_sess_lock);
                /*
                 * The se_nacl->nacl_sess pointer will be set to the
@@ -335,6 +337,19 @@ int target_put_session(struct se_session *se_sess)
 }
 EXPORT_SYMBOL(target_put_session);
 
+static void target_complete_nacl(struct kref *kref)
+{
+       struct se_node_acl *nacl = container_of(kref,
+                               struct se_node_acl, acl_kref);
+
+       complete(&nacl->acl_free_comp);
+}
+
+void target_put_nacl(struct se_node_acl *nacl)
+{
+       kref_put(&nacl->acl_kref, target_complete_nacl);
+}
+
 void transport_deregister_session_configfs(struct se_session *se_sess)
 {
        struct se_node_acl *se_nacl;
@@ -411,17 +426,17 @@ void transport_deregister_session(struct se_session *se_sess)
        }
        spin_unlock_irqrestore(&se_tpg->acl_node_lock, flags);
 
-       transport_free_session(se_sess);
-
        pr_debug("TARGET_CORE[%s]: Deregistered fabric_sess\n",
                se_tpg->se_tpg_tfo->get_fabric_name());
        /*
-        * Awake sleeping ->acl_free_comp caller from configfs se_node_acl
-        * removal context
+        * If last kref is dropping now for an explict NodeACL, awake sleeping
+        * ->acl_free_comp caller to wakeup configfs se_node_acl->acl_group
+        * removal context.
         */
        if (se_nacl && comp_nacl == true)
-               complete(&se_nacl->acl_free_comp);
+               target_put_nacl(se_nacl);
 
+       transport_free_session(se_sess);
 }
 EXPORT_SYMBOL(transport_deregister_session);
 
index f8aa300..2cda563 100644 (file)
@@ -642,6 +642,7 @@ struct se_node_acl {
        struct list_head        acl_list;
        struct list_head        acl_sess_list;
        struct completion       acl_free_comp;
+       struct kref             acl_kref;
 };
 
 struct se_session {
index 7e76aa1..032c487 100644 (file)
@@ -108,6 +108,7 @@ void        transport_register_session(struct se_portal_group *,
 void   target_get_session(struct se_session *);
 int    target_put_session(struct se_session *);
 void   transport_free_session(struct se_session *);
+void   target_put_nacl(struct se_node_acl *);
 void   transport_deregister_session_configfs(struct se_session *);
 void   transport_deregister_session(struct se_session *);