cleanup blockdev_direct_IO locking
Subsystems (3)
PATCH 1/1 cleanup blockdev_direct_IO locking
Currently the locking in blockdev_direct_IO is a mess, we have three different locking types and very confusing checks for some of them. The most complicated one is DIO_OWN_LOCKING for reads, which happens to not actually be used.
This patch gets rid of the DIO_OWN_LOCKING - as mentioned above the read case is unused anyway, and the write side is almost identical to DIO_NO_LOCKING. The difference is that DIO_NO_LOCKING always sets the create argument for the get_blocks callback to zero, but we can easily move that to the actual get_blocks callbacks. There are four users of the DIO_NO_LOCKING mode:
gfs already ignores the create argument and thus is fine with the new version, ocfs2 only errors out if create were ever set, and we can remove this dead code now, the block device code only ever uses create for an error message if we are fully beyond the device which can never happen, and last but not least XFS will need the new behavour for writes.
Now we can replace the lock_type variable with a flags one, where no flag means the DIO_NO_LOCKING behaviour and DIO_LOCKING is kept as the first flag. Separate out the check for not allowing to fill holes into a separate flag, although for now both flags always get set at the same time.
Also revamp the documentation of the locking scheme to actually make sense.
fs/ocfs2/aops.c +4 -30
@@ -547,6 +547,9 @@ bail:* * called like this: dio->get_blocks(dio->inode, fs_startblk, * fs_count, map_bh, dio->rw == WRITE); +* +* Note that we never bother to allocate blocks here, and thus ignore the +* create argument. */ static int ocfs2_direct_IO_get_blocks (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create)
@@ -563,14 +566,6 @@ static int ocfs2_direct_IO_get_blocks(st inode_blocks =ocfs2_blocks_for_bytes (inode->i_sb,i_size_read (inode)); -/* -* Any write past EOF is not allowed because we'd be extending. -*/ -if (create && (iblock + max_blocks) > inode_blocks) { - ret = -EIO ; - goto bail; - } -/* This figures out the size of the next contiguous block, and * our logical offset */ ret = ocfs2_extent_map_get_blocks(inode, iblock, &p_blkno,
@@ -582,15 +577,6 @@ static int ocfs2_direct_IO_get_blocks(st goto bail; } -if (!ocfs2_sparse_alloc (OCFS2_SB (inode->i_sb)) && !p_blkno && create) { -ocfs2_error (inode->i_sb, -"Inode %llu has a hole at block %llu\n" , - (unsigned long long )OCFS2_I (inode)->ip_blkno, - (unsigned long long )iblock); - ret = -EROFS ; - goto bail; - } -/* We should already CoW the refcounted extent. */ BUG_ON (ext_flags &OCFS2_EXT_REFCOUNTED );/*
@@ -601,20 +587,8 @@ static int ocfs2_direct_IO_get_blocks(st*/ if (p_blkno && !(ext_flags &OCFS2_EXT_UNWRITTEN ))map_bh (bh_result, inode->i_sb, p_blkno); -else { -/* -* ocfs2_prepare_inode_for_write() should have caught -* the case where we'd be filling a hole and triggered -* a buffered write instead. -*/ -if (create) { - ret = -EIO ; -mlog_errno (ret); - goto bail; - } - +else clear_buffer_mapped (bh_result); - }/* make sure we don't map more than max_blocks blocks here as that's all the kernel will handle at this point. */
fs/xfs/linux-2.6/xfs_aops.c +7 -13
@@ -1562,19 +1562,13 @@ xfs_vm_direct_IO( bdev =xfs_find_bdev_for_inode (XFS_I (inode)); -if (rw ==WRITE ) { - iocb->private =xfs_alloc_ioend (inode,IOMAP_UNWRITTEN ); - ret =blockdev_direct_IO_own_locking (rw, iocb, inode, - bdev, iov, offset, nr_segs, - xfs_get_blocks_direct, - xfs_end_io_direct); - }else { - iocb->private =xfs_alloc_ioend (inode,IOMAP_READ ); - ret =blockdev_direct_IO_no_locking (rw, iocb, inode, - bdev, iov, offset, nr_segs, - xfs_get_blocks_direct, - xfs_end_io_direct); - } + iocb->private =xfs_alloc_ioend (inode, rw ==WRITE ? +IOMAP_UNWRITTEN :IOMAP_READ ); + + ret =blockdev_direct_IO_no_locking (rw, iocb, inode, bdev, iov, + offset, nr_segs, + xfs_get_blocks_direct, + xfs_end_io_direct);if (unlikely (ret != -EIOCBQUEUED && iocb->private))xfs_destroy_ioend (iocb->private);
fs/direct-io.c +53 -78
213 lines not on this page · raw message
include/linux/fs.h +8 -14
@@ -2265,9 +2265,11 @@ ssize_t __blockdev_direct_IO(int rw, str int lock_type);enum { -DIO_LOCKING =1 ,/* need locking between buffered and direct access */ -DIO_NO_LOCKING ,/* bdev; no locking at all between buffered/direct */ -DIO_OWN_LOCKING ,/* filesystem locks buffered and direct internally */ +/* need locking between buffered and direct access */ +DIO_LOCKING =0x01 , + +/* filesystem does not support filling holes */ +DIO_SKIP_HOLES =0x02 , }; static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
@@ -2276,7 +2278,8 @@ static inline ssize_t blockdev_direct_IO dio_iodone_t end_io) {return __blockdev_direct_IO (rw, iocb, inode, bdev, iov, offset, - nr_segs, get_block, end_io,DIO_LOCKING ); + nr_segs, get_block, end_io, +DIO_LOCKING |DIO_SKIP_HOLES ); } static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
@@ -2285,16 +2288,7 @@ static inline ssize_t blockdev_direct_IO dio_iodone_t end_io) {return __blockdev_direct_IO (rw, iocb, inode, bdev, iov, offset, - nr_segs, get_block, end_io,DIO_NO_LOCKING ); -} - -static inline ssize_t blockdev_direct_IO_own_locking (int rw,struct kiocb *iocb, -struct inode *inode,struct block_device *bdev,const struct iovec *iov, -loff_t offset,unsigned long nr_segs,get_block_t get_block, -dio_iodone_t end_io) -{ -return __blockdev_direct_IO (rw, iocb, inode, bdev, iov, offset, - nr_segs, get_block, end_io,DIO_OWN_LOCKING ); + nr_segs, get_block, end_io,0 ); }#endif