From patchwork Thu Jul 22 07:53:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393377 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 4627AC63793 for ; Thu, 22 Jul 2021 07:55:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 286C961279 for ; Thu, 22 Jul 2021 07:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbhGVHOZ (ORCPT ); Thu, 22 Jul 2021 03:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbhGVHOZ (ORCPT ); Thu, 22 Jul 2021 03:14:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C32E9C061575; Thu, 22 Jul 2021 00:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=mbIbeGmh13wwxz96O7sSmFBmcvhWkF3OxLu0Zg4jK6s=; b=OuSUWbtjsxh0HrMjAQs03/0G1V S5b9reiJrj/rnbHgr330u5wCds43a2NYcsSv5dRjEDOTcBlGpzYTAwoDqIlZRcfBGcTYQXQBg1mod C5jJQIT65rSfbn/RyWeLSVzeX9WIv6Qpci9y4G7EwViZLNLaeE5bq+V+c/bqG6DW/e7poMNKEe5uO zv1+VJ3evRlUAI2RE6EWKiLNIz/ceUHsrLSqarq6K0jolR9q5Zc2hNo9Y0Q85JvGWIdLrhIGM8BfB djKZSKny2/DmWGRk+uRL6B0g1ZAPkhaj7SpVE2AbmhyS66BFdDJcZRAAyHzz6mgzDsAGuWlXPDVeY u9jRefSw==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TXH-00A1F9-S5; Thu, 22 Jul 2021 07:54:33 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, Ming Lei Subject: [PATCH 1/9] block: delay freeing the gendisk Date: Thu, 22 Jul 2021 09:53:54 +0200 Message-Id: <20210722075402.983367-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org blkdev_get_no_open acquires a reference to the block_device through the block device inode and then tries to acquire a device model reference to the gendisk. But at this point the disk migh already be freed (although the race is free). Fix this by only freeing the gendisk from the whole device bdevs ->free_inode callback as well. Fixes: 22ae8ce8b892 ("block: simplify bdev/disk lookup in blkdev_get") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik Reviewed-by: Ming Lei --- block/genhd.c | 3 +-- fs/block_dev.c | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index af4d2ab4a633..298ee78c1bda 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1079,10 +1079,9 @@ static void disk_release(struct device *dev) disk_release_events(disk); kfree(disk->random); xa_destroy(&disk->part_tbl); - bdput(disk->part0); if (test_bit(GD_QUEUE_REF, &disk->state) && disk->queue) blk_put_queue(disk->queue); - kfree(disk); + bdput(disk->part0); /* frees the disk */ } struct class block_class = { .name = "block", diff --git a/fs/block_dev.c b/fs/block_dev.c index 0c424a0cadaa..9ef4f1fc2cb0 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -812,6 +812,8 @@ static void bdev_free_inode(struct inode *inode) free_percpu(bdev->bd_stats); kfree(bdev->bd_meta_info); + if (!bdev_is_partition(bdev)) + kfree(bdev->bd_disk); kmem_cache_free(bdev_cachep, BDEV_I(inode)); } From patchwork Thu Jul 22 07:53:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393379 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 128BEC63793 for ; Thu, 22 Jul 2021 07:55:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E51AA61221 for ; Thu, 22 Jul 2021 07:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbhGVHPW (ORCPT ); Thu, 22 Jul 2021 03:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbhGVHPW (ORCPT ); Thu, 22 Jul 2021 03:15:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBB1AC061575; Thu, 22 Jul 2021 00:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=iItEmE7p+vg87/aZAxmFjmCUgcaSsiegChORg9UMdI8=; b=I6YWkxh2KKyhfhb9Zi/5AR3CPN ASEEqgrVklAX6d4GnWsTy3hIclmGy2cCrSZPyBj64T8OfpGfW8a1sBurSvk+WrcmujlyZK9TT1KWZ Bc/3Xu2vu/fc/jx21Va4YRzcbql4ICtRehNZtyDyL4/c3gy1IJOOi2zTUoXA6oH0owvtciXOSHST0 w/j/sZ1K+XW1v5tbqKRsXeApOFL8tFr44QpYWtmmjD9MpjM519Kxe9wq42Xs/YLKsXKeMLs8xgEE0 ZCufvnVIBjq9NGKxJfWV4QtjNyZXjMiHWxa9G4vEjiY5P1ERiSODKFS1ugysR9tyY4g8YR3MmKsS4 HRDL1b0A==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TXb-00A1Ft-6U; Thu, 22 Jul 2021 07:54:51 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, Ming Lei Subject: [PATCH 2/9] block: assert the locking state in delete_partition Date: Thu, 22 Jul 2021 09:53:55 +0200 Message-Id: <20210722075402.983367-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add a lockdep assert instead of the outdated locking comment. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik Reviewed-by: Ming Lei Reviewed-by: Chaitanya Kulkarni --- block/partitions/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 4230d4f71879..9902b1635b7d 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -281,12 +281,10 @@ struct device_type part_type = { .uevent = part_uevent, }; -/* - * Must be called either with open_mutex held, before a disk can be opened or - * after all disk users are gone. - */ static void delete_partition(struct block_device *part) { + lockdep_assert_held(&part->bd_disk->open_mutex); + fsync_bdev(part); __invalidate_device(part, true); From patchwork Thu Jul 22 07:53:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393381 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=ham 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 DD2BDC63793 for ; Thu, 22 Jul 2021 07:56:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFEC861283 for ; Thu, 22 Jul 2021 07:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230144AbhGVHPo (ORCPT ); Thu, 22 Jul 2021 03:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbhGVHPn (ORCPT ); Thu, 22 Jul 2021 03:15:43 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A220C061575; Thu, 22 Jul 2021 00:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=MrfK/pd5lPQFMuYt8109e1DhxgFkWG+yvxPoVqeqKHA=; b=pRwAsf64NNSNbBkDc8qMhyeiTn GSacmQ+fEufEU/3Yaf8nuJw0fexDhSeLxbi2RNLjh88L78e6QvSOD6RTXhc7yRqUp7URyjH0r5Vr5 yDLaccNUna4LzsdV6v20U/I0rqpY32FO+uhnWv8qlUzd9bHPO8amw3ijNmMZ91QSCmDSvIHnHvZEF zKacZMSEvTc45Y7p+VuvgdNTCN2aL0yToAP9QZA4KROXJ7mJz6leldCyom0tDjSPYnokVZHRhd5eb qM/Ao33Wlgh3R9r+URaAeenGE2YMts9sC1cfcOFo1O0VH6/h3KHtVt8jIAjrd4tlCu8oCXoV0hnVM VypbQzEQ==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TXz-00A1I8-Tm; Thu, 22 Jul 2021 07:55:31 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 3/9] block: unhash the whole device inode earlier Date: Thu, 22 Jul 2021 09:53:56 +0200 Message-Id: <20210722075402.983367-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Unhash the whole device inode early in del_gendisk. This allows to remove the first GENHD_FL_UP check in the open path as we simply won't find a just removed inode. The second non-racy check after taking open_mutex is still kept. Signed-off-by: Christoph Hellwig --- block/genhd.c | 7 +------ fs/block_dev.c | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 298ee78c1bda..716f5ca479ad 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -585,6 +585,7 @@ void del_gendisk(struct gendisk *disk) disk_del_events(disk); mutex_lock(&disk->open_mutex); + remove_inode_hash(disk->part0->bd_inode); disk->flags &= ~GENHD_FL_UP; blk_drop_partitions(disk); mutex_unlock(&disk->open_mutex); @@ -592,12 +593,6 @@ void del_gendisk(struct gendisk *disk) fsync_bdev(disk->part0); __invalidate_device(disk->part0, true); - /* - * Unhash the bdev inode for this device so that it can't be looked - * up any more even if openers still hold references to it. - */ - remove_inode_hash(disk->part0->bd_inode); - set_capacity(disk, 0); if (!(disk->flags & GENHD_FL_HIDDEN)) { diff --git a/fs/block_dev.c b/fs/block_dev.c index 9ef4f1fc2cb0..932f4034ad66 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1340,7 +1340,7 @@ struct block_device *blkdev_get_no_open(dev_t dev) disk = bdev->bd_disk; if (!kobject_get_unless_zero(&disk_to_dev(disk)->kobj)) goto bdput; - if ((disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP) + if (disk->flags & GENHD_FL_HIDDEN) goto put_disk; if (!try_module_get(bdev->bd_disk->fops->owner)) goto put_disk; From patchwork Thu Jul 22 07:53:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393383 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 6E6B4C6377D for ; Thu, 22 Jul 2021 07:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F3AE610CC for ; Thu, 22 Jul 2021 07:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230313AbhGVHQL (ORCPT ); Thu, 22 Jul 2021 03:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhGVHQL (ORCPT ); Thu, 22 Jul 2021 03:16:11 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B94C061575; Thu, 22 Jul 2021 00:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=EgPA2g5HAtaj6T3/K33bbshvzBgDm7uDiBhDmQ9TnQ4=; b=vbuupET/tRtwz0C+qHCZRlbcVK aitT88opultPqb5dyI6ooq+DZawvoKEcYTDpSpHhcCo5rxSVc0p/Be0H/j0ohw4wwoEZHgH/agJkH SuT9XGaBsWtvwTGiMmbbychXzOerpPdWXPegWAU2SpPK8u1NxmqFJ9TmV1NXMWZgzazJDFuuhTfUu mvBChB1ukV+IrJkyNEf9XV4J+X37keXqc9uX4P3PpPBxrf6JI1M2MfcObMdsykWrM7p3i/YUk8L7X qi7onvZfYrbYz49eD9dvFu6Iw/Bi1huhLNTBygNPb2jj2Wurgp1B7qPKnuOlT+I48GmpINvof7xXv S3pUNiHw==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TYj-00A1LH-85; Thu, 22 Jul 2021 07:56:10 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 4/9] block: allocate bd_meta_info later in add_partitions Date: Thu, 22 Jul 2021 09:53:57 +0200 Message-Id: <20210722075402.983367-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move the allocation of bd_meta_info after initializing the struct device to avoid the special bdput error handling path. Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei --- block/partitions/core.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 9902b1635b7d..09c58a110a89 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -356,13 +356,6 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, bdev->bd_start_sect = start; bdev_set_nr_sectors(bdev, len); - if (info) { - err = -ENOMEM; - bdev->bd_meta_info = kmemdup(info, sizeof(*info), GFP_KERNEL); - if (!bdev->bd_meta_info) - goto out_bdput; - } - pdev = &bdev->bd_device; dname = dev_name(ddev); if (isdigit(dname[strlen(dname) - 1])) @@ -386,6 +379,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, } pdev->devt = devt; + if (info) { + err = -ENOMEM; + bdev->bd_meta_info = kmemdup(info, sizeof(*info), GFP_KERNEL); + if (!bdev->bd_meta_info) + goto out_put; + } + /* delay uevent until 'holders' subdir is created */ dev_set_uevent_suppress(pdev, 1); err = device_add(pdev); @@ -415,9 +415,6 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, kobject_uevent(&pdev->kobj, KOBJ_ADD); return bdev; -out_bdput: - bdput(bdev); - return ERR_PTR(err); out_del: kobject_put(bdev->bd_holder_dir); device_del(pdev); From patchwork Thu Jul 22 07:53:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393385 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=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 6F246C63798 for ; Thu, 22 Jul 2021 07:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5289C61221 for ; Thu, 22 Jul 2021 07:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbhGVHQf (ORCPT ); Thu, 22 Jul 2021 03:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhGVHQe (ORCPT ); Thu, 22 Jul 2021 03:16:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2191AC061575; Thu, 22 Jul 2021 00:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=yuP/pCtnR11GZVGb5kljqrI8PYv0AD14UlcUVTme0ic=; b=CUk8GybL+SSu+eLD04j1uGD6dK CLIepPp7G7A9/riuWxoqZEEjBFh+iqv1RDiznW5b6aKAlSfsJNUANyXdlmjm2lLgqtLRettS2EjVc +ecmV01R8ccn3u53r24r2nvtmk6Ri5ApO0DT/T1YgRk0Kd6C/cLnanbJlSLVVcbVAn+3Dja7yOqe8 6Vo146yOA/KlircRkugs6jFd3ZLJrqlVJr0Lk+Trs+HMOmDUnTl8j/iCVT0+Kdu4kVwSQZjwjQqwI 777iQncVsAwtHxAyH0Vlow+dEV0tGhkMUiFNO5HTKOCCLcN/mjqyxDhrmDSSzfvV3jcLvsvXCQ6Ph oO1j/2VA==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TZC-00A1Mt-Lh; Thu, 22 Jul 2021 07:56:36 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 5/9] block: change the refcounting for partitions Date: Thu, 22 Jul 2021 09:53:58 +0200 Message-Id: <20210722075402.983367-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of acquiring an inode reference on open make sure partitions always hold device model references to the disk while alive, and switch open to grab only a device model reference to the opened block device. If that is a partition the disk reference is transitively held by the partition already. --- block/partitions/core.c | 9 ++++++- fs/block_dev.c | 60 ++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 09c58a110a89..4f7a1a9cd544 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -261,6 +261,7 @@ static void part_release(struct device *dev) { if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR) blk_free_ext_minor(MINOR(dev->devt)); + put_disk(dev_to_bdev(dev)->bd_disk); bdput(dev_to_bdev(dev)); } @@ -349,9 +350,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, if (xa_load(&disk->part_tbl, partno)) return ERR_PTR(-EBUSY); + /* ensure we always have a reference to the whole disk */ + get_device(disk_to_dev(disk)); + + err = -ENOMEM; bdev = bdev_alloc(disk, partno); if (!bdev) - return ERR_PTR(-ENOMEM); + goto out_put_disk; bdev->bd_start_sect = start; bdev_set_nr_sectors(bdev, len); @@ -420,6 +425,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, device_del(pdev); out_put: put_device(pdev); +out_put_disk: + put_disk(disk); return ERR_PTR(err); } diff --git a/fs/block_dev.c b/fs/block_dev.c index 932f4034ad66..4a6c8c0a3bc9 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -921,16 +921,6 @@ void bdev_add(struct block_device *bdev, dev_t dev) insert_inode_hash(bdev->bd_inode); } -static struct block_device *bdget(dev_t dev) -{ - struct inode *inode; - - inode = ilookup(blockdev_superblock, dev); - if (!inode) - return NULL; - return &BDEV_I(inode)->bdev; -} - /** * bdgrab -- Grab a reference to an already referenced block device * @bdev: Block device to grab a reference to. @@ -1282,16 +1272,14 @@ static void blkdev_put_whole(struct block_device *bdev, fmode_t mode) static int blkdev_get_part(struct block_device *part, fmode_t mode) { struct gendisk *disk = part->bd_disk; - struct block_device *whole; int ret; if (part->bd_openers) goto done; - whole = bdgrab(disk->part0); - ret = blkdev_get_whole(whole, mode); + ret = blkdev_get_whole(bdev_whole(part), mode); if (ret) - goto out_put_whole; + return ret; ret = -ENXIO; if (!bdev_nr_sectors(part)) @@ -1306,9 +1294,7 @@ static int blkdev_get_part(struct block_device *part, fmode_t mode) return 0; out_blkdev_put: - blkdev_put_whole(whole, mode); -out_put_whole: - bdput(whole); + blkdev_put_whole(bdev_whole(part), mode); return ret; } @@ -1321,42 +1307,42 @@ static void blkdev_put_part(struct block_device *part, fmode_t mode) blkdev_flush_mapping(part); whole->bd_disk->open_partitions--; blkdev_put_whole(whole, mode); - bdput(whole); } struct block_device *blkdev_get_no_open(dev_t dev) { struct block_device *bdev; - struct gendisk *disk; + struct inode *inode; - bdev = bdget(dev); - if (!bdev) { + inode = ilookup(blockdev_superblock, dev); + if (!inode) { blk_request_module(dev); - bdev = bdget(dev); - if (!bdev) + inode = ilookup(blockdev_superblock, dev); + if (!inode) return NULL; } - disk = bdev->bd_disk; - if (!kobject_get_unless_zero(&disk_to_dev(disk)->kobj)) - goto bdput; - if (disk->flags & GENHD_FL_HIDDEN) - goto put_disk; - if (!try_module_get(bdev->bd_disk->fops->owner)) - goto put_disk; + /* switch from the inode reference to a device mode one: */ + bdev = &BDEV_I(inode)->bdev; + if (!kobject_get_unless_zero(&bdev->bd_device.kobj)) + bdev = NULL; + iput(inode); + + if (!bdev) + return NULL; + if ((bdev->bd_disk->flags & GENHD_FL_HIDDEN) || + !try_module_get(bdev->bd_disk->fops->owner)) { + put_device(&bdev->bd_device); + return NULL; + } + return bdev; -put_disk: - put_disk(disk); -bdput: - bdput(bdev); - return NULL; } void blkdev_put_no_open(struct block_device *bdev) { module_put(bdev->bd_disk->fops->owner); - put_disk(bdev->bd_disk); - bdput(bdev); + put_device(&bdev->bd_device); } /** From patchwork Thu Jul 22 07:53:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393387 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=ham 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 CFA57C63793 for ; Thu, 22 Jul 2021 07:57:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2C41610CC for ; Thu, 22 Jul 2021 07:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbhGVHRB (ORCPT ); Thu, 22 Jul 2021 03:17:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhGVHRB (ORCPT ); Thu, 22 Jul 2021 03:17:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ADDFC061575; Thu, 22 Jul 2021 00:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=UbJH2uNi4xkqJoAv1o4QkFE0/x91fO1Ho7MrY00dYvU=; b=iPLLDqNnV7HqcS3288oCAy4yaT Iz74S2WPO0/JG+8aSJ9VnCbfMAJCk3FlCzFzKEeFSqZfAakQ6ZwP1Gm30hjyPZKJnvbZvQF29ayzT VtoNbjR8gmMaqagp1y7LX8UjtZOjkSp3hnKmiMvjZGfFMvbMeMMOu5qOR1O9qRlJbx9RqJBuRBVMy 6Pbe6/8VrttSe7v/YQC1JRJkBygw7soq6C1fNTy2oZUoJxagVV8La8Ytj7o9fmkhkUj4FIUxFEAie ESy2mFUWznK9Nk9iBEfcbDWsbjQrTurOZU0/i7Utohfh5Kl+/G4XA8/H8faSKRsCEQFs8zmr8qbj9 2Lb5w1lw==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TZc-00A1Ow-BJ; Thu, 22 Jul 2021 07:56:59 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 6/9] btrfs: store a block_device in struct btrfs_ordered_extent Date: Thu, 22 Jul 2021 09:53:59 +0200 Message-Id: <20210722075402.983367-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Store the block device instead of the gendisk in the btrfs_ordered_extent structure intead of acquiring a reference to it later. Signed-off-by: Christoph Hellwig Reviewed-by: David Sterba --- fs/btrfs/inode.c | 2 +- fs/btrfs/ordered-data.c | 2 -- fs/btrfs/ordered-data.h | 3 +-- fs/btrfs/zoned.c | 12 ++++-------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8f60314c36c5..0117d867ecf8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2992,7 +2992,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) goto out; } - if (ordered_extent->disk) + if (ordered_extent->bdev) btrfs_rewrite_logical_zoned(ordered_extent); btrfs_free_io_failure_record(inode, start, end); diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 6eb41b7c0c84..5c0f8481e25e 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -190,8 +190,6 @@ static int __btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset entry->truncated_len = (u64)-1; entry->qgroup_rsv = ret; entry->physical = (u64)-1; - entry->disk = NULL; - entry->partno = (u8)-1; ASSERT(type == BTRFS_ORDERED_REGULAR || type == BTRFS_ORDERED_NOCOW || diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 566472004edd..b2d88aba8420 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -145,8 +145,7 @@ struct btrfs_ordered_extent { * command in a workqueue context */ u64 physical; - struct gendisk *disk; - u8 partno; + struct block_device *bdev; }; /* diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 297c0b1c0634..907c2cc45c9c 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1349,8 +1349,7 @@ void btrfs_record_physical_zoned(struct inode *inode, u64 file_offset, return; ordered->physical = physical; - ordered->disk = bio->bi_bdev->bd_disk; - ordered->partno = bio->bi_bdev->bd_partno; + ordered->bdev = bio->bi_bdev; btrfs_put_ordered_extent(ordered); } @@ -1362,18 +1361,16 @@ void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered) struct extent_map_tree *em_tree; struct extent_map *em; struct btrfs_ordered_sum *sum; - struct block_device *bdev; u64 orig_logical = ordered->disk_bytenr; u64 *logical = NULL; int nr, stripe_len; /* Zoned devices should not have partitions. So, we can assume it is 0 */ - ASSERT(ordered->partno == 0); - bdev = bdgrab(ordered->disk->part0); - if (WARN_ON(!bdev)) + ASSERT(!bdev_is_partition(ordered->bdev)); + if (WARN_ON(!ordered->bdev)) return; - if (WARN_ON(btrfs_rmap_block(fs_info, orig_logical, bdev, + if (WARN_ON(btrfs_rmap_block(fs_info, orig_logical, ordered->bdev, ordered->physical, &logical, &nr, &stripe_len))) goto out; @@ -1402,7 +1399,6 @@ void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered) out: kfree(logical); - bdput(bdev); } bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, From patchwork Thu Jul 22 07:54:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393409 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=ham 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 2BA3CC6377D for ; Thu, 22 Jul 2021 07:58:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DCF961221 for ; Thu, 22 Jul 2021 07:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbhGVHRb (ORCPT ); Thu, 22 Jul 2021 03:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhGVHRa (ORCPT ); Thu, 22 Jul 2021 03:17:30 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13652C061575; Thu, 22 Jul 2021 00:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=EgGhUx4yzqyD/GIVSazVe5S/qr/x3vPRj6RyCg05ODA=; b=jIMmVRX1yiPY9Gr1wUWJFRpX9B pIUx2lqSAdNfpZUJRR4Rr/ysGuFFL0ozGnk+DHZdo+BQenGLeDRqHng7oHJ5aSNff2d/ZCgIahZhE PwGthQtIV0aKcx3Y7dFvYytxwzP/wiw2kv7qeUz/bCg9Rpw8qEObM4a6OptMym/5YQvzfIUwH/Z+3 RR8uyCfn0uD2Sp4QhNE83Y90g/fTJ6uUSkU6KlsPgbb4Ax1rLQrthFV9EQBNcYLNiSK0tvCpKkGAh K+kwHi9eUQmTIwQ2wnk3lBNBMfe2Jco3N6S95j/0bFcMY22uO0txuuwkkY+LTJgoxbkE9k/pQQw30 ltOQwjRg==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TZy-00A1Sz-K4; Thu, 22 Jul 2021 07:57:23 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 7/9] loop: don't grab a reference to the block device Date: Thu, 22 Jul 2021 09:54:00 +0200 Message-Id: <20210722075402.983367-8-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The whole device block device won't be removed while the disk is still alive, so don't bother to grab a reference to it. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik Reviewed-by: Ming Lei Reviewed-by: Chaitanya Kulkarni --- drivers/block/loop.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index f37b9e3d833c..62c5120cf744 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1249,10 +1249,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, if (partscan) lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; - /* Grab the block_device to prevent its destruction after we - * put /dev/loopXX inode. Later in __loop_clr_fd() we bdput(bdev). - */ - bdgrab(bdev); mutex_unlock(&lo->lo_mutex); if (partscan) loop_reread_partitions(lo); @@ -1332,7 +1328,6 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) blk_queue_physical_block_size(lo->lo_queue, 512); blk_queue_io_min(lo->lo_queue, 512); if (bdev) { - bdput(bdev); invalidate_bdev(bdev); bdev->bd_inode->i_mapping->wb_err = 0; } From patchwork Thu Jul 22 07:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393411 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=ham 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 0DE92C63793 for ; Thu, 22 Jul 2021 07:58:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE263610CC for ; Thu, 22 Jul 2021 07:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbhGVHRm (ORCPT ); Thu, 22 Jul 2021 03:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbhGVHRm (ORCPT ); Thu, 22 Jul 2021 03:17:42 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80AFC061575; Thu, 22 Jul 2021 00:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=6EOaGCr0s/6Ie6xU1pfdp0zJGxARJ60XJ1Wx1SRxcio=; b=D3/d8OwR5tBDEJ16l3TFeQW3Ij kFGx78NdmiveZyi+q0/tLwF1cQh9sMr5yCCo/M3LDBJ6fb1xsq3ikr4sQEqtPYEKg7eyK/TnlBI4W 8yvxvlL4gU08h433gqm3PlNARbcKQAiPDfUD3Nj56HBaw/366GLZY9uJCQbJgVKdQHqAAML1Hhdv9 TD+QiE6IvN1HLs6cgw4r+eAIK3uSxCiiAqFqeqJI7YvetTx867U1cpmitNTQHd/CQyOPjBKuVaUjv sDFToStybVpS5eEQS406l7zTbt2WcJNKK3mi6QQC6VKLgTtD/gPtr7cN9uz+g+wj8Eo8AZUXEV0bd I672ZB1Q==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6TaW-00A1VM-KP; Thu, 22 Jul 2021 07:57:55 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 8/9] block: remove bdgrab Date: Thu, 22 Jul 2021 09:54:01 +0200 Message-Id: <20210722075402.983367-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org All callers are gone, and no one should grab a pure inode reference to a block device anymore. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/block_dev.c | 15 --------------- include/linux/blkdev.h | 1 - 2 files changed, 16 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index 4a6c8c0a3bc9..4f2c4e9e84f5 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -921,21 +921,6 @@ void bdev_add(struct block_device *bdev, dev_t dev) insert_inode_hash(bdev->bd_inode); } -/** - * bdgrab -- Grab a reference to an already referenced block device - * @bdev: Block device to grab a reference to. - * - * Returns the block_device with an additional reference when successful, - * or NULL if the inode is already beeing freed. - */ -struct block_device *bdgrab(struct block_device *bdev) -{ - if (!igrab(bdev->bd_inode)) - return NULL; - return bdev; -} -EXPORT_SYMBOL(bdgrab); - long nr_blockdev_pages(void) { struct inode *inode; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 3177181c4326..98772da38bb1 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1984,7 +1984,6 @@ void blkdev_put_no_open(struct block_device *bdev); struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); void bdev_add(struct block_device *bdev, dev_t dev); struct block_device *I_BDEV(struct inode *inode); -struct block_device *bdgrab(struct block_device *bdev); void bdput(struct block_device *); int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, loff_t lend); From patchwork Thu Jul 22 07:54:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12393413 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=ham 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 8B284C6377D for ; Thu, 22 Jul 2021 07:58:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73863610CC for ; Thu, 22 Jul 2021 07:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbhGVHSV (ORCPT ); Thu, 22 Jul 2021 03:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbhGVHST (ORCPT ); Thu, 22 Jul 2021 03:18:19 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9383CC06179A; Thu, 22 Jul 2021 00:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=DLetPscjPSvYX0+JLQEAhyT0z61r6wDFfOuKfNbPHc0=; b=uUWXzTto9SFDBQ55AQSrqQxHhN VZpzslCNdO/UWTiIvTBl6h4QJDqG1TnDRothEUBP07YQytD/asdapiS37ZAZtnKS2r9ByHoaEJ/Nd +C5Wir7XByznnyLuB62cTCoCEtzbi2eVknvFgAeumtVjfaS7MR14Iq+acJZnNII+NP70ZJJT2CSzF sKgrAGq7ngTcGr8C/YaA/J9pVk3TW5DehOfhNRHb+2BpASQcft6bmptyc7frsR5HVlbFyrBz4z4ia PGIZAfJxci7DvR9YvLaCZKEwvT4iPykqATCtXYBaJZohA78lOSDQQvs2wXmOX2lr6L+r0HzEgNczt OMxmjbxA==; Received: from [2001:4bb8:193:7660:643c:9899:473:314a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Taq-00A1WF-7Q; Thu, 22 Jul 2021 07:58:10 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , David Sterba , Naohiro Aota , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 9/9] block: remove bdput Date: Thu, 22 Jul 2021 09:54:02 +0200 Message-Id: <20210722075402.983367-10-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210722075402.983367-1-hch@lst.de> References: <20210722075402.983367-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Now that we've stopped using inode references for anything meaninful in the block layer get rid of the helper to put it and just open code the call to iput on the block_device inode. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik Reviewed-by: Chaitanya Kulkarni --- block/genhd.c | 4 ++-- block/partitions/core.c | 2 +- fs/block_dev.c | 6 ------ include/linux/blkdev.h | 1 - 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 716f5ca479ad..5dbb99b57b33 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1076,7 +1076,7 @@ static void disk_release(struct device *dev) xa_destroy(&disk->part_tbl); if (test_bit(GD_QUEUE_REF, &disk->state) && disk->queue) blk_put_queue(disk->queue); - bdput(disk->part0); /* frees the disk */ + iput(disk->part0->bd_inode); /* frees the disk */ } struct class block_class = { .name = "block", @@ -1261,7 +1261,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) out_destroy_part_tbl: xa_destroy(&disk->part_tbl); - bdput(disk->part0); + iput(disk->part0->bd_inode); out_free_disk: kfree(disk); return NULL; diff --git a/block/partitions/core.c b/block/partitions/core.c index 4f7a1a9cd544..2415bffc2771 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -262,7 +262,7 @@ static void part_release(struct device *dev) if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR) blk_free_ext_minor(MINOR(dev->devt)); put_disk(dev_to_bdev(dev)->bd_disk); - bdput(dev_to_bdev(dev)); + iput(dev_to_bdev(dev)->bd_inode); } static int part_uevent(struct device *dev, struct kobj_uevent_env *env) diff --git a/fs/block_dev.c b/fs/block_dev.c index 4f2c4e9e84f5..6658f40ae492 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -934,12 +934,6 @@ long nr_blockdev_pages(void) return ret; } -void bdput(struct block_device *bdev) -{ - iput(bdev->bd_inode); -} -EXPORT_SYMBOL(bdput); - /** * bd_may_claim - test whether a block device can be claimed * @bdev: block device of interest diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 98772da38bb1..b94de1d194b8 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1984,7 +1984,6 @@ void blkdev_put_no_open(struct block_device *bdev); struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); void bdev_add(struct block_device *bdev, dev_t dev); struct block_device *I_BDEV(struct inode *inode); -void bdput(struct block_device *); int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, loff_t lend);