[RFC PATCH v3 09/13] iomap: don't ask for a buffered fallback for dma-buf iterators
From: Nitesh Shetty
Date: Tue Dec 01 2026 - 11:56:16 EST
From: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>
-ENOTBLK tells the file system to retry the write as buffered I/O.
A dma-buf iterator has no pages, so it can't, and the write would end
as a zero-byte success.
Return a real error instead. A busy folio becomes -EAGAIN.
Other invalidation errors are returned as is.
-ENOTBLK from the file system's iomap_iter_next_fn callback becomes
-EOPNOTSUPP if nothing was transferred, while a partial transfer still
returns its progress.
Only files with a dma-buf I/O tag reach these branches.
XFS and ext4 add the tag in the last two patches.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@xxxxxxxxxx>
Signed-off-by: Li Wang <liwang@xxxxxxxxxx>
Signed-off-by: Anuj Gupta <anuj20.g@xxxxxxxxxxx>
Signed-off-by: Nitesh Shetty <nj.shetty@xxxxxxxxxxx>
---
Documentation/filesystems/iomap/operations.rst | 3 +++
fs/iomap/direct-io.c | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst
index a5784dee0850..1760021183e1 100644
--- a/Documentation/filesystems/iomap/operations.rst
+++ b/Documentation/filesystems/iomap/operations.rst
@@ -519,6 +519,9 @@ Return Values
cache before issuing the I/O to storage.
The ``begin`` or ``end`` functions may also return
this value.
+ A dma-buf iterator cannot fall back to buffered I/O, so it gets
+ ``-EAGAIN`` when the failure is retryable and ``-EOPNOTSUPP`` when no
+ data could be transferred.
* ``-EIOCBQUEUED``: The asynchronous direct I/O request has been
queued and will be completed separately.
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 1cd907204501..be7f3ef57d8a 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -718,7 +718,9 @@ static int iomap_dio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
* completing partial requests asynchronously.
*
* Returns -ENOTBLK In case of a page invalidation invalidation failure for
- * writes. The callers needs to fall back to buffered I/O in this case.
+ * writes. The callers needs to fall back to buffered I/O in this case. A
+ * dma-buf iterator cannot use that fallback, so it gets -EAGAIN when the
+ * failure is retryable and -EOPNOTSUPP when nothing was transferred.
*/
struct iomap_dio *
__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
@@ -818,7 +820,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
/*
* Try to invalidate cache pages for the range we are writing.
* If this invalidation fails, let the caller fall back to
- * buffered I/O.
+ * buffered I/O unless the iterator cannot be handled there.
*/
ret = kiocb_invalidate_pages(iocb, iomi.len);
if (ret) {
@@ -832,6 +834,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
* the caller tries again.
*/
ret = -EAGAIN;
+ } else if (iov_iter_is_dmabuf_map(iter)) {
+ /*
+ * a busy folio is transient, let the
+ * caller retry the direct write
+ */
+ if (ret == -EBUSY)
+ ret = -EAGAIN;
} else {
/* fall back to buffered write */
ret = -ENOTBLK;
@@ -879,6 +888,9 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
if (ret == -ENOTBLK) {
wait_for_completion = true;
ret = 0;
+ /* a partial transfer is still reported as a short I/O */
+ if (!dio->size && iov_iter_is_dmabuf_map(iter))
+ ret = -EOPNOTSUPP;
}
if (ret < 0)
iomap_dio_set_error(dio, ret);
--
2.47.3