From patchwork Wed Feb 15 00:25:56 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: 9573079 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 21F586045F for ; Wed, 15 Feb 2017 00:26:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15E89283F4 for ; Wed, 15 Feb 2017 00:26:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACEB2842E; Wed, 15 Feb 2017 00:26:47 +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 8CBF62842B for ; Wed, 15 Feb 2017 00:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751362AbdBOA0p (ORCPT ); Tue, 14 Feb 2017 19:26:45 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:61609 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750908AbdBOA0m (ORCPT ); Tue, 14 Feb 2017 19:26:42 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86867830" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 08:26:20 +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 FA.E4.57638.C20A3A85; Tue, 14 Feb 2017 16:26:20 -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; Tue, 14 Feb 2017 16:26:15 -0800 X-AuditID: 0ac94369-26dee9800001e126-73-58a3a02cbcb7 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id AD.7D.11415.720A3A85; Tue, 14 Feb 2017 16:26:15 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v6 17/33] target: Use the command reference counting mechanism consistently Date: Tue, 14 Feb 2017 16:25:56 -0800 Message-ID: <20170215002612.14566-18-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215002612.14566-1-bart.vanassche@sandisk.com> References: <20170215002612.14566-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJLMWRmVeSWpSXmKPExsXCddJ5ka7OgsURBocnS1vsn/WMyeLr/+ks Fgve7GWzWLn6KJNF2+ozjBatS98yObB53N9+hMlj980GNo/3+66yeazfcpXFY/Ppao/Pm+QC 2KK4bFJSczLLUov07RK4Mv5+7mQpmCBd0dK/hq2BsUO8i5GTQ0LARGLh0u+MXYxcHEICS5kk uv8uYYFwdjBK9C/sZISpOnP4LVRiI6PEkZYF7CAJNgEjiW/vZ7KA2CJA9uqeZUwgRcwCtxkl 1jxezQaSEBaIlmi/upa5i5GDg0VAVWL7MkuQMK+Ag8TTY5NZIBbIS+xqu8gKYnMCxWfsOMkC Ui4kYC/x6Iw1yEgJgUWsEv8vrGGH6BWUODnzCVgvs4CExMEXL5hBbCEBdYmTS+YzTWAUmoWk bBaSsgWMTKsYxXIzc4pz01MLDE31ihPzUjKLs/WS83M3MUIiIHMH490n3ocYBTgYlXh4T8gu jhBiTSwrrsw9xCjBwawkwstWDxTiTUmsrEotyo8vKs1JLT7EKM3BoiTOe05maoSQQHpiSWp2 ampBahFMlomDU6qBMdzYPOq1XHD9s5sSr9++kF3svEjWtmVLwPFnb89dfbDoLsulhh7JULbo pTWzgl8xKex2tZ572d3+3Er91p93d6U0fzlW+qgq+L/49Wb2V6/ZmO2XyThXRjFlGX4SutUv 1XLv/LevFuFSV9u1JfZw/mV7mZX98tQOh7+nAlfxO0xjmSYvzsVZqcRSnJFoqMVcVJwIAKkx QUx8AgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBJMWRmVeSWpSXmKPExsXCtZGTTVd9weIIg9edShb7Zz1jsjj4s43R 4uv/6SwWC97sZbNYufook0Xb6jOMFq1L3zI5sHvc336EyWP3zQY2j/f7rrJ5TFtznslj/Zar LB6bT1d7fN4kF8AexWWTkpqTWZZapG+XwJXx93MnS8EE6YqW/jVsDYwd4l2MnBwSAiYSZw6/ Zeli5OIQEljPKLHh+nR2kASbgJHEt/czWUBsESB7dc8yJpAiZoG7jBJnuj+xgSSEBaIl2q+u Ze5i5OBgEVCV2L7MEiTMK+Ag8X/BTUaIBfISu9ousoLYnEDxGTtOsoCUCwnYSzw6Yz2BkXsB I8MqRrHczJzi3PTMAkNDveLEvJTM4my95PzcTYyQsIncwfh0ovkhRiYOTqkGxutLfkwxbDE9 esosqNMnIasys/P17LuFexLrjp4rt5BW/F7emiGS//Pk1on3Lm8rcCo7zXL5xRxbDy7R0wcC VI8tL82zv8z3cb6dlw57jMEr6ULHtBcKTz99CpTfsu6mbeYsf39tkcftT+72mzjLCJ8LrXNS rn0V3sLIsqxbZOW0LFaO9pJFSizFGYmGWsxFxYkATY2zFMsBAAA= 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 | 20 +++++++++----------- include/target/target_core_base.h | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 0cf2151b6a21..a641a7eac27d 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); @@ -2535,7 +2534,7 @@ 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); - cmd->se_tfo->release_cmd(cmd); + 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 9309522d50c3..6cd207fa1dc8 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 *);