Skip to content

Commit 3431d38

Browse files
committed
Merge patch series "iomap: erofs page cache sharing preliminaries"
Bring in the two changes needed in iomap and erofs to enable the page cache sharing work. * patches from https://patch.msgid.link/20260109102856.598531-1-lihongbo22@huawei.com: erofs: hold read context in iomap_iter if needed iomap: stash iomap read ctx in the private field of iomap_iter Link: https://patch.msgid.link/20260109102856.598531-1-lihongbo22@huawei.com Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents 8f0b4cc + 8d407bb commit 3431d38

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
lines changed

fs/erofs/data.c

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,20 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)
266266
folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO)));
267267
}
268268

269+
struct erofs_iomap_iter_ctx {
270+
struct page *page;
271+
void *base;
272+
};
273+
269274
static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
270275
unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
271276
{
272-
int ret;
277+
struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
278+
struct erofs_iomap_iter_ctx *ctx = iter->private;
273279
struct super_block *sb = inode->i_sb;
274280
struct erofs_map_blocks map;
275281
struct erofs_map_dev mdev;
282+
int ret;
276283

277284
map.m_la = offset;
278285
map.m_llen = length;
@@ -283,7 +290,6 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
283290
iomap->offset = map.m_la;
284291
iomap->length = map.m_llen;
285292
iomap->flags = 0;
286-
iomap->private = NULL;
287293
iomap->addr = IOMAP_NULL_ADDR;
288294
if (!(map.m_flags & EROFS_MAP_MAPPED)) {
289295
iomap->type = IOMAP_HOLE;
@@ -309,16 +315,20 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
309315
}
310316

311317
if (map.m_flags & EROFS_MAP_META) {
312-
void *ptr;
313-
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
314-
315318
iomap->type = IOMAP_INLINE;
316-
ptr = erofs_read_metabuf(&buf, sb, map.m_pa,
317-
erofs_inode_in_metabox(inode));
318-
if (IS_ERR(ptr))
319-
return PTR_ERR(ptr);
320-
iomap->inline_data = ptr;
321-
iomap->private = buf.base;
319+
/* read context should read the inlined data */
320+
if (ctx) {
321+
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
322+
void *ptr;
323+
324+
ptr = erofs_read_metabuf(&buf, sb, map.m_pa,
325+
erofs_inode_in_metabox(inode));
326+
if (IS_ERR(ptr))
327+
return PTR_ERR(ptr);
328+
iomap->inline_data = ptr;
329+
ctx->page = buf.page;
330+
ctx->base = buf.base;
331+
}
322332
} else {
323333
iomap->type = IOMAP_MAPPED;
324334
}
@@ -328,18 +338,18 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
328338
static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length,
329339
ssize_t written, unsigned int flags, struct iomap *iomap)
330340
{
331-
void *ptr = iomap->private;
341+
struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);
342+
struct erofs_iomap_iter_ctx *ctx = iter->private;
332343

333-
if (ptr) {
344+
if (ctx && ctx->base) {
334345
struct erofs_buf buf = {
335-
.page = kmap_to_page(ptr),
336-
.base = ptr,
346+
.page = ctx->page,
347+
.base = ctx->base,
337348
};
338349

339350
DBG_BUGON(iomap->type != IOMAP_INLINE);
340351
erofs_put_metabuf(&buf);
341-
} else {
342-
DBG_BUGON(iomap->type == IOMAP_INLINE);
352+
ctx->base = NULL;
343353
}
344354
return written;
345355
}
@@ -369,18 +379,30 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
369379
*/
370380
static int erofs_read_folio(struct file *file, struct folio *folio)
371381
{
382+
struct iomap_read_folio_ctx read_ctx = {
383+
.ops = &iomap_bio_read_ops,
384+
.cur_folio = folio,
385+
};
386+
struct erofs_iomap_iter_ctx iter_ctx = {};
387+
372388
trace_erofs_read_folio(folio, true);
373389

374-
iomap_bio_read_folio(folio, &erofs_iomap_ops);
390+
iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx);
375391
return 0;
376392
}
377393

