From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755272AbcAMIPY (ORCPT ); Wed, 13 Jan 2016 03:15:24 -0500 Received: from verein.lst.de ([213.95.11.211]:41557 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753718AbcAMIPW (ORCPT ); Wed, 13 Jan 2016 03:15:22 -0500 Date: Wed, 13 Jan 2016 09:15:18 +0100 From: Christoph Hellwig To: "Nicholas A. Bellinger" Cc: Christoph Hellwig , "Nicholas A. Bellinger" , target-devel , linux-scsi , lkml , Sagi Grimberg , Hannes Reinecke , Andy Grover , Vasu Dev , Vu Pham Subject: Re: [PATCH-v2 4/4] target: Obtain se_node_acl->acl_kref during get_initiator_node_acl Message-ID: <20160113081518.GA12642@lst.de> References: <1452457724-10629-1-git-send-email-nab@daterainc.com> <1452457724-10629-5-git-send-email-nab@daterainc.com> <20160112150941.GC2058@lst.de> <1452672028.27508.40.camel@haakon3.risingtidesystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452672028.27508.40.camel@haakon3.risingtidesystems.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 13, 2016 at 12:00:28AM -0800, Nicholas A. Bellinger wrote: > diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c > index 52ae8ba..62f02ea 100644 > --- a/drivers/target/target_core_tpg.c > +++ b/drivers/target/target_core_tpg.c > @@ -75,16 +75,9 @@ struct se_node_acl *core_tpg_get_initiator_node_acl( > unsigned char *initiatorname) > { > struct se_node_acl *acl; > - /* > - * Obtain the acl_kref now, which will be dropped upon the > - * release of se_sess memory within transport_free_session(). > - */ > + > mutex_lock(&tpg->acl_node_mutex); > acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname); > - if (acl) { > - if (!kref_get_unless_zero(&acl->acl_kref)) > - acl = NULL; > - } nah, please keep the kref_get_unless_zero here, it's needed. It's just the misleding comment I was complaining about :) > @@ -3435,10 +3436,14 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, > > if ((tpg->tpg_attrib.generate_node_acls == 0) && > (tpg->tpg_attrib.demo_mode_discovery == 0) && > - (!core_tpg_get_initiator_node_acl(&tpg->tpg_se_tpg, > - cmd->conn->sess->sess_ops->InitiatorName))) { > + (!(se_acl = core_tpg_get_initiator_node_acl(&tpg->tpg_se_tpg, > + cmd->conn->sess->sess_ops->InitiatorName)))) { > continue; > } > + if (se_acl) { > + target_put_nacl(se_acl); > + se_acl = NULL; > + } Seems like with the current code we don't need to keep the ACL, so a new helper like: bool target_tpg_has_node_acl(struct se_portal_group *tpg, const char *initiatorname) { struct se_node_acl *acl; acl = core_tpg_get_initiator_node_acl(tpg, initiatorname); if (acl) { target_put_nacl(se_acl); return true; } return false; } or fully open coded as: bool target_tpg_has_node_acl(struct se_portal_group *tpg, const char *initiatorname) { struct se_node_acl *acl; bool found = false; mutex_lock(&tpg->acl_node_mutex); list_for_each_entry(acl, &tpg->acl_node_list, acl_list) { if (!strcmp(acl->initiatorname, initiatorname)) { found = true; break; } } mutex_unlock(&tpg->acl_node_mutex); return found; } might be better to keep the code readable.