From patchwork Wed Feb 15 00:26:11 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: 9573115 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 D3EB26045F for ; Wed, 15 Feb 2017 00:26:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C76D0205D6 for ; Wed, 15 Feb 2017 00:26:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC49326E76; Wed, 15 Feb 2017 00:26:59 +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 525AB267EC for ; Wed, 15 Feb 2017 00:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751210AbdBOA06 (ORCPT ); Tue, 14 Feb 2017 19:26:58 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:17288 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751454AbdBOA0z (ORCPT ); Tue, 14 Feb 2017 19:26:55 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86867956" Received: from unknown (HELO milsmgep14.sandisk.com) ([63.163.107.225]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 08:26:23 +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 F3.FB.18895.E20A3A85; Tue, 14 Feb 2017 16:26:23 -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:16 -0800 X-AuditID: 0ac94371-0fadb980000049cf-44-58a3a02e749d Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 64.8D.11415.720A3A85; Tue, 14 Feb 2017 16:26:15 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v6 32/33] target: Inline transport_lun_remove_cmd() Date: Tue, 14 Feb 2017 16:26:11 -0800 Message-ID: <20170215002612.14566-33-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+NgFrrPLMWRmVeSWpSXmKPExsXCddJ5ka7+gsURBjN7uS32z3rGZPH1/3QW i5WrjzJZtK0+w2jRuvQtkwOrx/3tR5g8dt9sYPN4v+8qm8fm09UenzfJBbBGcdmkpOZklqUW 6dslcGXc3MtRMFmxYveBbWwNjEeluxg5OSQETCRed39m6WLk4hASWMokcePtDUYIZwejROu5 32wwVTuXvYSq2sgo0f6ojx0kwSZgJPHt/UwWEFsEyF7ds4wJpIgZpHviyt1gRcICzhJLWw+x gtgsAqoSc3bvAmvgFXCQWDn9CDvEBnmJXW0XwWo4geIzdpwEquEA2mYv8eiMNchMCYE+VolV 764wQfQKSpyc+QRsDrOAhMTBFy+YQWwhAXWJk0vmM01gFJqFpGwWkrIFjEyrGMVyM3OKc9NT CwxN9IoT81Iyi7P1kvNzNzFCgr1wB+Pr296HGAU4GJV4eE/ILo4QYk0sK67MPcQowcGsJMLL Vg8U4k1JrKxKLcqPLyrNSS0+xCjNwaIkzpslOzVCSCA9sSQ1OzW1ILUIJsvEwSnVwHhxuoXf fu/4qw/7jJ9OdzhyLG8b832tnZvX/siI2/N1W4HU9q03hfuO7iydOL1x/zT2zwteVAubHQ7a uumwuMudXe0hJz9N81Q5tuPo9roW7YNuglU704LmhD6cMkXSpzffeYfKOqa7LVY+R80mHb3B Ou9TdtlB/v+e620cHUM+/4md+ua9lq+kEktxRqKhFnNRcSIAH9PX63ICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHJMWRmVeSWpSXmKPExsXCtZGTTVd9weIIg3XbzSz2z3rGZHHwZxuj xdf/01ksVq4+ymTRtvoMo0Xr0rdMDmwe97cfYfLYfbOBzeP9vqtsHtPWnGfy2Hy62uPzJrkA tigum5TUnMyy1CJ9uwSujJt7OQomK1bsPrCNrYHxqHQXIyeHhICJxM5lL1m6GLk4hATWM0pc XXOPDSTBJmAk8e39TBYQWwTIXt2zjAmkiFlgF6PE5AknwBLCAs4SS1sPsYLYLAKqEnN27wKL 8wo4SOycdpgRYoO8xK62i2A1nEDxGTtOAtVwAG2zl3h0xnoCI/cCRoZVjGK5mTnFuemZBYaG esWJeSmZxdl6yfm5mxghIRK5g/HpRPNDjEwcnFINjG6KtYVMxfZ1K+b2Tqz+nHPqqcH/33J7 u61+nCuLOpafub+tvZelxSzmzT2b8AtCX4uTb/H5/dzoMSutqJJR9BLrfKfu36xnZ6af0HY4 KxOZt71zm3z43sKlAe6an+bH7ud87xk5gU1d72SPcOWlsKLJkbVT0swTt7Uxla1msw5uWZ3M LPZHiaU4I9FQi7moOBEAkn1BWcEBAAA= 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 5af06fd2abe9..e4c12f7e0437 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); @@ -686,8 +670,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; @@ -1762,7 +1744,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; @@ -2037,7 +2018,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); } @@ -2111,7 +2091,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; } @@ -2137,7 +2116,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; } @@ -2162,7 +2140,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; } @@ -2198,7 +2175,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; @@ -2511,9 +2487,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); } BUG_ON(!cmd->se_tfo); return target_put_sess_cmd(cmd); @@ -2577,6 +2550,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))) {