From patchwork Wed Feb 8 22:25:03 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: 9563645 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 AC0D1602B4 for ; Wed, 8 Feb 2017 22:28:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D65B284F2 for ; Wed, 8 Feb 2017 22:28:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7261B28530; Wed, 8 Feb 2017 22:28:05 +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 F0182284F2 for ; Wed, 8 Feb 2017 22:28:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752104AbdBHW2D (ORCPT ); Wed, 8 Feb 2017 17:28:03 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:63858 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751433AbdBHW2B (ORCPT ); Wed, 8 Feb 2017 17:28:01 -0500 X-IronPort-AV: E=Sophos;i="5.35,348,1483977600"; d="scan'208";a="76618224" Received: from unknown (HELO milsmgep14.sandisk.com) ([63.163.107.225]) by ob1.hgst.iphmx.com with ESMTP; 09 Feb 2017 06:28:25 +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 98.72.18895.DCA9B985; Wed, 8 Feb 2017 14:25:17 -0800 (PST) Received: from milsmgip12.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; Wed, 8 Feb 2017 14:25:11 -0800 X-AuditID: 0ac94371-0fadb980000049cf-04-589b9acdaf45 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id E8.42.18148.7CA9B985; Wed, 8 Feb 2017 14:25:11 -0800 (PST) From: Bart Van Assche To: Bart Van Assche CC: , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v4 33/37] target: Inline transport_lun_remove_cmd() Date: Wed, 8 Feb 2017 14:25:03 -0800 Message-ID: <20170208222507.25715-34-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170208222507.25715-1-bart.vanassche@sandisk.com> References: <20170208222507.25715-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsXCddJ5ke7ZWbMjDDomW1nsn/WMyeLr/+ks FitXH2WyaF36lsmBxWP3zQY2j/f7rrJ5bD5d7fF5k1wASxSXTUpqTmZZapG+XQJXxrfrx5kK ZitWNL6zb2A8JN3FyMEhIWAisa03uIuRi0NIYCmTxLQlrewQznZGiZUPNzN1MXKCFd29fYcV IrGRUaJ72zZ2kASbgJHEt/czWUBsEQEDid+9FxhBipgFOhgl5vc8YwVJCAs4Sxy4uZEZxGYR UJE40XSaDcTmFXCQWNf0mhVig7zErraLYDYnUHzCy2eMILaQgL3EqwNfwIZKCLSxSvxY/Isd ollQ4uTMJ2CbmQUkJA6+eMEM0aAucXLJfKYJjEKzkJTNQlK2gJFpFaNYbmZOcW56aoGhiV5x Yl5KZnG2XnJ+7iZGSGAX7mB8fdv7EKMAB6MSD+8F69kRQqyJZcWVuYcYJTiYlUR4U6YBhXhT EiurUovy44tKc1KLDzFKc7AoifNmyU6NEBJITyxJzU5NLUgtgskycXBKNTDaCG7e0HV3q7NH B2+YQG37Sb5N3bev5L02jfXb9jqNNXg6j/63n0UJWpn5dt8THN4kfy3PV330M+D63OoPh5sz Dmq/DA/qM3NcZ/Fk90tu9epH6562ONiKGu63KJ9+q6z905oVTSs1+J3VuYK+58lzsT95+/Hj 2/B+/mCRJrOiyQ9THokf91ViKc5INNRiLipOBABdntSnaAIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKJMWRmVeSWpSXmKPExsXCtZGTTff4rNkRBis321jsn/WMyeLgzzZG i6//p7NYrFx9lMmidelbJgdWj903G9g83u+7yuYxbc15Jo/Np6s9Pm+SC2CN4rJJSc3JLEst 0rdL4Mr4dv04U8FsxYrGd/YNjIekuxg5OSQETCTu3r7D2sXIxSEksJ5RYv/eTnaQBJuAkcS3 9zNZQGwRAQOJ370XGEGKmAW6GCU2nTkFViQs4Cxx4OZGZhCbRUBV4tbLzYwgNq+Ag8TjJQ/Y IDbIS+xqu8gKYnMCxSe8fAZWIyRgL/HqwBfGCYzcCxgZVjGK5WbmFOemZxYYGukVJ+alZBZn 6yXn525ihARE1A7G6xPNDzEycXBKNTDOv/Dj8Z8qPYVjxWrSj6e9PvGiznG+zsFn6w4+DD4/ /fSyqPv7Z/FW34v/FO18SLjjQOexO8lTn+V0s5RM3hEuP+PuG37zS2L8Bzx4Zlzac7t1k0/h 3/zKRcuEE72lVK5IqRiuauxNmhGTe87Gh+Xcfh4p9pau97dYdqom3/88Q/69F+MyG8+3SizF GYmGWsxFxYkAggc73LgBAAA= 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 8df03987bdb8..99531dc85f9c 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -598,11 +598,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 @@ -629,17 +624,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); @@ -675,8 +659,6 @@ static void transport_handle_abort(struct se_cmd *cmd) { bool ack_kref = cmd->se_cmd_flags & SCF_ACK_KREF; - transport_lun_remove_cmd(cmd); - if (cmd->send_abort_response) { cmd->scsi_status = SAM_STAT_TASK_ABORTED; pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", @@ -1747,7 +1729,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; @@ -2022,7 +2003,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); } @@ -2096,7 +2076,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; } @@ -2122,7 +2101,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; } @@ -2147,7 +2125,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; } @@ -2183,7 +2160,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; @@ -2498,9 +2474,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 @@ -2573,6 +2546,9 @@ static void target_release_cmd_kref(struct kref *kref) WARN_ON_ONCE(atomic_read(&se_cmd->tgt_ref) != 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))) {