Skip to content

Commit 1a1a3b5

Browse files
Brian Fosterbrauner
authored andcommitted
iomap: advance the iter directly on buffered writes
Modify the buffered write path to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Also remove the -EAGAIN return hack as it is no longer necessary now that separate return channels exist for processing progress and error returns. For example, the existing write handler must return either a count of bytes written or error if the write is interrupted, but presumably wants to return -EAGAIN directly in order to break the higher level iomap_iter() loop. Since the current iteration may have made some progress, it unwinds the iter on the way out to return the error while ensuring that portion of the write can be retried. If -EAGAIN occurs at any point beyond the first iteration, iomap_file_buffered_write() will then observe progress based on iter->pos to return a short write. With incremental advances on the iomap_iter, iomap_write_iter() can simply return the error. iomap_iter() completes whatever progress was made based on iomap_iter position and still breaks out of the iter loop based on the error code in iter.processed. The end result of the write is similar in terms of being a short write if progress was made or error return otherwise. Signed-off-by: Brian Foster <bfoster@redhat.com> Link: https://lore.kernel.org/r/20250207143253.314068-9-bfoster@redhat.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent bc264fe commit 1a1a3b5

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

fs/iomap/buffered-io.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,6 @@ static bool iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len,
905905

906906
static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
907907
{
908-
loff_t length = iomap_length(iter);
909-
loff_t pos = iter->pos;
910908
ssize_t total_written = 0;
911909
long status = 0;
912910
struct address_space *mapping = iter->inode->i_mapping;
@@ -919,7 +917,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
919917
size_t offset; /* Offset into folio */
920918
size_t bytes; /* Bytes to write to folio */
921919
size_t copied; /* Bytes copied from user */
922-
size_t written; /* Bytes have been written */
920+
u64 written; /* Bytes have been written */
921+
loff_t pos = iter->pos;
923922

924923
bytes = iov_iter_count(i);
925924
retry:
@@ -930,8 +929,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
930929
if (unlikely(status))
931930
break;
932931

933-
if (bytes > length)
934-
bytes = length;
932+
if (bytes > iomap_length(iter))
933+
bytes = iomap_length(iter);
935934

936935
/*
937936
* Bring in the user page that we'll copy from _first_.
@@ -1002,17 +1001,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
10021001
goto retry;
10031002
}
10041003
} else {
1005-
pos += written;
10061004
total_written += written;
1007-
length -= written;
1005+
iomap_iter_advance(iter, &written);
10081006
}
1009-
} while (iov_iter_count(i) && length);
1007+
} while (iov_iter_count(i) && iomap_length(iter));
10101008

1011-
if (status == -EAGAIN) {
1012-
iov_iter_revert(i, total_written);
1013-
return -EAGAIN;
1014-
}
1015-
return total_written ? total_written : status;
1009+
return total_written ? 0 : status;
10161010
}
10171011

10181012
ssize_t

0 commit comments

Comments
 (0)