Skip to content

Commit 3613f44

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 7d50f37 commit 3613f44

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
@@ -674,7 +674,8 @@ static int iomap_read_folio_range(const struct iomap_iter *iter,
674674
return submit_bio_wait(&bio);
675675
}
676676

677-
static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
677+
static int __iomap_write_begin(const struct iomap_iter *iter,
678+
const struct iomap_write_ops *write_ops, size_t len,
678679
struct folio *folio)
679680
{
680681
struct iomap_folio_state *ifs;
@@ -725,8 +726,12 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
725726
if (iter->flags & IOMAP_NOWAIT)
726727
return -EAGAIN;
727728

728-
status = iomap_read_folio_range(iter, folio,
729-
block_start, plen);
729+
if (write_ops && write_ops->read_folio_range)
730+
status = write_ops->read_folio_range(iter,
731+
folio, block_start, plen);
732+
else
733+
status = iomap_read_folio_range(iter,
734+
folio, block_start, plen);
730735
if (status)
731736
return status;
732737
}
@@ -842,7 +847,7 @@ static int iomap_write_begin(struct iomap_iter *iter,
842847
else if (srcmap->flags & IOMAP_F_BUFFER_HEAD)
843848
status = __block_write_begin_int(folio, pos, len, NULL, srcmap);
844849
else
845-
status = __iomap_write_begin(iter, len, folio);
850+
status = __iomap_write_begin(iter, write_ops, len, folio);
846851

847852
if (unlikely(status))
848853
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)