From 2116274af46b12df7cea1dc5698f3cf2f231f8a9 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 4 Nov 2021 18:20:37 +0100 Subject: [PATCH 1/2] block: add a loff_t cast to bdev_nr_bytes Not really needed as both loff_t and sector_t are always 64-bits wide, but this documents the different types a bit better. Signed-off-by: Christoph Hellwig Link: https://lore.kernel.org/r/20211104172037.531803-1-hch@lst.de Signed-off-by: Jens Axboe --- include/linux/genhd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 900325aa5d31..1dce769c4596 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -243,7 +243,7 @@ static inline sector_t bdev_nr_sectors(struct block_device *bdev) static inline loff_t bdev_nr_bytes(struct block_device *bdev) { - return bdev_nr_sectors(bdev) << SECTOR_SHIFT; + return (loff_t)bdev_nr_sectors(bdev) << SECTOR_SHIFT; } static inline sector_t get_capacity(struct gendisk *disk) From 138c1a38113d989416df57e9f8973c10c9e1fa04 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 4 Nov 2021 15:13:17 -0600 Subject: [PATCH 2/2] block: use new bdev_nr_bytes() helper for blkdev_{read,write}_iter() We have new helpers for this, use them rather than the slower inode size reads. This makes the read/write path consistent with most of the rest of block as well. Signed-off-by: Jens Axboe Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/a72767cd-3c6d-47f7-80f4-aa025a17b2cb@kernel.dk Signed-off-by: Jens Axboe --- block/fops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index 2ae8a7bd2b84..e6c5b35aa5a5 100644 --- a/block/fops.c +++ b/block/fops.c @@ -460,7 +460,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct block_device *bdev = iocb->ki_filp->private_data; struct inode *bd_inode = bdev->bd_inode; - loff_t size = i_size_read(bd_inode); + loff_t size = bdev_nr_bytes(bdev); struct blk_plug plug; size_t shorted = 0; ssize_t ret; @@ -498,7 +498,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct block_device *bdev = iocb->ki_filp->private_data; - loff_t size = i_size_read(bdev->bd_inode); + loff_t size = bdev_nr_bytes(bdev); loff_t pos = iocb->ki_pos; size_t shorted = 0; ssize_t ret;