From patchwork Fri Jan 25 18:34:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10781897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4396D746 for ; Fri, 25 Jan 2019 18:35:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 342B3299B5 for ; Fri, 25 Jan 2019 18:35:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 284782E1DB; Fri, 25 Jan 2019 18:35:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 9BA12299B5 for ; Fri, 25 Jan 2019 18:35:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729240AbfAYSfw (ORCPT ); Fri, 25 Jan 2019 13:35:52 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:55675 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbfAYSfw (ORCPT ); Fri, 25 Jan 2019 13:35:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=gr2Cy3BB5YoaLAlYiv6iPmXuuwcDWWeLIVIz+ofSTJg=; b=eP4c1Ug6q7wc lyw8V+ETDyUh1eFcryHzfBcI5hJd3SjYExu4t4g2s+0Bu3YOL+XLoYdTN4O6IiP2VdJ3qt+rtknJt MvhU7KnuQOIvn795HoD+TVXSOX5kPabY/QJHL9LfQJw3nARkjeP1Ft/HhYS6SQzfMSCEtR7LkGIqZ r1p5QyqcheT1YLSGaxqqJqu5bS57JXWddC87aYAgekgXsPJeiCStUhAB3dtYMNkdZKWBi2UabrafE 5kXnNc9W6Y1Wgf/mMusvH8lhZM+9WMqpxCEDgLG7ukfcqw4Ken39w4fyFQSrWMNGda3ljhSfRTuI5 9U089Nlt1q18RaT+shhfxQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gn6Jz-00041F-6y; Fri, 25 Jan 2019 19:35:24 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 0AA06C05E8; Fri, 25 Jan 2019 19:35:14 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Hannes Reinecke , Nicholas Bellinger , Mike Christie Subject: [PATCH 04/16] target/core: Inline transport_lun_remove_cmd() Date: Fri, 25 Jan 2019 10:34:46 -0800 Message-Id: <20190125183458.220477-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog In-Reply-To: <20190125183458.220477-1-bvanassche@acm.org> References: <20190125183458.220477-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5i6x58w9P4Xh3nFevv+gvsx602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3Ug2Z18o1igRi0Z9AoJlXGOnPH3eHvE/+YpYUPEvK1gTBln72tSTIs46SAn15Ne84Ii1Adc cqagVZJRZnZl4d3nKbnXLKV6PgqilNXCeStOb6fG4a+c9WQHY/ZSYGCg0KRnz36GGSOBMm+psSmc byPT+hsz8/q/OdhF13mF+CJjMsw4Oh2LkwsmIC+tUiJAU2HndEL8IbXBpRiMfP45Wz78wlk3Iika AYYay6zwzan8jJM4FJK5OR3dA6AwcnrK6eluxYvH2diC53wrDh3bCBPDF5WZp3AjdoRkErSrWMfJ QHJjKxjcJRcKJtpa3z3WiRQgMC0euyRWJ7x26Tv0oaNKsUXpeAiVHBWlM6dy+vmbeKTVDs7kesTy xgBnHEJLB92HXTxY/qMUubkMYlqd+ktCHX+vFtCJx//m0zCjZt/DB0RQrWCXPBvjQPTjIqT7lOxF QVRTn8m0sooRS7h6xdEgKTjECb0PwpN4olPuA0AI936c0SM84BxzaZIqKXfxGEKe5uvtvYPx5J/1 /DRNJM82fPZrhRHbfToy2oDKQNcS6UUZfR9Pm7MHzGqjesmrvl/J3zoiovuDVohDAu4bASAF5tj7 5Sf4aVP7fG6vuK0FWaTbSxwffnx7O0ytw52gHEssAcmEV7hMz3mBMrH9L+m/q1FQxqV/jN1mSd2B +sBKHhmok11u89pTKgJ27pjsIdIep0kfiq020WMUa8+aHGcg0CMad8Hsy40JMhGTdACw9DB8QZ6U 4Oy75gvIwpWZx7fPHkrggKwRrBHirQVdi7S7U8VMX2w7iiUjw9pZ+zXcnX6m+UeFXprlCOm3BAEb JtCUfKAc5tuMY57sizcN8Ybgo6ZwKd/lAfDURVeqOwDGeVPxhaTP1H+ecpe65ERyZY5hD/iWD0V+ +qD0gbQQTy2MYhai3vEoMrcP3ydYA96eq2KM8TNRPi4PtNSv3zAgl6Rv/trjt4n+OSd+6+F6OunJ 9jihx+Za/cV70jOJzN2r4A== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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. Reviewed-by: Hannes Reinecke Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 31 +++----------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index b25d27e8ca20..6471ede00336 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -664,11 +664,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 @@ -696,17 +691,6 @@ static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) return cmd->se_tfo->check_stop_free(cmd); } -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); @@ -797,8 +781,6 @@ static void target_handle_abort(struct se_cmd *cmd) WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); - transport_lun_remove_cmd(cmd); - transport_cmd_check_stop_to_fabric(cmd); } @@ -1711,7 +1693,6 @@ static void target_complete_tmr_failure(struct work_struct *work) se_cmd->se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST; se_cmd->se_tfo->queue_tm_rsp(se_cmd); - transport_lun_remove_cmd(se_cmd); transport_cmd_check_stop_to_fabric(se_cmd); } @@ -1902,7 +1883,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; @@ -2200,7 +2180,6 @@ static void transport_complete_qf(struct se_cmd *cmd) transport_handle_queue_full(cmd, cmd->se_dev, ret, false); return; } - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); } @@ -2295,7 +2274,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2321,7 +2299,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2357,7 +2334,6 @@ static void target_complete_ok_work(struct work_struct *work) if (ret) goto queue_full; - transport_lun_remove_cmd(cmd); transport_cmd_check_stop_to_fabric(cmd); return; } @@ -2393,7 +2369,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; @@ -2720,9 +2695,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); } if (aborted) cmd->free_compl = &compl; @@ -2794,6 +2766,9 @@ static void target_release_cmd_kref(struct kref *kref) struct completion *abrt_compl = se_cmd->abrt_compl; unsigned long flags; + 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); list_del_init(&se_cmd->se_cmd_list);