From patchwork Tue Mar 30 16:17:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D29CBC433E2 for ; Tue, 30 Mar 2021 16:18:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5CA3619D4 for ; Tue, 30 Mar 2021 16:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231752AbhC3QSJ (ORCPT ); Tue, 30 Mar 2021 12:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231951AbhC3QRm (ORCPT ); Tue, 30 Mar 2021 12:17:42 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0AD4C061762; Tue, 30 Mar 2021 09:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nGAZ/xM8Mx4+9DVBn7L/9DNXZELRNObgOzid/KBGpHQ=; b=zRV68zTBPzgjiVmJhp0hMiHEUS wdvtxworgSsfxi1V064WIjS0gZLE+amGlHrHyMRbGOTFOuHCL/xFaLHkTBE3Xq7MpSq0z5gwvD3F6 SONkPBKFiQRTcNt6shFCvdFWPkcdXobhxHkLcd1NOTqswzppxfarkdeTxUl1Ul1D3h5Q6YbvFjQUv sjRC9dfA6f04r6JueOLmEZ3YcE/xwPk/onaQtWiEs3I87qiGZzn1+aR0DMAagkuFujFpw4YxmCjP2 qJCql/G3agFT4MF4UFa8jPtjSWd0k1YYo9mNAvGzSYBFeqIh3uU0jDbxCLFaZUw/jJ5Zw18s3fQ0A uV+61n/g==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH3d-008aJl-Pm; Tue, 30 Mar 2021 16:17:34 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 01/15] md: remove the code to flush an old instance in md_open Date: Tue, 30 Mar 2021 18:17:13 +0200 Message-Id: <20210330161727.2297292-2-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Due to the flush_workqueue() call in md_alloc no previous instance of mddev can still be around at this point. Signed-off-by: Christoph Hellwig --- drivers/md/md.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 368cad6cd53a6e..cd2d825dd4f881 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7807,43 +7807,22 @@ static int md_open(struct block_device *bdev, fmode_t mode) * Succeed if we can lock the mddev, which confirms that * it isn't being stopped right now. */ - struct mddev *mddev = mddev_find(bdev->bd_dev); + struct mddev *mddev = bdev->bd_disk->private_data; int err; - if (!mddev) - return -ENODEV; - - if (mddev->gendisk != bdev->bd_disk) { - /* we are racing with mddev_put which is discarding this - * bd_disk. - */ - mddev_put(mddev); - /* Wait until bdev->bd_disk is definitely gone */ - if (work_pending(&mddev->del_work)) - flush_workqueue(md_misc_wq); - /* Then retry the open from the top */ - return -ERESTARTSYS; - } - BUG_ON(mddev != bdev->bd_disk->private_data); - - if ((err = mutex_lock_interruptible(&mddev->open_mutex))) - goto out; - + err = mutex_lock_interruptible(&mddev->open_mutex); + if (err) + return err; if (test_bit(MD_CLOSING, &mddev->flags)) { mutex_unlock(&mddev->open_mutex); - err = -ENODEV; - goto out; + return -ENODEV; } - - err = 0; + mddev_get(mddev); atomic_inc(&mddev->openers); mutex_unlock(&mddev->open_mutex); bdev_check_media_change(bdev); - out: - if (err) - mddev_put(mddev); - return err; + return 0; } static void md_release(struct gendisk *disk, fmode_t mode) From patchwork Tue Mar 30 16:17:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDC01C433E1 for ; Tue, 30 Mar 2021 16:18:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE89261964 for ; Tue, 30 Mar 2021 16:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbhC3QSK (ORCPT ); Tue, 30 Mar 2021 12:18:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232032AbhC3QRm (ORCPT ); Tue, 30 Mar 2021 12:17:42 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1781FC061574; Tue, 30 Mar 2021 09:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+ogX7BeZ7M/F4qtI598zEt/o+xdyAKsVBDVyMmdaGYM=; b=dfUzpyEBEYlWdEn1aeDyqi1buR w/HZmPpWIIthpvpZAWFDzlH27loA38grO3fAKvoTjYz8QzEogwmAKZXX4QyUWr0kfuA7UCfl+fV4k s+D5f4c6N0GfCBp6cbsh8tiy1qi5+7GJFXh4wsUjhcvQH9Tv0TKoNkAP+90WvjGyg9Bet7izTzavB rNkWpsBRgs12YRYuOKMNtr7ErcBquh6aLaoYLFM8FXoa5RCh1VdTH+ypz2RGvdWcNY7iafUG77TQE CkNhtJemAifZeS6382S4ljT4qqXKJtMLqIGkGx27FmljCiIlcJVWw78PBV31aI5P2SSTLGWlO1o3+ 6K0UjA7Q==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH3g-008aJr-CS; Tue, 30 Mar 2021 16:17:36 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 02/15] md: factor out a mddev_find_locked helper from mddev_find Date: Tue, 30 Mar 2021 18:17:14 +0200 Message-Id: <20210330161727.2297292-3-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Factor out a self-contained helper to just lookup a mddev by the dev_t "unit". Signed-off-by: Christoph Hellwig --- drivers/md/md.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index cd2d825dd4f881..9556724fdb0848 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -734,6 +734,17 @@ void mddev_init(struct mddev *mddev) } EXPORT_SYMBOL_GPL(mddev_init); +static struct mddev *mddev_find_locked(dev_t unit) +{ + struct mddev *mddev; + + list_for_each_entry(mddev, &all_mddevs, all_mddevs) + if (mddev->unit == unit) + return mddev; + + return NULL; +} + static struct mddev *mddev_find(dev_t unit) { struct mddev *mddev, *new = NULL; @@ -745,13 +756,13 @@ static struct mddev *mddev_find(dev_t unit) spin_lock(&all_mddevs_lock); if (unit) { - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == unit) { - mddev_get(mddev); - spin_unlock(&all_mddevs_lock); - kfree(new); - return mddev; - } + mddev = mddev_find_locked(unit); + if (mddev) { + mddev_get(mddev); + spin_unlock(&all_mddevs_lock); + kfree(new); + return mddev; + } if (new) { list_add(&new->all_mddevs, &all_mddevs); @@ -777,12 +788,7 @@ static struct mddev *mddev_find(dev_t unit) return NULL; } - is_free = 1; - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == dev) { - is_free = 0; - break; - } + is_free = !mddev_find_locked(dev); } new->unit = dev; new->md_minor = MINOR(dev); From patchwork Tue Mar 30 16:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20796C43459 for ; Tue, 30 Mar 2021 16:18:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F240161953 for ; Tue, 30 Mar 2021 16:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232292AbhC3QSN (ORCPT ); Tue, 30 Mar 2021 12:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232048AbhC3QRu (ORCPT ); Tue, 30 Mar 2021 12:17:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83408C061574; Tue, 30 Mar 2021 09:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=iV6sCX9X2hk1kAMEncdX18HrNbEV0YbR1UcnrSP5QxQ=; b=J7cxyCNKvNMMspOm5dbdjhDIQb w6T2yxDd4KZ6T+ICfWC2ifD055APOKLZ2utoTY4Dja9g9APGl+/TN/1TX63ZFmG1pGo0HnTNn5YAE wIDuh8+3vx0mr6lBeO54r6GevuPGXfzysUcP+H8bsZbEdieKhsGEzLA+1VJGtZhGdtkcfYByfk+xB rcIiirlOY7foT+bAYSk/zGKjYzk2pKVGNM8f6Ylxlde4C4usPiTZn3oQPkNwx3FrY+d/N9HSdNQfQ 4OPPSmM31eQnJNNfAsNGBd1G7H+4SN+Zl4deij0A6h65piix5lnJFhTHuMaZk/Gks5PzK9o/Z0C9i jMdP9jug==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH3o-008aKP-Tf; Tue, 30 Mar 2021 16:17:45 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 05/15] md: refactor mddev_find_or_alloc Date: Tue, 30 Mar 2021 18:17:17 +0200 Message-Id: <20210330161727.2297292-6-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allocate the new mddev first speculatively, which greatly simplifies the code flow. Signed-off-by: Christoph Hellwig --- drivers/md/md.c | 60 ++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8e60bcc9c1d10c..ea9c92c113619b 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -784,57 +784,45 @@ static struct mddev *mddev_find(dev_t unit) static struct mddev *mddev_find_or_alloc(dev_t unit) { - struct mddev *mddev, *new = NULL; + struct mddev *mddev = NULL, *new; if (unit && MAJOR(unit) != MD_MAJOR) - unit &= ~((1<all_mddevs, &all_mddevs); - spin_unlock(&all_mddevs_lock); - new->hold_active = UNTIL_IOCTL; - return new; - } - } else if (new) { + new->unit = unit; + if (MAJOR(unit) == MD_MAJOR) + new->md_minor = MINOR(unit); + else + new->md_minor = MINOR(unit) >> MdpMinorShift; + new->hold_active = UNTIL_IOCTL; + } else { new->unit = mddev_alloc_unit(); - if (!new->unit) { - spin_unlock(&all_mddevs_lock); - kfree(new); - return NULL; - } + if (!new->unit) + goto out_free_new; new->md_minor = MINOR(new->unit); new->hold_active = UNTIL_STOP; - list_add(&new->all_mddevs, &all_mddevs); - spin_unlock(&all_mddevs_lock); - return new; } - spin_unlock(&all_mddevs_lock); - - new = kzalloc(sizeof(*new), GFP_KERNEL); - if (!new) - return NULL; - new->unit = unit; - if (MAJOR(unit) == MD_MAJOR) - new->md_minor = MINOR(unit); - else - new->md_minor = MINOR(unit) >> MdpMinorShift; - - mddev_init(new); - - goto retry; + list_add(&new->all_mddevs, &all_mddevs); + spin_unlock(&all_mddevs_lock); + return new; +out_free_new: + spin_unlock(&all_mddevs_lock); + kfree(new); + return mddev; } static struct attribute_group md_redundancy_group; From patchwork Tue Mar 30 16:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6400EC433E4 for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 439AC61964 for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232048AbhC3QSS (ORCPT ); Tue, 30 Mar 2021 12:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231579AbhC3QRz (ORCPT ); Tue, 30 Mar 2021 12:17:55 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44B56C061574; Tue, 30 Mar 2021 09:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fx9ipDNB8QCJwEpZSdFltGaNtDhKrZaNZLShscDG/iw=; b=rrdgMTcGdw7+3aotjkdCc98+ld 5rvxhpirkXotysTVdC4+asorCLAnEuZiLfUKI/tbq8YFylitozuutsHfmqz4+JC0CoUQSc11Soear qMe9c3sRMNci3i6xwlBwqbYyUY+0j8HhPXDdYXse5pwVDqx66l4v6VfwfSnQ52dm+IwQoXBzcM6nY hyPxHv/YBvmsbjOBoZ3CHwQLoAqZaUhMmtwdrEIN4BaQgWyobNxw6HPAHDA2wdwijf80a4vbr0aYL NDxxx2Tv9jD2kX03MpMmcHS9HU6toBtu28WiXRb79c4jlglwhI7fhUfR1B+BI80At8XP9hV4m3tpC V6kOvVgQ==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH3u-008aKi-CW; Tue, 30 Mar 2021 16:17:51 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 07/15] block: remove the -ERESTARTSYS handling in blkdev_get_by_dev Date: Tue, 30 Mar 2021 18:17:19 +0200 Message-Id: <20210330161727.2297292-8-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Now that md has been cleaned up we can get rid of this hack. Signed-off-by: Christoph Hellwig --- fs/block_dev.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 535d29fa06fa47..0c09b6517b20b7 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1430,10 +1430,6 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) if (ret) return ERR_PTR(ret); - /* - * If we lost a race with 'disk' being deleted, try again. See md.c. - */ -retry: bdev = blkdev_get_no_open(dev); if (!bdev) return ERR_PTR(-ENXIO); @@ -1480,8 +1476,6 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) disk_unblock_events(disk); put_blkdev: blkdev_put_no_open(bdev); - if (ret == -ERESTARTSYS) - goto retry; return ERR_PTR(ret); } EXPORT_SYMBOL(blkdev_get_by_dev); From patchwork Tue Mar 30 16:17:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412148 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D028BC4332D for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBCDE61964 for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbhC3QSU (ORCPT ); Tue, 30 Mar 2021 12:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbhC3QSA (ORCPT ); Tue, 30 Mar 2021 12:18:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27AD6C061574; Tue, 30 Mar 2021 09:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=4L2qT1khKY2QTFz1lzxiescWjxM5Qi1GFLY/dRNxlyc=; b=QWtp3pC/JljBgg0SwzE0JD6MTD 6t5Kalb+rtVodDwmuWpDBBBMlhGRVttYpNAyuX2d+ZjHYgnL4wHK6AnVoU/Iz2tIUAbW4UgYaFSLl tOPmMoyKortlmnCXTEZ7j2gRof0TE4fKLclbumoAgoSv0cHR8kbFN3R1TEWXcUEt/zPEyfDwl38l1 ZrJX3lWg956OafIh51eD8JSq5BKqEnmsokKiubXD5J+Qq7g1tN/w2yTU8Qt+QSxYaLhDYnh4AOR/8 6YWZRlla7mLYzGdoJ18jkTlPO6awHSm1ypZ4s7I5Nu2974kTXKPI11u7KTCYXNtM2nLbfGOelTX9D fIuUWVOw==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH40-008aL2-3v; Tue, 30 Mar 2021 16:17:56 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 09/15] block: move sync_blockdev from __blkdev_put to blkdev_put Date: Tue, 30 Mar 2021 18:17:21 +0200 Message-Id: <20210330161727.2297292-10-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Do the early unlocked syncing even earlier to move more code out of the recursive path. Signed-off-by: Christoph Hellwig --- fs/block_dev.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index d732001285201a..691eef20a7ced7 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1547,16 +1547,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) struct gendisk *disk = bdev->bd_disk; struct block_device *victim = NULL; - /* - * Sync early if it looks like we're the last one. If someone else - * opens the block device between now and the decrement of bd_openers - * then we did a sync that we didn't need to, but that's not the end - * of the world and we want to avoid long (could be several minute) - * syncs while holding the mutex. - */ - if (bdev->bd_openers == 1) - sync_blockdev(bdev); - mutex_lock_nested(&bdev->bd_mutex, for_part); if (for_part) bdev->bd_part_count--; @@ -1583,6 +1573,16 @@ void blkdev_put(struct block_device *bdev, fmode_t mode) { struct gendisk *disk = bdev->bd_disk; + /* + * Sync early if it looks like we're the last one. If someone else + * opens the block device between now and the decrement of bd_openers + * then we did a sync that we didn't need to, but that's not the end + * of the world and we want to avoid long (could be several minute) + * syncs while holding the mutex. + */ + if (bdev->bd_openers == 1) + sync_blockdev(bdev); + mutex_lock(&bdev->bd_mutex); if (mode & FMODE_EXCL) { From patchwork Tue Mar 30 16:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2347C4332E for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CECF161953 for ; Tue, 30 Mar 2021 16:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbhC3QSW (ORCPT ); Tue, 30 Mar 2021 12:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231797AbhC3QSE (ORCPT ); Tue, 30 Mar 2021 12:18:04 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09DCFC061574; Tue, 30 Mar 2021 09:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=06DvUoaPP4FnUhreDcYAOss1XhbqHxuJ6o8UzGwX1y8=; b=2NOUq5KWVdqnvqKrh8gqBNagiy Tb7ttzO8cOVqiWC9HEEudkBx4GCzmSt5+H6KlFY4F8OOgg2tl7Iyxc9namweH84oJVbh6LnoZLvDX ZHoI2uogyAIGjMj25Rq638TyWIe/Q7sLbO+FHjHO9ND4/xx78PJvkI8g2TM+oFr8E/Y+r26QgAQou T0wr12XWYjk1xmozBIdbm/opiokZTKHO0iyfd61U47zXVLJuD7VcXutlGu39GA2Keiq92RIk7mRio ECU7KBIyn1n36yE9VFsSiFefgXBnh5A52mG3M90UB3QzoWMHm+Nelqa9SW9wz+vCbGeQDmhSndyMk BDFKBS+Q==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH42-008aLm-Vt; Tue, 30 Mar 2021 16:17:59 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 10/15] block: move bd_mutex to struct gendisk Date: Tue, 30 Mar 2021 18:17:22 +0200 Message-Id: <20210330161727.2297292-11-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Replace the per-block device bd_mutex with a per-gendisk open_mutex, thus simplifying locking wherever we deal with partitions. Signed-off-by: Christoph Hellwig Acked-by: Roger Pau Monné Acked-by: Stefan Haberland --- Documentation/filesystems/locking.rst | 2 +- block/genhd.c | 3 ++- block/partitions/core.c | 22 +++++++--------- drivers/block/loop.c | 14 +++++----- drivers/block/xen-blkfront.c | 8 +++--- drivers/block/zram/zram_drv.c | 18 ++++++------- drivers/block/zram/zram_drv.h | 2 +- drivers/md/md.h | 6 ++--- drivers/s390/block/dasd_genhd.c | 8 +++--- drivers/scsi/sd.c | 4 +-- fs/block_dev.c | 37 +++++++++++---------------- fs/btrfs/volumes.c | 2 +- fs/super.c | 8 +++--- include/linux/blk_types.h | 1 - include/linux/genhd.h | 3 +++ 15 files changed, 65 insertions(+), 73 deletions(-) diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst index 9774e92e449fbd..1cd8090fd4b262 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -475,7 +475,7 @@ prototypes:: locking rules: ======================= =================== -ops bd_mutex +ops open_mutex ======================= =================== open: yes release: yes diff --git a/block/genhd.c b/block/genhd.c index 8c8f543572e64e..7acedbd2474381 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1379,6 +1379,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) goto out_free_disk; disk->node_id = node_id; + mutex_init(&disk->open_mutex); xa_init(&disk->part_tbl); if (xa_insert(&disk->part_tbl, 0, disk->part0, GFP_KERNEL)) goto out_destroy_part_tbl; @@ -1596,7 +1597,7 @@ void disk_unblock_events(struct gendisk *disk) * doesn't clear the events from @disk->ev. * * CONTEXT: - * If @mask is non-zero must be called with bdev->bd_mutex held. + * If @mask is non-zero must be called with disk->open_mutex held. */ void disk_flush_events(struct gendisk *disk, unsigned int mask) { diff --git a/block/partitions/core.c b/block/partitions/core.c index 1a7558917c47d6..60388a41ff92a3 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -282,7 +282,7 @@ struct device_type part_type = { }; /* - * Must be called either with bd_mutex held, before a disk can be opened or + * Must be called either with open_mutex held, before a disk can be opened or * after all disk users are gone. */ void delete_partition(struct block_device *part) @@ -308,7 +308,7 @@ static ssize_t whole_disk_show(struct device *dev, static DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL); /* - * Must be called either with bd_mutex held, before a disk can be opened or + * Must be called either with open_mutex held, before a disk can be opened or * after all disk users are gone. */ static struct block_device *add_partition(struct gendisk *disk, int partno, @@ -440,15 +440,15 @@ int bdev_add_partition(struct block_device *bdev, int partno, { struct block_device *part; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); if (partition_overlaps(bdev->bd_disk, start, length, -1)) { - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return -EBUSY; } part = add_partition(bdev->bd_disk, partno, start, length, ADDPART_FLAG_NONE, NULL); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return PTR_ERR_OR_ZERO(part); } @@ -461,8 +461,7 @@ int bdev_del_partition(struct block_device *bdev, int partno) if (!part) return -ENXIO; - mutex_lock(&part->bd_mutex); - mutex_lock_nested(&bdev->bd_mutex, 1); + mutex_lock(&bdev->bd_disk->open_mutex); ret = -EBUSY; if (part->bd_openers) @@ -474,8 +473,7 @@ int bdev_del_partition(struct block_device *bdev, int partno) delete_partition(part); ret = 0; out_unlock: - mutex_unlock(&bdev->bd_mutex); - mutex_unlock(&part->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); bdput(part); return ret; } @@ -490,8 +488,7 @@ int bdev_resize_partition(struct block_device *bdev, int partno, if (!part) return -ENXIO; - mutex_lock(&part->bd_mutex); - mutex_lock_nested(&bdev->bd_mutex, 1); + mutex_lock(&bdev->bd_disk->open_mutex); ret = -EINVAL; if (start != part->bd_start_sect) goto out_unlock; @@ -504,8 +501,7 @@ int bdev_resize_partition(struct block_device *bdev, int partno, ret = 0; out_unlock: - mutex_unlock(&part->bd_mutex); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); bdput(part); return ret; } diff --git a/drivers/block/loop.c b/drivers/block/loop.c index a370cde3ddd49a..f5eb70a90ed067 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -651,9 +651,9 @@ static void loop_reread_partitions(struct loop_device *lo, { int rc; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); rc = bdev_disk_changed(bdev, false); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); if (rc) pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n", __func__, lo->lo_number, lo->lo_file_name, rc); @@ -746,7 +746,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, mutex_unlock(&lo->lo_mutex); /* * We must drop file reference outside of lo_mutex as dropping - * the file ref can take bd_mutex which creates circular locking + * the file ref can take open_mutex which creates circular locking * dependency. */ fput(old_file); @@ -1259,7 +1259,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) mutex_unlock(&lo->lo_mutex); if (partscan) { /* - * bd_mutex has been held already in release path, so don't + * open_mutex has been held already in release path, so don't * acquire it if this function is called in such case. * * If the reread partition isn't from release path, lo_refcnt @@ -1267,10 +1267,10 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) * current holder is released. */ if (!release) - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); err = bdev_disk_changed(bdev, false); if (!release) - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); if (err) pr_warn("%s: partition scan of loop%d failed (rc=%d)\n", __func__, lo_number, err); @@ -1297,7 +1297,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) /* * Need not hold lo_mutex to fput backing file. Calling fput holding * lo_mutex triggers a circular lock dependency possibility warning as - * fput can take bd_mutex which is usually taken before lo_mutex. + * fput can take open_mutex which is usually taken before lo_mutex. */ if (filp) fput(filp); diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index e1c6798889f48a..fbab2ce7dfa1a5 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -2163,7 +2163,7 @@ static void blkfront_closing(struct blkfront_info *info) return; } - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); if (bdev->bd_openers) { xenbus_dev_error(xbdev, -EBUSY, @@ -2174,7 +2174,7 @@ static void blkfront_closing(struct blkfront_info *info) xenbus_frontend_closed(xbdev); } - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); bdput(bdev); } @@ -2531,7 +2531,7 @@ static int blkfront_remove(struct xenbus_device *xbdev) * isn't closed yet, we let release take care of it. */ - mutex_lock(&bdev->bd_mutex); + mutex_lock(&disk->open_mutex); info = disk->private_data; dev_warn(disk_to_dev(disk), @@ -2546,7 +2546,7 @@ static int blkfront_remove(struct xenbus_device *xbdev) mutex_unlock(&blkfront_mutex); } - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&disk->open_mutex); bdput(bdev); return 0; diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index cf8deecc39efbc..b3bf544493d340 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1781,24 +1781,24 @@ static ssize_t reset_store(struct device *dev, zram = dev_to_zram(dev); bdev = zram->disk->part0; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); /* Do not reset an active device or claimed device */ if (bdev->bd_openers || zram->claim) { - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return -EBUSY; } /* From now on, anyone can't open /dev/zram[0-9] */ zram->claim = true; - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); /* Make sure all the pending I/O are finished */ fsync_bdev(bdev); zram_reset_device(zram); - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); zram->claim = false; - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return len; } @@ -1808,7 +1808,7 @@ static int zram_open(struct block_device *bdev, fmode_t mode) int ret = 0; struct zram *zram; - WARN_ON(!mutex_is_locked(&bdev->bd_mutex)); + WARN_ON(!mutex_is_locked(&bdev->bd_disk->open_mutex)); zram = bdev->bd_disk->private_data; /* zram was claimed to reset so open request fails */ @@ -1982,14 +1982,14 @@ static int zram_remove(struct zram *zram) { struct block_device *bdev = zram->disk->part0; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); if (bdev->bd_openers || zram->claim) { - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return -EBUSY; } zram->claim = true; - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); zram_debugfs_unregister(zram); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 419a7e8281ee3a..74c411911b6eac 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -112,7 +112,7 @@ struct zram { /* * zram is claimed so open request will be failed */ - bool claim; /* Protected by bdev->bd_mutex */ + bool claim; /* Protected by disk->open_mutex */ struct file *backing_dev; #ifdef CONFIG_ZRAM_WRITEBACK spinlock_t wb_limit_lock; diff --git a/drivers/md/md.h b/drivers/md/md.h index fb7eab58cfd517..a88086d4110c24 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -395,10 +395,10 @@ struct mddev { * that we are never stopping an array while it is open. * 'reconfig_mutex' protects all other reconfiguration. * These locks are separate due to conflicting interactions - * with bdev->bd_mutex. + * with disk->open_mutex. * Lock ordering is: - * reconfig_mutex -> bd_mutex - * bd_mutex -> open_mutex: e.g. __blkdev_get -> md_open + * reconfig_mutex -> disk->open_mutex + * disk->open_mutex -> open_mutex: e.g. __blkdev_get -> md_open */ struct mutex open_mutex; struct mutex reconfig_mutex; diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index a9698fba9b76ce..c93a46a38085bb 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -109,9 +109,9 @@ int dasd_scan_partitions(struct dasd_block *block) return -ENODEV; } - mutex_lock(&bdev->bd_mutex); + mutex_lock(&block->gdp->open_mutex); rc = bdev_disk_changed(bdev, false); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&block->gdp->open_mutex); if (rc) DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, rc %d", rc); @@ -145,9 +145,9 @@ void dasd_destroy_partitions(struct dasd_block *block) bdev = block->bdev; block->bdev = NULL; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); blk_drop_partitions(bdev); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */ blkdev_put(bdev, FMODE_READ); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index ed0b1bb99f0832..dc79d2e0e9dba9 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1400,7 +1400,7 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt) * In the latter case @inode and @filp carry an abridged amount * of information as noted above. * - * Locking: called with bdev->bd_mutex held. + * Locking: called with bdev->bd_disk->open_mutex held. **/ static int sd_open(struct block_device *bdev, fmode_t mode) { @@ -1476,7 +1476,7 @@ static int sd_open(struct block_device *bdev, fmode_t mode) * Note: may block (uninterruptible) if error recovery is underway * on this disk. * - * Locking: called with bdev->bd_mutex held. + * Locking: called with bdev->bd_disk->open_mutex held. **/ static void sd_release(struct gendisk *disk, fmode_t mode) { diff --git a/fs/block_dev.c b/fs/block_dev.c index 691eef20a7ced7..4113a27ad9e72d 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -891,7 +891,6 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) mapping_set_gfp_mask(&inode->i_data, GFP_USER); bdev = I_BDEV(inode); - mutex_init(&bdev->bd_mutex); mutex_init(&bdev->bd_fsfreeze_mutex); spin_lock_init(&bdev->bd_size_lock); bdev->bd_disk = disk; @@ -1150,7 +1149,7 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk) struct bd_holder_disk *holder; int ret = 0; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); WARN_ON_ONCE(!bdev->bd_holder); @@ -1195,7 +1194,7 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk) out_free: kfree(holder); out_unlock: - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); return ret; } EXPORT_SYMBOL_GPL(bd_link_disk_holder); @@ -1214,7 +1213,7 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk) { struct bd_holder_disk *holder; - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); holder = bd_find_holder_disk(bdev, disk); @@ -1226,7 +1225,7 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk) kfree(holder); } - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); } EXPORT_SYMBOL_GPL(bd_unlink_disk_holder); #endif @@ -1238,7 +1237,7 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) struct gendisk *disk = bdev->bd_disk; int ret; - lockdep_assert_held(&bdev->bd_mutex); + lockdep_assert_held(&disk->open_mutex); clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); @@ -1318,14 +1317,10 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode) goto done; whole = bdgrab(disk->part0); - mutex_lock_nested(&whole->bd_mutex, 1); ret = blkdev_get_whole(whole, mode); - if (ret) { - mutex_unlock(&whole->bd_mutex); + if (ret) goto out_put_whole; - } whole->bd_part_count++; - mutex_unlock(&whole->bd_mutex); ret = -ENXIO; if (!(disk->flags & GENHD_FL_UP) || !bdev_nr_sectors(part)) @@ -1435,7 +1430,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) disk_block_events(disk); - mutex_lock(&bdev->bd_mutex); + mutex_lock(&disk->open_mutex); if (bdev_is_partition(bdev)) ret = blkdev_get_part(bdev, mode); else @@ -1458,7 +1453,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) unblock_events = false; } } - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&disk->open_mutex); if (unblock_events) disk_unblock_events(disk); @@ -1467,7 +1462,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) abort_claiming: if (mode & FMODE_EXCL) bd_abort_claiming(bdev, holder); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&disk->open_mutex); disk_unblock_events(disk); put_blkdev: blkdev_put_no_open(bdev); @@ -1547,7 +1542,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) struct gendisk *disk = bdev->bd_disk; struct block_device *victim = NULL; - mutex_lock_nested(&bdev->bd_mutex, for_part); if (for_part) bdev->bd_part_count--; @@ -1562,7 +1556,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) if (!bdev_is_partition(bdev) && disk->fops->release) disk->fops->release(disk, mode); - mutex_unlock(&bdev->bd_mutex); if (victim) { __blkdev_put(victim, mode, 1); bdput(victim); @@ -1583,15 +1576,14 @@ void blkdev_put(struct block_device *bdev, fmode_t mode) if (bdev->bd_openers == 1) sync_blockdev(bdev); - mutex_lock(&bdev->bd_mutex); - + mutex_lock(&disk->open_mutex); if (mode & FMODE_EXCL) { struct block_device *whole = bdev_whole(bdev); bool bdev_free; /* * Release a claim on the device. The holder fields - * are protected with bdev_lock. bd_mutex is to + * are protected with bdev_lock. open_mutex is to * synchronize disk_holder unlinking. */ spin_lock(&bdev_lock); @@ -1622,9 +1614,10 @@ void blkdev_put(struct block_device *bdev, fmode_t mode) * from userland - e.g. eject(1). */ disk_flush_events(disk, DISK_EVENT_MEDIA_CHANGE); - mutex_unlock(&bdev->bd_mutex); __blkdev_put(bdev, mode, 0); + mutex_unlock(&disk->open_mutex); + blkdev_put_no_open(bdev); } EXPORT_SYMBOL(blkdev_put); @@ -1917,10 +1910,10 @@ void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg) old_inode = inode; bdev = I_BDEV(inode); - mutex_lock(&bdev->bd_mutex); + mutex_lock(&bdev->bd_disk->open_mutex); if (bdev->bd_openers) func(bdev, arg); - mutex_unlock(&bdev->bd_mutex); + mutex_unlock(&bdev->bd_disk->open_mutex); spin_lock(&blockdev_superblock->s_inode_list_lock); } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bc3b33efddc569..30fb9084ac145b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1246,7 +1246,7 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, lockdep_assert_held(&uuid_mutex); /* * The device_list_mutex cannot be taken here in case opening the - * underlying device takes further locks like bd_mutex. + * underlying device takes further locks like open_mutex. * * We also don't need the lock here as this is called during mount and * exclusion is provided by uuid_mutex diff --git a/fs/super.c b/fs/super.c index 8c1baca35c160b..90b68352a26e14 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1276,9 +1276,9 @@ int get_tree_bdev(struct fs_context *fc, } /* - * s_umount nests inside bd_mutex during + * s_umount nests inside open_mutex during * __invalidate_device(). blkdev_put() acquires - * bd_mutex and can't be called under s_umount. Drop + * open_mutex and can't be called under s_umount. Drop * s_umount temporarily. This is safe as we're * holding an active reference. */ @@ -1351,9 +1351,9 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, } /* - * s_umount nests inside bd_mutex during + * s_umount nests inside open_mutex during * __invalidate_device(). blkdev_put() acquires - * bd_mutex and can't be called under s_umount. Drop + * open_mutex and can't be called under s_umount. Drop * s_umount temporarily. This is safe as we're * holding an active reference. */ diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index db026b6ec15ab7..a09660671fa47e 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -29,7 +29,6 @@ struct block_device { int bd_openers; struct inode * bd_inode; /* will die */ struct super_block * bd_super; - struct mutex bd_mutex; /* open/close mutex */ void * bd_claiming; struct device bd_device; void * bd_holder; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index f364619092cca0..02ea04144ece7b 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -153,6 +153,9 @@ struct gendisk { unsigned long state; #define GD_NEED_PART_SCAN 0 #define GD_READ_ONLY 1 + + struct mutex open_mutex; /* open/close mutex */ + struct kobject *slave_dir; struct timer_rand_state *random; From patchwork Tue Mar 30 16:17:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CDB4C433E0 for ; Tue, 30 Mar 2021 16:19:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 354D9619C7 for ; Tue, 30 Mar 2021 16:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232395AbhC3QSn (ORCPT ); Tue, 30 Mar 2021 12:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbhC3QSM (ORCPT ); Tue, 30 Mar 2021 12:18:12 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D78C061574; Tue, 30 Mar 2021 09:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=clkaBMHqFEToWoG3RDL6mkbv+bLYy50wIeoj77viXRA=; b=c3AcMH2v35AJV6QxSMjXVIjS3c xMGVOnpEA1YpVnz6WJU3lezlXMW0RilNWPUgV7xmP2S1UmvywCdmpnhUngNhTlr593ZbiaZt3kOXx 1tRbtPGxTu4NTDfMciddtxSaYmSgx09AvUYjZQsuuZs5udhMxbC9Oq39h8diYJ6rgLeBT4HtlVi5D idX2moOu2jO7BFNsBTBUyl9O2H0t0Sg0wgpsIH9CA0Duv4evm4Fvv43krUoIxBIdU9bgLow67TYM4 BAAhZV597MjoXiqzCYf2+FyFVjBaKBUAkszJTV+1NJC9Mejda6jwlNMoKNIcDJoIeWy/lJUStHbNL BOuCjqGA==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH4A-008aMG-LY; Tue, 30 Mar 2021 16:18:07 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 13/15] block: move bd_part_count to struct gendisk Date: Tue, 30 Mar 2021 18:17:25 +0200 Message-Id: <20210330161727.2297292-14-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The bd_part_count value only makes sense for whole devices, so move it to struct gendisk and give it a more descriptive name. Signed-off-by: Christoph Hellwig --- block/partitions/core.c | 2 +- fs/block_dev.c | 4 ++-- include/linux/blk_types.h | 3 --- include/linux/genhd.h | 1 + 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 60388a41ff92a3..162b9b35c53171 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -527,7 +527,7 @@ int blk_drop_partitions(struct block_device *bdev) struct disk_part_iter piter; struct block_device *part; - if (bdev->bd_part_count) + if (bdev->bd_disk->open_partitions) return -EBUSY; sync_blockdev(bdev); diff --git a/fs/block_dev.c b/fs/block_dev.c index ade5a180ff62d3..6d7e3bd7cb7ce3 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1339,7 +1339,7 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode) if (!(disk->flags & GENHD_FL_UP) || !bdev_nr_sectors(part)) goto out_blkdev_put; - whole->bd_part_count++; + disk->open_partitions++; set_init_blocksize(part); if (part->bd_bdi == &noop_backing_dev_info) part->bd_bdi = bdi_get(disk->queue->backing_dev_info); @@ -1361,7 +1361,7 @@ static void blkdev_put_part(struct block_device *part, fmode_t mode) if (--part->bd_openers) return; blkdev_flush_mapping(part); - whole->bd_part_count--; + whole->bd_disk->open_partitions--; blkdev_put_whole(whole, mode); bdput(whole); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index a09660671fa47e..fd3860d18d7ed7 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -39,9 +39,6 @@ struct block_device { #endif struct kobject *bd_holder_dir; u8 bd_partno; - /* number of times partitions within this device have been opened. */ - unsigned bd_part_count; - spinlock_t bd_size_lock; /* for bd_inode->i_size updates */ struct gendisk * bd_disk; struct backing_dev_info *bd_bdi; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 02ea04144ece7b..146d2dafdccd58 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -155,6 +155,7 @@ struct gendisk { #define GD_READ_ONLY 1 struct mutex open_mutex; /* open/close mutex */ + unsigned open_partitions; /* number of open partitions */ struct kobject *slave_dir; From patchwork Tue Mar 30 16:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 412145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81D2EC433F1 for ; Tue, 30 Mar 2021 16:19:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5487B61953 for ; Tue, 30 Mar 2021 16:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbhC3QSs (ORCPT ); Tue, 30 Mar 2021 12:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232335AbhC3QSR (ORCPT ); Tue, 30 Mar 2021 12:18:17 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD195C061574; Tue, 30 Mar 2021 09:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=zC+4YJD9ldRriFlatLe0IwHAqCBRKAl162mGz5hi+WE=; b=As1MJbmYPQeQeXEW/C51TJx2dv RN0cnFsE4oLAZbMe7+7NaABrulhuQ2D0ljxdBjVf6h47CrUjNows7IRdbshExLiy0DRqTk1GXZFPM dGLsTPhIvowq9WXJ0g4d8pNo97Ooj9AON4bolv9yOqva7Shk5RS9tAxcnTP4XsCLVvle6hFOTX6eF velMXMgXwTIQvAI2nqCjb4Bob8J7KfRq3aGqKkUA4zYlgpO6P9Shi7cshbQNsHOzZ7nFLlv49rKwQ QBTOZCuMrNQEYpssQEJbSVRgTIjeIBsjfvdvhcCrh53AprG/HKID8WsIws14wKGooNi7ZxYn5r69a fCrdYebw==; Received: from [185.12.131.45] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lRH4G-008aNH-D0; Tue, 30 Mar 2021 16:18:12 +0000 From: Christoph Hellwig To: Jens Axboe , Song Liu Cc: Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Mo?= =?utf-8?q?nn=C3=A9?= , Minchan Kim , Nitin Gupta , Stefan Haberland , Jan Hoeppner , linux-block@vger.kernel.org, linux-raid@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 15/15] block: remove bdget_disk Date: Tue, 30 Mar 2021 18:17:27 +0200 Message-Id: <20210330161727.2297292-16-hch@lst.de> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210330161727.2297292-1-hch@lst.de> References: <20210330161727.2297292-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Just opencode the xa_load in the callers, as none of them actually needs a reference to the bdev. Signed-off-by: Christoph Hellwig --- block/genhd.c | 35 +++++------------------------------ block/partitions/core.c | 25 ++++++++++++------------- include/linux/genhd.h | 1 - 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 232c8420b04973..f0d4cf80dac1ea 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -778,32 +778,6 @@ void blk_request_module(dev_t devt) request_module("block-major-%d", MAJOR(devt)); } -/** - * bdget_disk - do bdget() by gendisk and partition number - * @disk: gendisk of interest - * @partno: partition number - * - * Find partition @partno from @disk, do bdget() on it. - * - * CONTEXT: - * Don't care. - * - * RETURNS: - * Resulting block_device on success, NULL on failure. - */ -struct block_device *bdget_disk(struct gendisk *disk, int partno) -{ - struct block_device *bdev = NULL; - - rcu_read_lock(); - bdev = xa_load(&disk->part_tbl, partno); - if (bdev && !bdgrab(bdev)) - bdev = NULL; - rcu_read_unlock(); - - return bdev; -} - /* * print a full list of all partitions - intended for places where the root * filesystem can't be mounted and thus to give the victim some idea of what @@ -1328,13 +1302,14 @@ module_init(proc_genhd_init); dev_t part_devt(struct gendisk *disk, u8 partno) { - struct block_device *part = bdget_disk(disk, partno); + struct block_device *part; dev_t devt = 0; - if (part) { + rcu_read_lock(); + part = xa_load(&disk->part_tbl, partno); + if (part) devt = part->bd_dev; - bdput(part); - } + rcu_read_unlock(); return devt; } diff --git a/block/partitions/core.c b/block/partitions/core.c index 162b9b35c53171..00e425c668a5f8 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -322,6 +322,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, const char *dname; int err; + lockdep_assert_held(&disk->open_mutex); + /* * Partitions are not supported on zoned block devices that are used as * such. @@ -454,14 +456,13 @@ int bdev_add_partition(struct block_device *bdev, int partno, int bdev_del_partition(struct block_device *bdev, int partno) { - struct block_device *part; - int ret; - - part = bdget_disk(bdev->bd_disk, partno); - if (!part) - return -ENXIO; + struct block_device *part = NULL; + int ret = -ENXIO; mutex_lock(&bdev->bd_disk->open_mutex); + part = xa_load(&bdev->bd_disk->part_tbl, partno); + if (!part) + goto out_unlock; ret = -EBUSY; if (part->bd_openers) @@ -474,21 +475,20 @@ int bdev_del_partition(struct block_device *bdev, int partno) ret = 0; out_unlock: mutex_unlock(&bdev->bd_disk->open_mutex); - bdput(part); return ret; } int bdev_resize_partition(struct block_device *bdev, int partno, sector_t start, sector_t length) { - struct block_device *part; - int ret = 0; + struct block_device *part = NULL; + int ret = -ENXIO; - part = bdget_disk(bdev->bd_disk, partno); + mutex_lock(&bdev->bd_disk->open_mutex); + part = xa_load(&bdev->bd_disk->part_tbl, partno); if (!part) - return -ENXIO; + goto out_unlock; - mutex_lock(&bdev->bd_disk->open_mutex); ret = -EINVAL; if (start != part->bd_start_sect) goto out_unlock; @@ -502,7 +502,6 @@ int bdev_resize_partition(struct block_device *bdev, int partno, ret = 0; out_unlock: mutex_unlock(&bdev->bd_disk->open_mutex); - bdput(part); return ret; } diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 819366811349eb..674fc0761105bc 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -241,7 +241,6 @@ static inline void add_disk_no_queue_reg(struct gendisk *disk) } extern void del_gendisk(struct gendisk *gp); -extern struct block_device *bdget_disk(struct gendisk *disk, int partno); void set_disk_ro(struct gendisk *disk, bool read_only);