From patchwork Tue Nov 27 23:51:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10701633 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 EF8F913BB for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEF172C967 for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D304C2C9D5; Tue, 27 Nov 2018 23:52:35 +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 56A142C967 for ; Tue, 27 Nov 2018 23:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeK1KwI (ORCPT ); Wed, 28 Nov 2018 05:52:08 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:37107 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbeK1KwH (ORCPT ); Wed, 28 Nov 2018 05:52:07 -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=Swcy2cYErNU8CpB1PrDu9dwZbX6WDAwe8m7bPUXP3Zg=; b=uSDj3zJkNUsz B+D35FV7JJ8sCPnLrSTgqupq9U0B0+QaBanebvwgGMeV8T24WNdPshj7i1YESA8jvDVN0Pj5Loped cAd7PYdjtswxq/fYeQ6ksK5HOs1OXD19F6JhqwUgDTXKQMePxkG2gWlRpnEoZ2cPEQmL4hER35LT2 Ht6+voap4wgUi8Q221sK8E7JE2bxTha+Rt9S9Yqv6oRVkBFrl7oX5VdhTNsQzFmp054V7TQ5LMmIX saSaDC63e/fcFE31pGK4LYtc7v8dC+6IiNnyjHD8B8opfqsgfekSzrH68N2J0jPgbhXQTvOjHcUqu Iv7vu16qG608QBKw9JXcXw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gRn9U-000A0F-8I; Wed, 28 Nov 2018 00:52:25 +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 8DE72C03F9; Wed, 28 Nov 2018 00:52:21 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" Cc: Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Nicholas Bellinger , Mike Christie , David Disseldorp , Hannes Reinecke Subject: [PATCH v2 03/10] target/core: Simplify transport_clear_lun_ref() Date: Tue, 27 Nov 2018 15:51:57 -0800 Message-Id: <20181127235204.186731-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181127235204.186731-1-bvanassche@acm.org> References: <20181127235204.186731-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 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.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5mor0YVb2OVbcJJPTAkmkZt602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTagCTS5H5Pie2sCQ3gGSzr06cM7U7xDGmYwNG93LVnxwxjk yGQYCd08t3lHobjxX/OigDGQOIiVUN5rGO3B5zfVpnsdsF0/474T9aStD4uEKVG9P9yTThxC66Ku Xb0HO3W8nbMwgkUuW83PKbk25YSnvgtxKKcMIJ7ptgUxRg53TuCt4QJNIvyoxb4710Nl6KAZZ+9r UkyLOOkgJ9eTXvOC4trOptRiSOXsXUvIrRE5Gm67jINC+YEE7xhwtpNGAXpI2C8QBYsWIMCVBHpa 7Qj+JYN6Crh9DXUDEtWWsjsNUWDlGPaDR+Aes7asAZpVFyfMODodi5MLJiAvrVIiQFNhc8S+HKYI 1vbaqYoREZsvVKq8YZ9/SG1CqFB/T9oOuGkszjGcI+mbLJLuOAP016dVWgH88tf6uZ3Odz3W94Ik DCkIj7lUenMOpFxPb4a0gTxJECCYsMoByn2L5D4ESJJSPTtI2NWSXQ8+P45Rhlff/V8o9A8S4+tr vYumJM3atRPpj3GbeSYQbpjOFT4aGmRsFCWUldd4Zfx8AzM82qsIbx1/rxbQicf/5tMwo2bfwweZ +eEX1T91V5n3FsMEfdSIIO3fJ9DGWEJopzxygkVT7yk4xAm9D8KTeKJT7gNACPfxVynFIF3Xrs2K JHQMxL9Pga9lSGLsEntA55GTrob+bwU0pkWukw/5GtMnr6abkRkpgkQUlPutI474zhMXQYPkD4he QHulQ78UyVYAqkOPE6qW2xg/HY4alqklDBtTqXGJI9CnVA3fjMGyg48sBVMwSw4LvlF4kd5XJtyi c4/Tu+J4YfXDApCFS5UnqSvzTBMZqJNdbvPaUyoCdu6Y7CHSkG34KkwBCHXe+q6DmHcPHDs1wsEZ jz0fAsM4x/JvNN8Bwvd7/eQYhrnXrwqCT+txkgCIMo7V3eOzJJ/4nSzNzW4P2kDC4uGq3HDl7GPw DDt+pvlHhV6a5QjptwQBGybQnI83ChkUX8F6u4X0g9iAwvJfZx3lGs1VZ0iZG6egppXkjOrhVptJ 8gZRjxEnfx1IYQ/4lg9Ffvqg9IG0EE8tjDWZlB+G9Jc9fWekhCkYETsycmIe9DyBCzx4I5obgO+2 ucHiHFYFX/uMKqFwmrSG6vY4ocfmWv3Fe9Iziczdq+A= 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 Since transport_clear_lun_ref() already waits until the percpu-refcount .release() method is called, it is not necessary to wait first until percpu_ref_kill_and_confirm() has finished transitioning the refcount into atomic mode. Remove the code that waits for percpu_ref_kill_and_confirm() to complete and also the completion object that is used by that code. This patch does not change the behavior of the SCSI target code. Cc: Nicholas Bellinger Cc: Mike Christie Cc: Christoph Hellwig Cc: David Disseldorp Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- drivers/target/target_core_device.c | 1 - drivers/target/target_core_tpg.c | 1 - drivers/target/target_core_transport.c | 35 ++++---------------------- include/target/target_core_base.h | 1 - 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 47b5ef153135..c6b1122ee097 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -822,7 +822,6 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) xcopy_lun = &dev->xcopy_lun; rcu_assign_pointer(xcopy_lun->lun_se_dev, dev); - init_completion(&xcopy_lun->lun_ref_comp); init_completion(&xcopy_lun->lun_shutdown_comp); INIT_LIST_HEAD(&xcopy_lun->lun_deve_list); INIT_LIST_HEAD(&xcopy_lun->lun_dev_link); diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index 02e8a5d86658..0cfb9d7b31a3 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -577,7 +577,6 @@ struct se_lun *core_tpg_alloc_lun( } lun->unpacked_lun = unpacked_lun; atomic_set(&lun->lun_acl_count, 0); - init_completion(&lun->lun_ref_comp); init_completion(&lun->lun_shutdown_comp); INIT_LIST_HEAD(&lun->lun_deve_list); INIT_LIST_HEAD(&lun->lun_dev_link); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index d9e4b736312e..3cd037558957 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2911,38 +2911,13 @@ void target_wait_for_sess_cmds(struct se_session *se_sess) } EXPORT_SYMBOL(target_wait_for_sess_cmds); -static void target_lun_confirm(struct percpu_ref *ref) -{ - struct se_lun *lun = container_of(ref, struct se_lun, lun_ref); - - complete(&lun->lun_ref_comp); -} - +/* + * Prevent that new percpu_ref_tryget_live() calls succeed and wait until + * all references to the LUN have been released. Called during LUN shutdown. + */ void transport_clear_lun_ref(struct se_lun *lun) { - /* - * Mark the percpu-ref as DEAD, switch to atomic_t mode, drop - * the initial reference and schedule confirm kill to be - * executed after one full RCU grace period has completed. - */ - percpu_ref_kill_and_confirm(&lun->lun_ref, target_lun_confirm); - /* - * The first completion waits for percpu_ref_switch_to_atomic_rcu() - * to call target_lun_confirm after lun->lun_ref has been marked - * as __PERCPU_REF_DEAD on all CPUs, and switches to atomic_t - * mode so that percpu_ref_tryget_live() lookup of lun->lun_ref - * fails for all new incoming I/O. - */ - wait_for_completion(&lun->lun_ref_comp); - /* - * The second completion waits for percpu_ref_put_many() to - * invoke ->release() after lun->lun_ref has switched to - * atomic_t mode, and lun->lun_ref.count has reached zero. - * - * At this point all target-core lun->lun_ref references have - * been dropped via transport_lun_remove_cmd(), and it's safe - * to proceed with the remaining LUN shutdown. - */ + percpu_ref_kill(&lun->lun_ref); wait_for_completion(&lun->lun_shutdown_comp); } diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index e3bdb0550a59..58a03a094257 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -731,7 +731,6 @@ struct se_lun { struct scsi_port_stats lun_stats; struct config_group lun_group; struct se_port_stat_grps port_stat_grps; - struct completion lun_ref_comp; struct completion lun_shutdown_comp; struct percpu_ref lun_ref; struct list_head lun_dev_link;