Skip to content

Commit ff9ea32

Browse files
htejunaxboe
authored andcommitted
block, bdi: an active gendisk always has a request_queue associated with it
bdev_get_queue() returns the request_queue associated with the specified block_device. blk_get_backing_dev_info() makes use of bdev_get_queue() to determine the associated bdi given a block_device. All the callers of bdev_get_queue() including blk_get_backing_dev_info() assume that bdev_get_queue() may return NULL and implement NULL handling; however, bdev_get_queue() requires the passed in block_device is opened and attached to its gendisk. Because an active gendisk always has a valid request_queue associated with it, bdev_get_queue() can never return NULL and neither can blk_get_backing_dev_info(). Make it clear that neither of the two functions can return NULL and remove NULL handling from all the callers. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Chris Mason <clm@fb.com> Cc: Dave Chinner <david@fromorbit.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent f4da807 commit ff9ea32

7 files changed

Lines changed: 5 additions & 21 deletions

File tree

‎block/blk-core.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,14 @@ void blk_queue_congestion_threshold(struct request_queue *q)
8383
* @bdev: device
8484
*
8585
* Locates the passed device's request queue and returns the address of its
86-
* backing_dev_info
87-
*
88-
* Will return NULL if the request queue cannot be located.
86+
* backing_dev_info. This function can only be called if @bdev is opened
87+
* and the return value is never NULL.
8988
*/
9089
struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
9190
{
92-
struct backing_dev_info *ret = NULL;
9391
struct request_queue *q = bdev_get_queue(bdev);
9492

95-
if (q)
96-
ret = &q->backing_dev_info;
97-
return ret;
93+
return &q->backing_dev_info;
9894
}
9995
EXPORT_SYMBOL(blk_get_backing_dev_info);
10096

‎block/compat_ioctl.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
709709
if (!arg)
710710
return -EINVAL;
711711
bdi = blk_get_backing_dev_info(bdev);
712-
if (bdi == NULL)
713-
return -ENOTTY;
714712
return compat_put_long(arg,
715713
(bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
716714
case BLKROGET: /* compatible */
@@ -731,8 +729,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
731729
if (!capable(CAP_SYS_ADMIN))
732730
return -EACCES;
733731
bdi = blk_get_backing_dev_info(bdev);
734-
if (bdi == NULL)
735-
return -ENOTTY;
736732
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
737733
return 0;
738734
case BLKGETSIZE:

‎block/ioctl.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
356356
if (!arg)
357357
return -EINVAL;
358358
bdi = blk_get_backing_dev_info(bdev);
359-
if (bdi == NULL)
360-
return -ENOTTY;
361359
return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
362360
case BLKROGET:
363361
return put_int(arg, bdev_read_only(bdev) != 0);
@@ -386,8 +384,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
386384
if(!capable(CAP_SYS_ADMIN))
387385
return -EACCES;
388386
bdi = blk_get_backing_dev_info(bdev);
389-
if (bdi == NULL)
390-
return -ENOTTY;
391387
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
392388
return 0;
393389
case BLKBSZSET:

‎fs/block_dev.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
11731173
if (!ret) {
11741174
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
11751175
bdi = blk_get_backing_dev_info(bdev);
1176-
if (bdi == NULL)
1177-
bdi = &default_backing_dev_info;
11781176
bdev_inode_switch_bdi(bdev->bd_inode, bdi);
11791177
}
11801178

‎fs/btrfs/disk-io.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
16941694
if (!device->bdev)
16951695
continue;
16961696
bdi = blk_get_backing_dev_info(device->bdev);
1697-
if (bdi && bdi_congested(bdi, bdi_bits)) {
1697+
if (bdi_congested(bdi, bdi_bits)) {
16981698
ret = 1;
16991699
break;
17001700
}

‎fs/xfs/xfs_buf.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,8 +1678,6 @@ xfs_alloc_buftarg(
16781678
btp->bt_dev = bdev->bd_dev;
16791679
btp->bt_bdev = bdev;
16801680
btp->bt_bdi = blk_get_backing_dev_info(bdev);
1681-
if (!btp->bt_bdi)
1682-
goto error;
16831681

16841682
if (xfs_setsize_buftarg_early(btp, bdev))
16851683
goto error;

‎include/linux/blkdev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
865865

866866
static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
867867
{
868-
return bdev->bd_disk->queue;
868+
return bdev->bd_disk->queue; /* this is never NULL */
869869
}
870870

871871
/*

0 commit comments

Comments
 (0)