Skip to content

Commit bbab37d

Browse files
Matthew WilcoxAl Viro
authored andcommitted
block: Add support for DAX reads/writes to block devices
If a block device supports the ->direct_access methods, bypass the normal DIO path and use DAX to go straight to memcpy() instead of allocating a DIO and a BIO. Includes support for the DIO_SKIP_DIO_COUNT flag in DAX, as is done in do_blockdev_direct_IO(). Signed-off-by: Matthew Wilcox <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 872eb12 commit bbab37d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

fs/block_dev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset)
151151
struct file *file = iocb->ki_filp;
152152
struct inode *inode = file->f_mapping->host;
153153

154+
if (IS_DAX(inode))
155+
return dax_do_io(iocb, inode, iter, offset, blkdev_get_block,
156+
NULL, DIO_SKIP_DIO_COUNT);
154157
return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter, offset,
155158
blkdev_get_block, NULL, NULL,
156159
DIO_SKIP_DIO_COUNT);
@@ -1173,6 +1176,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
11731176
bdev->bd_disk = disk;
11741177
bdev->bd_queue = disk->queue;
11751178
bdev->bd_contains = bdev;
1179+
bdev->bd_inode->i_flags = disk->fops->direct_access ? S_DAX : 0;
11761180
if (!partno) {
11771181
ret = -ENXIO;
11781182
bdev->bd_part = disk_get_part(disk, partno);

fs/dax.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ ssize_t dax_do_io(struct kiocb *iocb, struct inode *inode,
209209
}
210210

211211
/* Protects against truncate */
212-
inode_dio_begin(inode);
212+
if (!(flags & DIO_SKIP_DIO_COUNT))
213+
inode_dio_begin(inode);
213214

214215
retval = dax_io(inode, iter, pos, end, get_block, &bh);
215216

@@ -219,7 +220,8 @@ ssize_t dax_do_io(struct kiocb *iocb, struct inode *inode,
219220
if ((retval > 0) && end_io)
220221
end_io(iocb, pos, retval, bh.b_private);
221222

222-
inode_dio_end(inode);
223+
if (!(flags & DIO_SKIP_DIO_COUNT))
224+
inode_dio_end(inode);
223225
out:
224226
return retval;
225227
}

0 commit comments

Comments
 (0)