Commit 72ecad22 authored by Jens Axboe's avatar Jens Axboe

block: support a full bio worth of IO for simplified bdev direct-io

Just alloc the bio_vec array if we exceed the inline limit.
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 64f1c21e
...@@ -193,7 +193,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, ...@@ -193,7 +193,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct block_device *bdev = I_BDEV(bdev_file_inode(file)); struct block_device *bdev = I_BDEV(bdev_file_inode(file));
unsigned blkbits = blksize_bits(bdev_logical_block_size(bdev)); unsigned blkbits = blksize_bits(bdev_logical_block_size(bdev));
struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *bvec; struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs, *bvec;
loff_t pos = iocb->ki_pos; loff_t pos = iocb->ki_pos;
bool should_dirty = false; bool should_dirty = false;
struct bio bio; struct bio bio;
...@@ -204,9 +204,17 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, ...@@ -204,9 +204,17 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
if ((pos | iov_iter_alignment(iter)) & ((1 << blkbits) - 1)) if ((pos | iov_iter_alignment(iter)) & ((1 << blkbits) - 1))
return -EINVAL; return -EINVAL;
if (nr_pages <= DIO_INLINE_BIO_VECS)
vecs = inline_vecs;
else {
vecs = kmalloc(nr_pages * sizeof(struct bio_vec), GFP_KERNEL);
if (!vecs)
return -ENOMEM;
}
bio_init(&bio); bio_init(&bio);
bio.bi_max_vecs = nr_pages; bio.bi_max_vecs = nr_pages;
bio.bi_io_vec = inline_vecs; bio.bi_io_vec = vecs;
bio.bi_bdev = bdev; bio.bi_bdev = bdev;
bio.bi_iter.bi_sector = pos >> blkbits; bio.bi_iter.bi_sector = pos >> blkbits;
bio.bi_private = current; bio.bi_private = current;
...@@ -243,6 +251,9 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, ...@@ -243,6 +251,9 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
put_page(bvec->bv_page); put_page(bvec->bv_page);
} }
if (vecs != inline_vecs)
kfree(vecs);
if (unlikely(bio.bi_error)) if (unlikely(bio.bi_error))
return bio.bi_error; return bio.bi_error;
iocb->ki_pos += ret; iocb->ki_pos += ret;
...@@ -256,10 +267,10 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -256,10 +267,10 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
struct inode *inode = bdev_file_inode(file); struct inode *inode = bdev_file_inode(file);
int nr_pages; int nr_pages;
nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES); nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES + 1);
if (!nr_pages) if (!nr_pages)
return 0; return 0;
if (is_sync_kiocb(iocb) && nr_pages <= DIO_INLINE_BIO_VECS) if (is_sync_kiocb(iocb) && nr_pages <= BIO_MAX_PAGES)
return __blkdev_direct_IO_simple(iocb, iter, nr_pages); return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter, return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter,
blkdev_get_block, NULL, NULL, blkdev_get_block, NULL, NULL,
......
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