From patchwork Wed Dec 13 23:50:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10111187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B212602A7 for ; Wed, 13 Dec 2017 23:50:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E32B295AB for ; Wed, 13 Dec 2017 23:50:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4317529755; Wed, 13 Dec 2017 23:50:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE64D295AB for ; Wed, 13 Dec 2017 23:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751152AbdLMXui (ORCPT ); Wed, 13 Dec 2017 18:50:38 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:50508 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbdLMXuf (ORCPT ); Wed, 13 Dec 2017 18:50:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1513209036; x=1544745036; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vSRNxQ19UBoUDndm9M1ERz4B+P9UaoUs+PWJtBn55xM=; b=qHDS43ZL+xU9A2KDmbJeAd5w5X4rWS1ZCEhztPn/9N9ryJjESC+qDBoF a23Ix2szm9kIL/nP29vhaFcfXWwyzBiTZL4IlNBb5lmGPnnIRkOvtZ0Cw JYQZZ6cAOAnKY0LGLbuedpNLlOOjlFYRTtPBnqtWETY9NTutVl08dS32C yEHZvWpQgiqVmwztCgTUNNCmce9dGbyZRLfImB1rDtUHAZ7c/lSUHEFtl HSS/BMBtigNWDeABk1LshVAd93nVWy1KkatIxacJExFu7m5+F7sNCLHrY rRkoxS82wrJo8NEuWU0tod9K6z45ED6Wre1PzxmGPKj7so+8XBTUV0JTd g==; X-IronPort-AV: E=Sophos;i="5.45,398,1508774400"; d="scan'208";a="65384156" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Dec 2017 07:50:32 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 13 Dec 2017 15:46:56 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.166.51]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2017 15:50:33 -0800 From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Nicholas Bellinger , Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Mike Christie Subject: [PATCH 10/11] target: Simplify the code for waiting for command completion Date: Wed, 13 Dec 2017 15:50:28 -0800 Message-Id: <20171213235029.581-11-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171213235029.581-1-bart.vanassche@wdc.com> References: <20171213235029.581-1-bart.vanassche@wdc.com> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of embedding the completion that is used for waiting for command completion in struct se_cmd, let the context that waits for command completion allocate it. This makes it possible to have a single code path for non-aborted and aborted commands in target_release_cmd_kref() and avoids that transport_generic_free_cmd() has to call cmd->se_tfo->release_cmd() directly. This patch does not change any functionality. Note: transport_generic_free_cmd() only waits until the se_cmd reference count has reached zero after it has set both CMD_T_FABRIC_STOP and CMD_T_ABORTED. Signed-off-by: Bart Van Assche Cc: Nicholas Bellinger Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Mike Christie --- drivers/target/target_core_transport.c | 24 ++++++++---------------- include/target/target_core_base.h | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7bf2248e9664..eecc98b763a6 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1276,7 +1276,7 @@ void transport_init_se_cmd( INIT_LIST_HEAD(&cmd->se_cmd_list); INIT_LIST_HEAD(&cmd->state_list); init_completion(&cmd->t_transport_stop_comp); - init_completion(&cmd->cmd_wait_comp); + cmd->compl = NULL; spin_lock_init(&cmd->t_state_lock); INIT_WORK(&cmd->work, NULL); kref_init(&cmd->cmd_kref); @@ -2631,6 +2631,7 @@ static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) */ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) { + DECLARE_COMPLETION_ONSTACK(compl); int ret = 0; bool aborted = false, tas = false; @@ -2649,12 +2650,13 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) if (cmd->se_lun) transport_lun_remove_cmd(cmd); } + if (aborted) + cmd->compl = &compl; if (!aborted || tas) ret = target_put_sess_cmd(cmd); if (aborted) { pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); - wait_for_completion(&cmd->cmd_wait_comp); - cmd->se_tfo->release_cmd(cmd); + wait_for_completion(&compl); ret = 1; } return ret; @@ -2714,8 +2716,8 @@ static void target_release_cmd_kref(struct kref *kref) { struct se_cmd *se_cmd = container_of(kref, struct se_cmd, cmd_kref); struct se_session *se_sess = se_cmd->se_sess; + struct completion *compl = se_cmd->compl; unsigned long flags; - bool fabric_stop; if (se_sess) { spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); @@ -2724,23 +2726,13 @@ static void target_release_cmd_kref(struct kref *kref) if (list_empty(&se_sess->sess_cmd_list)) wake_up(&se_sess->cmd_list_wq); } - - spin_lock(&se_cmd->t_state_lock); - fabric_stop = (se_cmd->transport_state & CMD_T_FABRIC_STOP) && - (se_cmd->transport_state & CMD_T_ABORTED); - spin_unlock(&se_cmd->t_state_lock); - - if (fabric_stop) { - spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); - target_free_cmd_mem(se_cmd); - complete(&se_cmd->cmd_wait_comp); - return; - } spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); } target_free_cmd_mem(se_cmd); se_cmd->se_tfo->release_cmd(se_cmd); + if (compl) + complete(compl); } /** diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index b2c4a2fa905f..3a345a609584 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -472,7 +472,7 @@ struct se_cmd { struct se_session *se_sess; struct se_tmr_req *se_tmr_req; struct list_head se_cmd_list; - struct completion cmd_wait_comp; + struct completion *compl; const struct target_core_fabric_ops *se_tfo; sense_reason_t (*execute_cmd)(struct se_cmd *); sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool, int *);