Skip to content

Commit 97308f8

Browse files
author
Andreas Gruenbacher
committed
iomap: Support partial direct I/O on user copy failures
In iomap_dio_rw, when iomap_apply returns an -EFAULT error and the IOMAP_DIO_PARTIAL flag is set, complete the request synchronously and return a partial result. This allows the caller to deal with the page fault and retry the remainder of the request. Signed-off-by: Andreas Gruenbacher <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]>
1 parent 42c498c commit 97308f8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

fs/iomap/direct-io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
581581
if (iov_iter_rw(iter) == READ && iomi.pos >= dio->i_size)
582582
iov_iter_revert(iter, iomi.pos - dio->i_size);
583583

584+
if (ret == -EFAULT && dio->size && (dio_flags & IOMAP_DIO_PARTIAL)) {
585+
if (!(iocb->ki_flags & IOCB_NOWAIT))
586+
wait_for_completion = true;
587+
ret = 0;
588+
}
589+
584590
/* magic error code to fall back to buffered I/O */
585591
if (ret == -ENOTBLK) {
586592
wait_for_completion = true;

include/linux/iomap.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ struct iomap_dio_ops {
330330
*/
331331
#define IOMAP_DIO_OVERWRITE_ONLY (1 << 1)
332332

333+
/*
334+
* When a page fault occurs, return a partial synchronous result and allow
335+
* the caller to retry the rest of the operation after dealing with the page
336+
* fault.
337+
*/
338+
#define IOMAP_DIO_PARTIAL (1 << 2)
339+
333340
ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
334341
const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
335342
unsigned int dio_flags);

0 commit comments

Comments
 (0)