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>
This commit is contained in:
parent
f4da80727c
commit
ff9ea32381
7 changed files with 5 additions and 21 deletions
|
@ -83,18 +83,14 @@ void blk_queue_congestion_threshold(struct request_queue *q)
|
||||||
* @bdev: device
|
* @bdev: device
|
||||||
*
|
*
|
||||||
* Locates the passed device's request queue and returns the address of its
|
* Locates the passed device's request queue and returns the address of its
|
||||||
* backing_dev_info
|
* backing_dev_info. This function can only be called if @bdev is opened
|
||||||
*
|
* and the return value is never NULL.
|
||||||
* Will return NULL if the request queue cannot be located.
|
|
||||||
*/
|
*/
|
||||||
struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
|
struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
struct backing_dev_info *ret = NULL;
|
|
||||||
struct request_queue *q = bdev_get_queue(bdev);
|
struct request_queue *q = bdev_get_queue(bdev);
|
||||||
|
|
||||||
if (q)
|
return &q->backing_dev_info;
|
||||||
ret = &q->backing_dev_info;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(blk_get_backing_dev_info);
|
EXPORT_SYMBOL(blk_get_backing_dev_info);
|
||||||
|
|
||||||
|
|
|
@ -709,8 +709,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
bdi = blk_get_backing_dev_info(bdev);
|
bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (bdi == NULL)
|
|
||||||
return -ENOTTY;
|
|
||||||
return compat_put_long(arg,
|
return compat_put_long(arg,
|
||||||
(bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
|
(bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
|
||||||
case BLKROGET: /* compatible */
|
case BLKROGET: /* compatible */
|
||||||
|
@ -731,8 +729,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
bdi = blk_get_backing_dev_info(bdev);
|
bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (bdi == NULL)
|
|
||||||
return -ENOTTY;
|
|
||||||
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
|
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
case BLKGETSIZE:
|
case BLKGETSIZE:
|
||||||
|
|
|
@ -356,8 +356,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
bdi = blk_get_backing_dev_info(bdev);
|
bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (bdi == NULL)
|
|
||||||
return -ENOTTY;
|
|
||||||
return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
|
return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
|
||||||
case BLKROGET:
|
case BLKROGET:
|
||||||
return put_int(arg, bdev_read_only(bdev) != 0);
|
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,
|
||||||
if(!capable(CAP_SYS_ADMIN))
|
if(!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
bdi = blk_get_backing_dev_info(bdev);
|
bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (bdi == NULL)
|
|
||||||
return -ENOTTY;
|
|
||||||
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
|
bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
case BLKBSZSET:
|
case BLKBSZSET:
|
||||||
|
|
|
@ -1173,8 +1173,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
|
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
|
||||||
bdi = blk_get_backing_dev_info(bdev);
|
bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (bdi == NULL)
|
|
||||||
bdi = &default_backing_dev_info;
|
|
||||||
bdev_inode_switch_bdi(bdev->bd_inode, bdi);
|
bdev_inode_switch_bdi(bdev->bd_inode, bdi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1694,7 +1694,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
|
||||||
if (!device->bdev)
|
if (!device->bdev)
|
||||||
continue;
|
continue;
|
||||||
bdi = blk_get_backing_dev_info(device->bdev);
|
bdi = blk_get_backing_dev_info(device->bdev);
|
||||||
if (bdi && bdi_congested(bdi, bdi_bits)) {
|
if (bdi_congested(bdi, bdi_bits)) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1678,8 +1678,6 @@ xfs_alloc_buftarg(
|
||||||
btp->bt_dev = bdev->bd_dev;
|
btp->bt_dev = bdev->bd_dev;
|
||||||
btp->bt_bdev = bdev;
|
btp->bt_bdev = bdev;
|
||||||
btp->bt_bdi = blk_get_backing_dev_info(bdev);
|
btp->bt_bdi = blk_get_backing_dev_info(bdev);
|
||||||
if (!btp->bt_bdi)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (xfs_setsize_buftarg_early(btp, bdev))
|
if (xfs_setsize_buftarg_early(btp, bdev))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -865,7 +865,7 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
|
||||||
|
|
||||||
static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
|
static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
return bdev->bd_disk->queue;
|
return bdev->bd_disk->queue; /* this is never NULL */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue