From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org
Subject: [PATCH 8/8] block: remove bdget/bdput
Date: Wed, 21 Jul 2021 17:35:23 +0200 [thread overview]
Message-ID: <20210721153523.103818-9-hch@lst.de> (raw)
In-Reply-To: <20210721153523.103818-1-hch@lst.de>
Now that we've stopped using inode references for anything meaninful
in the block layer get rid of the helpers for it and just open code
the places that look up a block device by dev_t and drop the main
inode reference held by the device model.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 4 ++--
block/partitions/core.c | 8 ++++----
fs/block_dev.c | 34 ++++++++++------------------------
include/linux/blkdev.h | 1 -
4 files changed, 16 insertions(+), 31 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index e6d782714ad3..3ea27bee0615 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1081,7 +1081,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);
+ iput(disk->part0->bd_inode); /* actually frees the disk */
}
struct class block_class = {
.name = "block",
@@ -1266,7 +1266,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 9902b1635b7d..4397ac9f905e 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -261,7 +261,7 @@ static void part_release(struct device *dev)
{
if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR)
blk_free_ext_minor(MINOR(dev->devt));
- bdput(dev_to_bdev(dev));
+ iput(dev_to_bdev(dev)->bd_inode);
}
static int part_uevent(struct device *dev, struct kobj_uevent_env *env)
@@ -360,7 +360,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
err = -ENOMEM;
bdev->bd_meta_info = kmemdup(info, sizeof(*info), GFP_KERNEL);
if (!bdev->bd_meta_info)
- goto out_bdput;
+ goto out_iput;
}
pdev = &bdev->bd_device;
@@ -415,8 +415,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
kobject_uevent(&pdev->kobj, KOBJ_ADD);
return bdev;
-out_bdput:
- bdput(bdev);
+out_iput:
+ iput(bdev->bd_inode);
return ERR_PTR(err);
out_del:
kobject_put(bdev->bd_holder_dir);
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 5c56d88fd838..8747c264e64c 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;
-}
-
long nr_blockdev_pages(void)
{
struct inode *inode;
@@ -944,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
@@ -1308,18 +1292,20 @@ 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;
}
+ bdev = &BDEV_I(inode)->bdev;
disk = bdev->bd_disk;
if (!kobject_get_unless_zero(&disk_to_dev(disk)->kobj))
- goto bdput;
+ goto iput;
if ((disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP)
goto put_disk;
if (!try_module_get(disk->fops->owner))
@@ -1328,14 +1314,14 @@ struct block_device *blkdev_get_no_open(dev_t dev)
/* switch to a device model reference instead of the inode one: */
if (!kobject_get_unless_zero(&bdev->bd_device.kobj))
goto put_module;
- bdput(bdev);
+ iput(bdev->bd_inode);
return bdev;
put_module:
module_put(disk->fops->owner);
put_disk:
put_disk(disk);
-bdput:
- bdput(bdev);
+iput:
+ iput(bdev->bd_inode);
return NULL;
}
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);
--
2.30.2
next prev parent reply other threads:[~2021-07-21 15:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 15:35 fixes and cleanups for block_device refcounting Christoph Hellwig
2021-07-21 15:35 ` [PATCH 1/8] block: delay freeing the gendisk Christoph Hellwig
2021-07-22 2:05 ` Ming Lei
2021-07-21 15:35 ` [PATCH 2/8] block: assert the locking state in delete_partition Christoph Hellwig
2021-07-22 2:06 ` Ming Lei
2021-07-21 15:35 ` [PATCH 3/8] block: grab a device model reference in blkdev_get_no_open Christoph Hellwig
2021-07-22 2:47 ` Ming Lei
2021-07-21 15:35 ` [PATCH 4/8] block: don't grab a reference to the whole device in blkdev_get_part Christoph Hellwig
2021-07-21 15:35 ` [PATCH 5/8] btrfs: no need to grab a reference to disk->part0 Christoph Hellwig
2021-07-21 16:15 ` David Sterba
2021-07-21 15:35 ` [PATCH 6/8] loop: don't grab a reference to the block device Christoph Hellwig
2021-07-21 15:35 ` [PATCH 7/8] block: remove bdgrab Christoph Hellwig
2021-07-21 15:35 ` Christoph Hellwig [this message]
2021-07-21 20:52 ` fixes and cleanups for block_device refcounting Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210721153523.103818-9-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).