iomap: split size and error for iomap_dio_rw ->end_io

Modify the calling convention for the iomap_dio_rw ->end_io() callback.
Rather than passing either dio->error or dio->size as the 'size' argument,
instead pass both the dio->error and the dio->size value separately.

In the instance that an error occurred during a write, we currently cannot
determine whether any blocks have been allocated beyond the current EOF and
data has subsequently been written to these blocks within the ->end_io()
callback. As a result, we cannot judge whether we should take the truncate
failed write path. Having both dio->error and dio->size will allow us to
perform such checks within this callback.

Signed-off-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
[hch: minor cleanups]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
This commit is contained in:
Matthew Bobrowski 2019-09-19 15:32:44 -07:00 committed by Darrick J. Wong
parent 609488bc97
commit 6fe7b99014
3 changed files with 10 additions and 11 deletions

View File

@ -77,13 +77,10 @@ static ssize_t iomap_dio_complete(struct iomap_dio *dio)
loff_t offset = iocb->ki_pos; loff_t offset = iocb->ki_pos;
ssize_t ret; ssize_t ret;
if (dio->end_io) { if (dio->end_io)
ret = dio->end_io(iocb, ret = dio->end_io(iocb, dio->size, dio->error, dio->flags);
dio->error ? dio->error : dio->size, else
dio->flags);
} else {
ret = dio->error; ret = dio->error;
}
if (likely(!ret)) { if (likely(!ret)) {
ret = dio->size; ret = dio->size;

View File

@ -369,21 +369,23 @@ static int
xfs_dio_write_end_io( xfs_dio_write_end_io(
struct kiocb *iocb, struct kiocb *iocb,
ssize_t size, ssize_t size,
int error,
unsigned flags) unsigned flags)
{ {
struct inode *inode = file_inode(iocb->ki_filp); struct inode *inode = file_inode(iocb->ki_filp);
struct xfs_inode *ip = XFS_I(inode); struct xfs_inode *ip = XFS_I(inode);
loff_t offset = iocb->ki_pos; loff_t offset = iocb->ki_pos;
unsigned int nofs_flag; unsigned int nofs_flag;
int error = 0;
trace_xfs_end_io_direct_write(ip, offset, size); trace_xfs_end_io_direct_write(ip, offset, size);
if (XFS_FORCED_SHUTDOWN(ip->i_mount)) if (XFS_FORCED_SHUTDOWN(ip->i_mount))
return -EIO; return -EIO;
if (size <= 0) if (error)
return size; return error;
if (!size)
return 0;
/* /*
* Capture amount written on completion as we can't reliably account * Capture amount written on completion as we can't reliably account

View File

@ -188,8 +188,8 @@ sector_t iomap_bmap(struct address_space *mapping, sector_t bno,
*/ */
#define IOMAP_DIO_UNWRITTEN (1 << 0) /* covers unwritten extent(s) */ #define IOMAP_DIO_UNWRITTEN (1 << 0) /* covers unwritten extent(s) */
#define IOMAP_DIO_COW (1 << 1) /* covers COW extent(s) */ #define IOMAP_DIO_COW (1 << 1) /* covers COW extent(s) */
typedef int (iomap_dio_end_io_t)(struct kiocb *iocb, ssize_t ret, typedef int (iomap_dio_end_io_t)(struct kiocb *iocb, ssize_t size, int error,
unsigned flags); unsigned int flags);
ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
const struct iomap_ops *ops, iomap_dio_end_io_t end_io); const struct iomap_ops *ops, iomap_dio_end_io_t end_io);
int iomap_dio_iopoll(struct kiocb *kiocb, bool spin); int iomap_dio_iopoll(struct kiocb *kiocb, bool spin);