Skip to content

Commit 996b3a6

Browse files
author
Brian Foster
committed
iomap: add read_folio_range() handler for buffered writes
JIRA: https://issues.redhat.com/browse/RHEL-121230 commit c5690dd Author: Christoph Hellwig <hch@lst.de> Date: Thu Jul 10 15:33:37 2025 +0200 iomap: add read_folio_range() handler for buffered writes Add a read_folio_range() handler for buffered writes that filesystems may pass in if they wish to provide a custom handler for synchronously reading in the contents of a folio. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> [hch: renamed to read_folio_range, pass less arguments] Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/20250710133343.399917-14-hch@lst.de Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Brian Foster <bfoster@redhat.com>
1 parent be3436b commit 996b3a6

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Documentation/filesystems/iomap/operations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ The following address space operations can be wrapped easily:
6868
void (*put_folio)(struct inode *inode, loff_t pos, unsigned copied,
6969
struct folio *folio);
7070
bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap);
71+
int (*read_folio_range)(const struct iomap_iter *iter,
72+
struct folio *folio, loff_t pos, size_t len);
7173
};
7274
7375
iomap calls these functions:
@@ -123,6 +125,10 @@ iomap calls these functions:
123125
``->iomap_valid``, then the iomap should considered stale and the
124126
validation failed.
125127

128+
- ``read_folio_range``: Called to synchronously read in the range that will
129+
be written to. If this function is not provided, iomap will default to
130+
submitting a bio read request.
131+
126132
These ``struct kiocb`` flags are significant for buffered I/O with iomap:
127133

128134
* ``IOCB_NOWAIT``: Turns on ``IOMAP_NOWAIT``.

fs/iomap/buffered-io.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ static int iomap_read_folio_range(const struct iomap_iter *iter,
672672
return submit_bio_wait(&bio);
673673
}
674674

675-
static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
675+
static int __iomap_write_begin(const struct iomap_iter *iter,
676+
const struct iomap_write_ops *write_ops, size_t len,
676677
struct folio *folio)
677678
{
678679
struct iomap_folio_state *ifs;
@@ -723,8 +724,12 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
723724
if (iter->flags & IOMAP_NOWAIT)
724725
return -EAGAIN;
725726

726-
status = iomap_read_folio_range(iter, folio,
727-
block_start, plen);
727+
if (write_ops && write_ops->read_folio_range)
728+
status = write_ops->read_folio_range(iter,
729+
folio, block_start, plen);
730+
else
731+
status = iomap_read_folio_range(iter,
732+
folio, block_start, plen);
728733
if (status)
729734
return status;
730735
}
@@ -840,7 +845,7 @@ static int iomap_write_begin(struct iomap_iter *iter,
840845
else if (srcmap->flags & IOMAP_F_BUFFER_HEAD)
841846
status = __block_write_begin_int(folio, pos, len, NULL, srcmap);
842847
else
843-
status = __iomap_write_begin(iter, len, folio);
848+
status = __iomap_write_begin(iter, write_ops, len, folio);
844849

845850
if (unlikely(status))
846851
goto out_unlock;

include/linux/iomap.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ struct iomap_write_ops {
166166
* locked by the iomap code.
167167
*/
168168
bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap);
169+
170+
/*
171+
* Optional if the filesystem wishes to provide a custom handler for
172+
* reading in the contents of a folio, otherwise iomap will default to
173+
* submitting a bio read request.
174+
*
175+
* The read must be done synchronously.
176+
*/
177+
int (*read_folio_range)(const struct iomap_iter *iter,
178+
struct folio *folio, loff_t pos, size_t len);
169179
};
170180

171181
/*

0 commit comments

Comments
 (0)