From patchwork Fri Feb 10 01:28:48 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: 9565801 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 63AA760572 for ; Fri, 10 Feb 2017 01:29:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 555C72853A for ; Fri, 10 Feb 2017 01:29:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A71E28548; Fri, 10 Feb 2017 01:29:51 +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 A8AB92853A for ; Fri, 10 Feb 2017 01:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751389AbdBJB3s (ORCPT ); Thu, 9 Feb 2017 20:29:48 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15691 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751375AbdBJB3Z (ORCPT ); Thu, 9 Feb 2017 20:29:25 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="82349481" Received: from unknown (HELO milsmgep14.sandisk.com) ([63.163.107.225]) by ob1.hgst.iphmx.com with ESMTP; 10 Feb 2017 09:28:59 +0800 Received: from MILHUBIP03.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 E1.64.18895.B571D985; Thu, 9 Feb 2017 17:28:59 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Thu, 9 Feb 2017 17:28:55 -0800 X-AuditID: 0ac94371-0fadb980000049cf-09-589d175b8990 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id A8.9F.11415.7571D985; Thu, 9 Feb 2017 17:28:55 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v5 18/22] target: Inline transport_lun_remove_cmd() Date: Thu, 9 Feb 2017 17:28:48 -0800 Message-ID: <20170210012852.15735-19-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+NgFrrHLMWRmVeSWpSXmKPExsXCddJ5kW60+NwIg/8zlCz2z3rGZPH1/3QW i5WrjzJZtK0+w2jRuvQtkwOrx/3tR5g8dt9sYPN4v+8qm8fm09UenzfJBbBGcdmkpOZklqUW 6dslcGVMatjLWrBIsWLLfo4GxhPSXYycHBICJhJ9l16zdTFycQgJLGWS6N42ix3C2coo8b51 FTNMVc+3JUwQiY2MEhuWzGUESbAJGEl8ez+TBcQWAbJX9ywDK2IW2MEoMXHlbnaQhLCAs8Tl 5zuBijg4WARUJLZeVgAJ8wo4SFz7fowFYoG8xK62i6wgNidQ/NXs66wg5UIC9hI7dhmAjJQQ 6GOVeNB/hAmiV1Di5MwnYL3MAhISB1+8ADtUSEBd4uSS+UwTGIVmISmbhaRsASPTKkax3Myc 4tz01AJDE73ixLyUzOJsveT83E2MkFAv3MH4+rb3IUYBDkYlHt4JVXMihFgTy4orcw8xSnAw K4nw3uebGyHEm5JYWZValB9fVJqTWnyIUZqDRUmcN0t2aoSQQHpiSWp2ampBahFMlomDU6qB cSvz81eMLk56RXmFXo8X9L5PC9rku2rnZaW2mUY/rSTm/3fRe2r//ePrjsY4/1XL53gnzzFd udCZL+RLvHO/Y07AjEMRDMf8S3smz+3oy+45aaDm4RBkMd0jK2yZXADX/qpJmx4X3rzA0Nb+ OzWvbjZD/fe0+JTdi/kFzqs2M93vSIkSuHFfiaU4I9FQi7moOBEAnmwDI3ECAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHJMWRmVeSWpSXmKPExsXCtZGTTTdcfG6EwYGzKhb7Zz1jsjj4s43R 4uv/6SwWK1cfZbJoW32G0aJ16VsmBzaP+9uPMHnsvtnA5vF+31U2j2lrzjN5bD5d7fF5k1wA WxSXTUpqTmZZapG+XQJXxqSGvawFixQrtuznaGA8Id3FyMkhIWAi0fNtCVMXIxeHkMB6RolN LZsYQRJsAkYS397PZAGxRYDs1T3LwIqYBXYxSkyecAIsISzgLHH5+U4wm0VAVeLqltVgNq+A g8SPWavYITbIS+xqu8gKYnMCxV/Nvg5kcwBts5fYsctgAiP3AkaGVYxiuZk5xbnpmQWGhnrF iXkpmcXZesn5uZsYISESuYPx6UTzQ4xMHJxSDYzlp2PNRdZrbGBadtr1X5Uy26Pf+520T1y4 rSgyR6Y4cnH4Kn729JiQufNWHCoVjvlXd1SrxXnlvWV2Pkm8pv8FZsw+nrVwctvk/ttHZVUt dyblP188w2pp5fxMv22+lu84HknZqPFMOHzlvSvbyVcZzaqbJTQs7u9aER1QMcuM/dKn5r/T 0hqUWIozEg21mIuKEwGaFVAVwQEAAA== 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 Remove the code that clears .se_lun from transport_cmd_check_stop_to_fabric() such that the transport_lun_remove_cmd() call can be moved into target_release_cmd_kref(). Because this guarantees that transport_lun_remove_cmd() will be called exactly once, it is safe to change the cmpxchg() call into a test of se_cmd.lun_ref_active. Inline transport_lun_remove_cmd() because it is not worth to keep it as a separate function. Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp --- drivers/target/target_core_transport.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 0dd2119f21a9..9deab861529c 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -606,11 +606,6 @@ static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) target_remove_from_state_list(cmd); - /* - * Clear struct se_cmd->se_lun before the handoff to FE. - */ - cmd->se_lun = NULL; - spin_lock_irqsave(&cmd->t_state_lock, flags); /* * Determine if frontend context caller is requesting the stopping of @@ -639,17 +634,6 @@ static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) : 0; } -static void transport_lun_remove_cmd(struct se_cmd *cmd) -{ - struct se_lun *lun = cmd->se_lun; - - if (!lun) - return; - - if (cmpxchg(&cmd->lun_ref_active, true, false)) - percpu_ref_put(&lun->lun_ref); -} - static void target_complete_failure_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); @@ -688,8 +672,6 @@ static void target_handle_abort(struct se_cmd *cmd) pr_debug("tag %#llx: send_abort_response = %d\n", cmd->tag, cmd->send_abort_response); - transport_lun_remove_cmd(cmd); - if (cmd->send_abort_response) { if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) { cmd->scsi_status = SAM_STAT_TASK_ABORTED; @@ -1766,7 +1748,6 @@ void transport_generic_request_failure(struct se_cmd *cmd, goto queue_full; check_stop: - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; @@ -2041,7 +2022,6 @@ static void transport_complete_qf(struct se_cmd *cmd) transport_handle_queue_full(cmd, cmd->se_dev); return; } - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); } @@ -2115,7 +2095,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret == -EAGAIN || ret == -ENOMEM) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2141,7 +2120,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret == -EAGAIN || ret == -ENOMEM) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2166,7 +2144,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret == -EAGAIN || ret == -ENOMEM) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2202,7 +2179,6 @@ static void target_complete_ok_work(struct work_struct *work) break; } - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; @@ -2517,9 +2493,6 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) */ if (cmd->state_active) target_remove_from_state_list(cmd); - - if (cmd->se_lun) - transport_lun_remove_cmd(cmd); } /* * Since the iSCSI and iSER targets driver assume that a SCSI command @@ -2592,6 +2565,9 @@ static void target_release_cmd_kref(struct kref *kref) WARN_ON_ONCE(atomic_read(&se_cmd->tgt_ref.refcount) != 0); + if (se_cmd->lun_ref_active) + percpu_ref_put(&se_cmd->se_lun->lun_ref); + if (se_sess) { spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); if (likely(!list_empty(&se_cmd->se_cmd_list))) {