Skip to content

Commit c5690dd

Browse files
Christoph Hellwigbrauner
authored andcommitted
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 <[email protected]> [hch: renamed to read_folio_range, pass less arguments] Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent e6caf01 commit c5690dd

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
@@ -671,7 +671,8 @@ static int iomap_read_folio_range(const struct iomap_iter *iter,
671671
return submit_bio_wait(&bio);
672672
}
673673

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

725-
status = iomap_read_folio_range(iter, folio,
726-
block_start, plen);
726+
if (write_ops && write_ops->read_folio_range)
727+
status = write_ops->read_folio_range(iter,
728+
folio, block_start, plen);
729+
else
730+
status = iomap_read_folio_range(iter,
731+
folio, block_start, plen);
727732
if (status)
728733
return status;
729734
}
@@ -839,7 +844,7 @@ static int iomap_write_begin(struct iomap_iter *iter,
839844
else if (srcmap->flags & IOMAP_F_BUFFER_HEAD)
840845
status = __block_write_begin_int(folio, pos, len, NULL, srcmap);
841846
else
842-
status = __iomap_write_begin(iter, len, folio);
847+
status = __iomap_write_begin(iter, write_ops, len, folio);
843848

844849
if (unlikely(status))
845850
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)