378394
static void erofs_readahead(struct readahead_control *rac)
379395
{
396+
struct iomap_read_folio_ctx read_ctx = {
397+
.ops = &iomap_bio_read_ops,
398+
.rac = rac,
399+
};
400+
struct erofs_iomap_iter_ctx iter_ctx = {};
401+
380402
trace_erofs_readahead(rac->mapping->host, readahead_index(rac),
381403
readahead_count(rac), true);
382404

383-
iomap_bio_readahead(rac, &erofs_iomap_ops);
405+
iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx);
384406
}
385407

386408
static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
@@ -400,9 +422,12 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
400422
if (IS_DAX(inode))
401423
return dax_iomap_rw(iocb, to, &erofs_iomap_ops);
402424
#endif
403-
if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev)
425+
if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) {
426+
struct erofs_iomap_iter_ctx iter_ctx = {};
427+
404428
return iomap_dio_rw(iocb, to, &erofs_iomap_ops,
405-
NULL, 0, NULL, 0);
429+
NULL, 0, &iter_ctx, 0);
430+
}
406431
return filemap_read(iocb, to, 0);
407432
}
408433

fs/fuse/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int fuse_read_folio(struct file *file, struct folio *folio)
979979
return -EIO;
980980
}
981981

982-
iomap_read_folio(&fuse_iomap_ops, &ctx);
982+
iomap_read_folio(&fuse_iomap_ops, &ctx, NULL);
983983
fuse_invalidate_atime(inode);
984984
return 0;
985985
}
@@ -1081,7 +1081,7 @@ static void fuse_readahead(struct readahead_control *rac)
10811081
if (fuse_is_bad(inode))
10821082
return;
10831083

1084-
iomap_readahead(&fuse_iomap_ops, &ctx);
1084+
iomap_readahead(&fuse_iomap_ops, &ctx, NULL);
10851085
}
10861086

10871087
static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to)

fs/iomap/buffered-io.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,14 @@ static int iomap_read_folio_iter(struct iomap_iter *iter,
555555
}
556556

557557
void iomap_read_folio(const struct iomap_ops *ops,
558-
struct iomap_read_folio_ctx *ctx)
558+
struct iomap_read_folio_ctx *ctx, void *private)
559559
{
560560
struct folio *folio = ctx->cur_folio;
561561
struct iomap_iter iter = {
562562
.inode = folio->mapping->host,
563563
.pos = folio_pos(folio),
564564
.len = folio_size(folio),
565+
.private = private,
565566
};
566567
size_t bytes_submitted = 0;
567568
int ret;
@@ -620,13 +621,14 @@ static int iomap_readahead_iter(struct iomap_iter *iter,
620621
* the filesystem to be reentered.
621622
*/
622623
void iomap_readahead(const struct iomap_ops *ops,
623-
struct iomap_read_folio_ctx *ctx)
624+
struct iomap_read_folio_ctx *ctx, void *private)
624625
{
625626
struct readahead_control *rac = ctx->rac;
626627
struct iomap_iter iter = {
627628
.inode = rac->mapping->host,
628629
.pos = readahead_pos(rac),
629630
.len = readahead_length(rac),
631+
.private = private,
630632
};
631633
size_t cur_bytes_submitted;
632634

include/linux/iomap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
341341
const struct iomap_ops *ops,
342342
const struct iomap_write_ops *write_ops, void *private);
343343
void iomap_read_folio(const struct iomap_ops *ops,
344-
struct iomap_read_folio_ctx *ctx);
344+
struct iomap_read_folio_ctx *ctx, void *private);
345345
void iomap_readahead(const struct iomap_ops *ops,
346-
struct iomap_read_folio_ctx *ctx);
346+
struct iomap_read_folio_ctx *ctx, void *private);
347347
bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count);
348348
struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
349349
bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
@@ -595,7 +595,7 @@ static inline void iomap_bio_read_folio(struct folio *folio,
595595
.cur_folio = folio,
596596
};
597597

598-
iomap_read_folio(ops, &ctx);
598+
iomap_read_folio(ops, &ctx, NULL);
599599
}
600600

601601
static inline void iomap_bio_readahead(struct readahead_control *rac,
@@ -606,7 +606,7 @@ static inline void iomap_bio_readahead(struct readahead_control *rac,
606606
.rac = rac,
607607
};
608608

609-
iomap_readahead(ops, &ctx);
609+
iomap_readahead(ops, &ctx, NULL);
610610
}
611611
#endif /* CONFIG_BLOCK */
612612

0 commit comments

Comments
 (0)