Commit 37fee2e4 authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe

block: add a helper function for dio alignment

This will make it easier to add more complex acceptable alignment
criteria in the future.
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220610195830.3574005-6-kbusch@fb.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4a2dcc35
...@@ -42,6 +42,13 @@ static unsigned int dio_bio_write_op(struct kiocb *iocb) ...@@ -42,6 +42,13 @@ static unsigned int dio_bio_write_op(struct kiocb *iocb)
return op; return op;
} }
static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos,
struct iov_iter *iter)
{
return ((pos | iov_iter_alignment(iter)) &
(bdev_logical_block_size(bdev) - 1));
}
#define DIO_INLINE_BIO_VECS 4 #define DIO_INLINE_BIO_VECS 4
static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
...@@ -54,8 +61,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, ...@@ -54,8 +61,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
struct bio bio; struct bio bio;
ssize_t ret; ssize_t ret;
if ((pos | iov_iter_alignment(iter)) & if (blkdev_dio_unaligned(bdev, pos, iter))
(bdev_logical_block_size(bdev) - 1))
return -EINVAL; return -EINVAL;
if (nr_pages <= DIO_INLINE_BIO_VECS) if (nr_pages <= DIO_INLINE_BIO_VECS)
...@@ -173,8 +179,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, ...@@ -173,8 +179,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
loff_t pos = iocb->ki_pos; loff_t pos = iocb->ki_pos;
int ret = 0; int ret = 0;
if ((pos | iov_iter_alignment(iter)) & if (blkdev_dio_unaligned(bdev, pos, iter))
(bdev_logical_block_size(bdev) - 1))
return -EINVAL; return -EINVAL;
if (iocb->ki_flags & IOCB_ALLOC_CACHE) if (iocb->ki_flags & IOCB_ALLOC_CACHE)
...@@ -298,8 +303,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, ...@@ -298,8 +303,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
loff_t pos = iocb->ki_pos; loff_t pos = iocb->ki_pos;
int ret = 0; int ret = 0;
if ((pos | iov_iter_alignment(iter)) & if (blkdev_dio_unaligned(bdev, pos, iter))
(bdev_logical_block_size(bdev) - 1))
return -EINVAL; return -EINVAL;
if (iocb->ki_flags & IOCB_ALLOC_CACHE) if (iocb->ki_flags & IOCB_ALLOC_CACHE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment