aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-09-07 19:03:56 -0400
committerJens Axboe <axboe@fb.com>2014-09-08 12:00:35 -0400
commitff9ea323816dc1c8ac7144afd4eab3ac97704430 (patch)
treea865fe69407f8c15d4d877defbc801aebf8d1849
parentf4da80727cfbc3590d95ff17ef8db96e6f1483a4 (diff)
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>
-rw-r--r--block/blk-core.c10
-rw-r--r--block/compat_ioctl.c4
-rw-r--r--block/ioctl.c4
-rw-r--r--fs/block_dev.c2
-rw-r--r--fs/btrfs/disk-io.c2
-rw-r--r--fs/xfs/xfs_buf.c2
-rw-r--r--include/linux/blkdev.h2
7 files changed, 5 insertions, 21 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 93603e6ff479..817446175489 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -83,18 +83,14 @@ void blk_queue_congestion_threshold(struct request_queue *q)
83 * @bdev: device 83 * @bdev: device
84 * 84 *
85 * Locates the passed device's request queue and returns the address of its 85 * Locates the passed device's request queue and returns the address of its
86 * backing_dev_info 86 * backing_dev_info. This function can only be called if @bdev is opened
87 * 87 * and the return value is never NULL.
88 * Will return NULL if the request queue cannot be located.
89 */ 88 */
90struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev) 89struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
91{ 90{
92 struct backing_dev_info *ret = NULL;
93 struct request_queue *q = bdev_get_queue(bdev); 91 struct request_queue *q = bdev_get_queue(bdev);
94 92
95 if (q) 93 return &q->backing_dev_info;
96 ret = &q->backing_dev_info;
97 return ret;
98} 94}
99EXPORT_SYMBOL(blk_get_backing_dev_info); 95EXPORT_SYMBOL(blk_get_backing_dev_info);
100 96
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 18b282ce361e..f678c733df40 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -709,8 +709,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
709 if (!arg) 709 if (!arg)
710 return -EINVAL; 710 return -EINVAL;
711 bdi = blk_get_backing_dev_info(bdev); 711 bdi = blk_get_backing_dev_info(bdev);
712 if (bdi == NULL)
713 return -ENOTTY;
714 return compat_put_long(arg, 712 return compat_put_long(arg,
715 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); 713 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
716 case BLKROGET: /* compatible */ 714 case BLKROGET: /* compatible */
@@ -731,8 +729,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
731 if (!capable(CAP_SYS_ADMIN)) 729 if (!capable(CAP_SYS_ADMIN))
732 return -EACCES; 730 return -EACCES;
733 bdi = blk_get_backing_dev_info(bdev); 731 bdi = blk_get_backing_dev_info(bdev);
734 if (bdi == NULL)
735 return -ENOTTY;
736 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 732 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
737 return 0; 733 return 0;
738 case BLKGETSIZE: 734 case BLKGETSIZE:
diff --git a/block/ioctl.c b/block/ioctl.c
index d6cda8147c91..6c7bf903742f 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -356,8 +356,6 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
356 if (!arg) 356 if (!arg)
357 return -EINVAL; 357 return -EINVAL;
358 bdi = blk_get_backing_dev_info(bdev); 358 bdi = blk_get_backing_dev_info(bdev);
359 if (bdi == NULL)
360 return -ENOTTY;
361 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); 359 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
362 case BLKROGET: 360 case BLKROGET:
363 return put_int(arg, bdev_read_only(bdev) != 0); 361 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,
386 if(!capable(CAP_SYS_ADMIN)) 384 if(!capable(CAP_SYS_ADMIN))
387 return -EACCES; 385 return -EACCES;
388 bdi = blk_get_backing_dev_info(bdev); 386 bdi = blk_get_backing_dev_info(bdev);
389 if (bdi == NULL)
390 return -ENOTTY;
391 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 387 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
392 return 0; 388 return 0;
393 case BLKBSZSET: 389 case BLKBSZSET:
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 6d7274619bf9..d3251eca6429 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1173,8 +1173,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
1173 if (!ret) { 1173 if (!ret) {
1174 bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); 1174 bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
1175 bdi = blk_get_backing_dev_info(bdev); 1175 bdi = blk_get_backing_dev_info(bdev);
1176 if (bdi == NULL)
1177 bdi = &default_backing_dev_info;
1178 bdev_inode_switch_bdi(bdev->bd_inode, bdi); 1176 bdev_inode_switch_bdi(bdev->bd_inode, bdi);
1179 } 1177 }
1180 1178
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index d0ed9e664f7d..39ff591ae1b4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1694,7 +1694,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
1694 if (!device->bdev) 1694 if (!device->bdev)
1695 continue; 1695 continue;
1696 bdi = blk_get_backing_dev_info(device->bdev); 1696 bdi = blk_get_backing_dev_info(device->bdev);
1697 if (bdi && bdi_congested(bdi, bdi_bits)) { 1697 if (bdi_congested(bdi, bdi_bits)) {
1698 ret = 1; 1698 ret = 1;
1699 break; 1699 break;
1700 } 1700 }
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index cd7b8ca9b064..497fcde381d7 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1678,8 +1678,6 @@ xfs_alloc_buftarg(
1678 btp->bt_dev = bdev->bd_dev; 1678 btp->bt_dev = bdev->bd_dev;
1679 btp->bt_bdev = bdev; 1679 btp->bt_bdev = bdev;
1680 btp->bt_bdi = blk_get_backing_dev_info(bdev); 1680 btp->bt_bdi = blk_get_backing_dev_info(bdev);
1681 if (!btp->bt_bdi)
1682 goto error;
1683 1681
1684 if (xfs_setsize_buftarg_early(btp, bdev)) 1682 if (xfs_setsize_buftarg_early(btp, bdev))
1685 goto error; 1683 goto error;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 518b46555b80..e267bf0db559 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -865,7 +865,7 @@ extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
865 865
866static inline struct request_queue *bdev_get_queue(struct block_device *bdev) 866static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
867{ 867{
868 return bdev->bd_disk->queue; 868 return bdev->bd_disk->queue; /* this is never NULL */
869} 869}
870 870
871/* 871/*