From patchwork Fri Feb 10 01:28:34 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: 9565769 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 DBB0360572 for ; Fri, 10 Feb 2017 01:29:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB51D28532 for ; Fri, 10 Feb 2017 01:29:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE46228559; Fri, 10 Feb 2017 01:29:36 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 15F3828532 for ; Fri, 10 Feb 2017 01:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751456AbdBJB3a (ORCPT ); Thu, 9 Feb 2017 20:29:30 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:18628 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751440AbdBJB31 (ORCPT ); Thu, 9 Feb 2017 20:29:27 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="82349489" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 10 Feb 2017 09:28:59 +0800 Received: from MILHUBIP04.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id DE.87.57638.B571D985; Thu, 9 Feb 2017 17:28:59 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Thu, 9 Feb 2017 17:28:55 -0800 X-AuditID: 0ac94369-26dee9800001e126-fa-589d175b6cd3 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 82.9F.11415.7571D985; Thu, 9 Feb 2017 17:28:55 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v5 04/22] target: Use the command reference counting mechanism consistently Date: Thu, 9 Feb 2017 17:28:34 -0800 Message-ID: <20170210012852.15735-5-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170210012852.15735-1-bart.vanassche@sandisk.com> References: <20170210012852.15735-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsXCddJ5kW60+NwIg/ubFSz2z3rGZPH1/3QW iwVv9rJZrFx9lMmibfUZRovWpW+ZHNg87m8/wuSx+2YDm8f7fVfZPNZvucrisfl0tcfnTXIB bFFcNimpOZllqUX6dglcGW+XXmUteCVdseueQQPjLfEuRk4OCQETibUHzzN2MXJxCAksZZL4 OecAK0hCSGA7o8TsA8UwRdParjBBFG1klPi69QwzSIJNwEji2/uZLCC2CJC9umcZWBGzwG1G iTWPV7OBJIQFoiXWHr8NVsQioCKxZeNJJhCbV8BeoufZMXaIDfISu9ougm3mFHCQeDX7OpDN AbTNXmLHLgOQmRIC81glfp3ZyALRKyhxcuYTMJtZQELi4IsXzBBXq0ucXDKfaQKj0CwkZbOQ lC1gZFrFKJabmVOcm55aYGiqV5yYl5JZnK2XnJ+7iRES/pk7GO8+8T7EKMDBqMTD+6JmToQQ a2JZcWXuIUYJDmYlEd77fHMjhHhTEiurUovy44tKc1KLDzFKc7AoifOek5kaISSQnliSmp2a WpBaBJNl4uCUamDMmaLB4HV8Zp3w3AIbvcUvb0hdSJRY8pY/d8P5zsjrEmFWDp2XOSf+FAxp ifi5ND2Ss+GhpsHJ13mNb+/Hz4tucG5VPcPI73hF726uit2WteLlyc0WzJ7X2vc/WdY3R2vx 7XM7+f8U7svLr1cofuxbxXbV4+ubIy9WbrEpmMKsFeT+rOnAXF8lluKMREMt5qLiRAAwkHPu ewIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOJMWRmVeSWpSXmKPExsXCtZGTTTdcfG6EwZsmfov9s54xWRz82cZo 8fX/dBaLBW/2slmsXH2UyaJt9RlGi9alb5kc2D3ubz/C5LH7ZgObx/t9V9k8pq05z+SxfstV Fo/Np6s9Pm+SC2CP4rJJSc3JLEst0rdL4Mp4u/Qqa8Er6Ypd9wwaGG+JdzFyckgImEhMa7vC 1MXIxSEksJ5R4sKcB4wgCTYBI4lv72eygNgiQPbqnmVgRcwCdxklznR/YgNJCAtES6w9fhuo iIODRUBVovMqO0iYV8BeYt25XawQC+QldrVdBLM5BRwkXs2+zgpSLgRUs2OXwQRG7gWMDKsY xXIzc4pz0zMLDA31ihPzUjKLs/WS83M3MUKCJnIH49OJ5ocYmTg4pRoYt5V9Zl6r9C4oN+yM 7Cq+jhfPH1+rtZrUV8P0Iy2dnfO11IapcmFlqc17rGK7nA4wJy5/JbHwalFcXufB3ctdNq6d 9J614v+bdd87eG4fbvOLylu6Ukf/i1alnqtd2tVF0Tvunj53cNetWz0aGxP6xU0uftv9s2yZ +uGvy0RmNU8OPNrbd/NkphJLcUaioRZzUXEiAHO8SQrKAQAA MIME-Version: 1.0 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 Use the se_cmd reference counting mechanism instead of calling the .release_cmd() method directly. Switch from 'cmd_wait_comp' to 'complete' to avoid triggering a circular dependency. Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp --- drivers/target/target_core_transport.c | 22 ++++++++++------------ include/target/target_core_base.h | 1 - 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index c4ea12966fad..27a6df77c078 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1220,7 +1220,6 @@ 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); spin_lock_init(&cmd->t_state_lock); kref_init(&cmd->cmd_kref); kref_init(&cmd->tgt_ref); @@ -2534,8 +2533,8 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) */ 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(&cmd->complete); + transport_put_cmd(cmd); ret = 1; } return ret; @@ -2612,7 +2611,6 @@ static void target_release_cmd_kref(struct kref *kref) list_del_init(&se_cmd->se_cmd_list); spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); target_free_cmd_mem(se_cmd); - complete(&se_cmd->cmd_wait_comp); return; } list_del_init(&se_cmd->se_cmd_list); @@ -2652,9 +2650,8 @@ int target_put_sess_cmd(struct se_cmd *se_cmd) } EXPORT_SYMBOL(target_put_sess_cmd); -/* target_sess_cmd_list_set_waiting - Flag all commands in - * sess_cmd_list to complete cmd_wait_comp. Set - * sess_tearing_down so no more commands are queued. +/** + * target_sess_cmd_list_set_waiting - prevent new commands to be queued * @se_sess: session to flag */ void target_sess_cmd_list_set_waiting(struct se_session *se_sess) @@ -2711,12 +2708,13 @@ void target_wait_for_sess_cmds(struct se_session *se_sess) target_put_sess_cmd(se_cmd); } - wait_for_completion(&se_cmd->cmd_wait_comp); - pr_debug("After cmd_wait_comp: se_cmd: %p t_state: %d" - " fabric state: %d\n", se_cmd, se_cmd->t_state, - se_cmd->se_tfo->get_cmd_state(se_cmd)); + wait_for_completion(&se_cmd->complete); + pr_debug("Finished waiting for se_cmd %p t_state %d fabric state: %d\n", + se_cmd, se_cmd->t_state, + se_cmd->se_tfo->get_cmd_state(se_cmd)); - se_cmd->se_tfo->release_cmd(se_cmd); + WARN_ON_ONCE(!se_cmd->se_sess); + target_put_sess_cmd(se_cmd); } spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 2633e6ff7eee..0f2a9bea9ef3 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -473,7 +473,6 @@ 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; 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 *);