[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210724193449.361667-7-agruenba@redhat.com>
Date: Sat, 24 Jul 2021 21:34:47 +0200
From: Andreas Gruenbacher <agruenba@...hat.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christoph Hellwig <hch@...radead.org>,
"Darrick J. Wong" <djwong@...nel.org>
Cc: Jan Kara <jack@...e.cz>, Matthew Wilcox <willy@...radead.org>,
cluster-devel@...hat.com, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, ocfs2-devel@....oracle.com,
Andreas Gruenbacher <agruenba@...hat.com>
Subject: [PATCH v4 6/8] iomap: Support restarting direct I/O requests after user copy failures
In iomap_dio_rw, when iomap_apply returns an -EFAULT error, complete the
request synchronously. Either return a partial result (when the
IOMAP_DIO_FAULT_RETRY flag is set and the caller is thus prepared to handle
partial results), or reset the iterator to the start to allow a restart.
Signed-off-by: Andreas Gruenbacher <agruenba@...hat.com>
---
fs/iomap/direct-io.c | 13 +++++++++++++
include/linux/iomap.h | 7 +++++++
2 files changed, 20 insertions(+)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 51831ce93f6e..1ba825bab08b 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -565,6 +565,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
ret = iomap_apply(inode, pos, count, iomap_flags, ops, dio,
iomap_dio_actor);
if (ret <= 0) {
+ if (ret == -EFAULT) {
+ /*
+ * Finish synchronously and revert the iterator
+ * when failing the request to allow a retry.
+ */
+ wait_for_completion = true;
+ if (dio->size &&
+ (dio_flags & IOMAP_DIO_FAULT_RETRY))
+ ret = 0;
+ else
+ iov_iter_revert(iter, dio->size);
+ }
+
/* magic error code to fall back to buffered I/O */
if (ret == -ENOTBLK) {
wait_for_completion = true;
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 8aea35f1a003..9dbba9f7c945 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -267,6 +267,13 @@ struct iomap_dio_ops {
*/
#define IOMAP_DIO_OVERWRITE_ONLY (1 << 1)
+/*
+ * When a page fault occurs, return a partial synchronous result and allow
+ * the caller to retry the rest of the operation after dealing with the page
+ * fault.
+ */
+#define IOMAP_DIO_FAULT_RETRY (1 << 2)
+
ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
unsigned int dio_flags, size_t done_before);
--
2.26.3
Powered by blists - more mailing lists