Skip to content

Commit de4c7be

Browse files
johnpgarryaxboe
authored andcommitted
block: Call blkdev_dio_unaligned() from blkdev_direct_IO()
blkdev_dio_unaligned() is called from __blkdev_direct_IO(), __blkdev_direct_IO_simple(), and __blkdev_direct_IO_async(), and all these are only called from blkdev_direct_IO(). Move the blkdev_dio_unaligned() call to the common callsite, blkdev_direct_IO(). Pass those functions the bdev pointer from blkdev_direct_IO(), as it is non-trivial to look up. Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 688c8b9 commit de4c7be

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

block/fops.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,15 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos,
4444
#define DIO_INLINE_BIO_VECS 4
4545

4646
static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
47-
struct iov_iter *iter, unsigned int nr_pages)
47+
struct iov_iter *iter, struct block_device *bdev,
48+
unsigned int nr_pages)
4849
{
49-
struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
5050
struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs;
5151
loff_t pos = iocb->ki_pos;
5252
bool should_dirty = false;
5353
struct bio bio;
5454
ssize_t ret;
5555

56-
if (blkdev_dio_unaligned(bdev, pos, iter))
57-
return -EINVAL;
58-
5956
if (nr_pages <= DIO_INLINE_BIO_VECS)
6057
vecs = inline_vecs;
6158
else {
@@ -161,9 +158,8 @@ static void blkdev_bio_end_io(struct bio *bio)
161158
}
162159

163160
static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
164-
unsigned int nr_pages)
161+
struct block_device *bdev, unsigned int nr_pages)
165162
{
166-
struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
167163
struct blk_plug plug;
168164
struct blkdev_dio *dio;
169165
struct bio *bio;
@@ -172,9 +168,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
172168
loff_t pos = iocb->ki_pos;
173169
int ret = 0;
174170

175-
if (blkdev_dio_unaligned(bdev, pos, iter))
176-
return -EINVAL;
177-
178171
if (iocb->ki_flags & IOCB_ALLOC_CACHE)
179172
opf |= REQ_ALLOC_CACHE;
180173
bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL,
@@ -302,19 +295,16 @@ static void blkdev_bio_end_io_async(struct bio *bio)
302295

303296
static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
304297
struct iov_iter *iter,
298+
struct block_device *bdev,
305299
unsigned int nr_pages)
306300
{
307-
struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
308301
bool is_read = iov_iter_rw(iter) == READ;
309302
blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb);
310303
struct blkdev_dio *dio;
311304
struct bio *bio;
312305
loff_t pos = iocb->ki_pos;
313306
int ret = 0;
314307

315-
if (blkdev_dio_unaligned(bdev, pos, iter))
316-
return -EINVAL;
317-
318308
if (iocb->ki_flags & IOCB_ALLOC_CACHE)
319309
opf |= REQ_ALLOC_CACHE;
320310
bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL,
@@ -368,18 +358,23 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
368358

369359
static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
370360
{
361+
struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host);
371362
unsigned int nr_pages;
372363

373364
if (!iov_iter_count(iter))
374365
return 0;
375366

367+
if (blkdev_dio_unaligned(bdev, iocb->ki_pos, iter))
368+
return -EINVAL;
369+
376370
nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1);
377371
if (likely(nr_pages <= BIO_MAX_VECS)) {
378372
if (is_sync_kiocb(iocb))
379-
return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
380-
return __blkdev_direct_IO_async(iocb, iter, nr_pages);
373+
return __blkdev_direct_IO_simple(iocb, iter, bdev,
374+
nr_pages);
375+
return __blkdev_direct_IO_async(iocb, iter, bdev, nr_pages);
381376
}
382-
return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages));
377+
return __blkdev_direct_IO(iocb, iter, bdev, bio_max_segs(nr_pages));
383378
}
384379

385380
static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,

0 commit comments

Comments
 (0)