block: remove bdget_disk
authorChristoph Hellwig <hch@lst.de>
Tue, 25 May 2021 06:13:01 +0000 (08:13 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Jun 2021 13:47:14 +0000 (07:47 -0600)
Just opencode the xa_load in the callers, as none of them actually
needs a reference to the bdev.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20210525061301.2242282-9-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c
block/partitions/core.c
include/linux/genhd.h

index 3f7b1c92c7f3c779383c8a9105c5f42c5c66f36c..5f56282162951c04a3463e98d38e7c009d62d7f3 100644 (file)
@@ -676,32 +676,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
@@ -1229,13 +1203,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;
 }
index 4fde8e0dd7cde41dfe9c6fcf212836dd9597c812..186d4fbd9f092f5e4fbd2285b7f864048cf1decb 100644 (file)
@@ -326,6 +326,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
        const char *dname;
        int err;
 
+       lockdep_assert_held(&disk->open_mutex);
+
        if (partno >= disk_max_parts(disk))
                return ERR_PTR(-EINVAL);
 
@@ -467,14 +469,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)
@@ -484,21 +485,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;
@@ -512,7 +512,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;
 }
 
index 64a8431202b79b1a4e6843ab5e961a4653f8f58a..03d684f0498fb46e453bbc3891ef3706c4886da1 100644 (file)
@@ -223,7 +223,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);