Skip to content

Commit 32e850e

Browse files
Christoph Hellwigkawasaki
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]> Reviewed-by: "Darrick J. Wong" <[email protected]>
1 parent f2d77a4 commit 32e850e

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

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

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

724-
status = iomap_read_folio_range(iter, folio,
725-
block_start, plen);
725+
if (write_ops && write_ops->read_folio_range)
726+
status = write_ops->read_folio_range(iter,
727+
folio, block_start, plen);
728+
else
729+
status = iomap_read_folio_range(iter,
730+
folio, block_start, plen);
726731
if (status)
727732
return status;
728733
}
@@ -838,7 +843,7 @@ static int iomap_write_begin(struct iomap_iter *iter,
838843
else if (srcmap->flags & IOMAP_F_BUFFER_HEAD)
839844
status = __block_write_begin_int(folio, pos, len, NULL, srcmap);
840845
else
841-
status = __iomap_write_begin(iter, len, folio);
846+
status = __iomap_write_begin(iter, write_ops, len, folio);
842847

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