From: Christoph Hellwig Date: Fri, 28 Apr 2017 01:27:09 +0000 (-0700) Subject: direct-io: always call ->end_io if non-NULL X-Git-Tag: v4.1.12-102.0.20170529_2200~68 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a27867b807d3771846e1cf6ae3052a95756b9753;p=users%2Fjedix%2Flinux-maple.git direct-io: always call ->end_io if non-NULL This way we can pass back errors to the file system, and allow for cleanup required for all direct I/O invocations. Also allow the ->end_io handlers to return errors on their own, so that I/O completion errors can be passed on to the callers. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner (cherry-picked commit from 187372a3b9faff68ed61c291d0135e6739e0dbdf) Orabug: 24393811 Conflicts: The change in the return type of the function dio_iodone_t broke the KABI. Hence, the original function return type is wrapped around under the flag __GENKSYMS__ Signed-off-by: Ashok Vairavan Reviewed-by: Darrick J. Wong --- diff --git a/fs/dax.c b/fs/dax.c index 5c548d821a2a6..2ba28af71b80c 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -264,8 +264,13 @@ ssize_t dax_do_io(struct kiocb *iocb, struct inode *inode, if ((flags & DIO_LOCKING) && iov_iter_rw(iter) == READ) mutex_unlock(&inode->i_mutex); - if ((retval > 0) && end_io) - end_io(iocb, pos, retval, bh.b_private); + if (end_io) { + int err; + + err = end_io(iocb, pos, retval, bh.b_private); + if (err) + retval = err; + } if (!(flags & DIO_SKIP_DIO_COUNT)) inode_dio_end(inode); diff --git a/fs/direct-io.c b/fs/direct-io.c index 9434d6a08119c..4664f5a2dac47 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -251,8 +251,13 @@ static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret, if (ret == 0) ret = transferred; - if (dio->end_io && dio->result) - dio->end_io(dio->iocb, offset, transferred, dio->private); + if (dio->end_io) { + int err; + + err = dio->end_io(dio->iocb, offset, ret, dio->private); + if (err) + ret = err; + } if (!(dio->flags & DIO_SKIP_DIO_COUNT)) inode_dio_end(dio->inode); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index c3f8fc88707b0..bb22f8176a307 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3095,14 +3095,17 @@ int ext4_get_block_dax(struct inode *inode, sector_t iblock, return _ext4_get_block(inode, iblock, bh_result, flags); } -static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, +static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset, ssize_t size, void *private) { ext4_io_end_t *io_end = iocb->private; + if (size <= 0) + return 0; + /* if not async direct IO just return */ if (!io_end) - return; + return 0; ext_debug("ext4_end_io_dio(): io_end 0x%p " "for inode %lu, iocb 0x%p, offset %llu, size %zd\n", @@ -3113,6 +3116,8 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, io_end->offset = offset; io_end->size = size; ext4_put_io_end(io_end); + + return 0; } /* diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index e378c5135334c..3a793bc4ad58e 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -608,7 +608,7 @@ bail: * particularly interested in the aio/dio case. We use the rw_lock DLM lock * to protect io on one node from truncation on another. */ -static void ocfs2_dio_end_io(struct kiocb *iocb, +static int ocfs2_dio_end_io(struct kiocb *iocb, loff_t offset, ssize_t bytes, void *private) @@ -617,6 +617,9 @@ static void ocfs2_dio_end_io(struct kiocb *iocb, int level; wait_queue_head_t *wq = ocfs2_ioend_wq(inode); + if (bytes <= 0) + return 0; + /* this io's submitter should not have unlocked this before we could */ BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); @@ -636,6 +639,8 @@ static void ocfs2_dio_end_io(struct kiocb *iocb, level = ocfs2_iocb_rw_locked_level(iocb); ocfs2_rw_unlock(inode, level); + + return 0; } static int ocfs2_releasepage(struct page *page, gfp_t wait) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 42624303277ba..89934e6665fa6 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -1649,7 +1649,7 @@ out_end_io: * case the completion can be called in interrupt context, whereas if we have an * ioend we will always be called in task context (i.e. from a workqueue). */ -STATIC void +STATIC int xfs_end_io_direct_write( struct kiocb *iocb, loff_t offset, @@ -1659,15 +1659,19 @@ xfs_end_io_direct_write( struct inode *inode = file_inode(iocb->ki_filp); struct xfs_ioend *ioend = private; + if (size <= 0) + return 0; + trace_xfs_gbmap_direct_endio(XFS_I(inode), offset, size, ioend ? ioend->io_type : 0, NULL); if (!ioend) { ASSERT(offset + size <= i_size_read(inode)); - return; + return 0; } __xfs_end_io_direct_write(inode, ioend, offset, size); + return 0; } static inline ssize_t @@ -1676,10 +1680,7 @@ xfs_vm_do_dio( struct kiocb *iocb, struct iov_iter *iter, loff_t offset, - void (*endio)(struct kiocb *iocb, - loff_t offset, - ssize_t size, - void *private), + dio_iodone_t endio, int flags) { struct block_device *bdev; diff --git a/include/linux/fs.h b/include/linux/fs.h index 8308813f5c12c..ab0abde661134 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -67,8 +67,13 @@ extern int sysctl_protected_hardlinks; struct buffer_head; typedef int (get_block_t)(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create); +#ifdef __GENKSYMS__ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, ssize_t bytes, void *private); +#else +typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, + ssize_t bytes, void *private); +#endif typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate); #define MAY_EXEC 0x00000001