]> www.infradead.org Git - users/hch/block.git/commitdiff
block: remove bdget_disk blkdev_get
authorChristoph Hellwig <hch@lst.de>
Wed, 3 Mar 2021 16:09:30 +0000 (17:09 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 24 May 2021 13:23:32 +0000 (15:23 +0200)
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>
block/genhd.c
block/partitions/core.c
include/linux/genhd.h

index e3de476797de329a784d997374f396f154c0674e..2abafe44bf4b2cc6fe2f3d488d9114114852258d 100644 (file)
@@ -692,32 +692,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
@@ -1244,13 +1218,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 0d33f55a7d7804eb2d0e0415c45700e4b756726d..325368b9de292017c3cf04bc1806338bc12cac69 100644 (file)
@@ -325,6 +325,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
        const char *dname;
        int err;
 
+       lockdep_assert_held(&disk->open_mutex);
+
        /*
         * disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set
         * or 'minors' is passed to alloc_disk().
@@ -464,14 +466,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)
@@ -481,21 +482,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;
@@ -509,7 +509,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 96d55cd06cf63e486c48cb1b16133f0235fcf75f..d06892a0a9efc6128512fbdb59f3abd91f967943 100644 (file)
@@ -222,7 +222,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);