Skip to content

Commit 5375e7c

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: implement fscache-based metadata read
Implement the data plane of reading metadata from primary data blob over fscache. Signed-off-by: Jeffle Xu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 955b478 commit 5375e7c

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

fs/erofs/data.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
#include "internal.h"
88
#include <linux/prefetch.h>
9+
#include <linux/sched/mm.h>
910
#include <linux/dax.h>
1011
#include <trace/events/erofs.h>
1112

@@ -35,14 +36,20 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode,
3536
erofs_off_t offset = blknr_to_addr(blkaddr);
3637
pgoff_t index = offset >> PAGE_SHIFT;
3738
struct page *page = buf->page;
39+
struct folio *folio;
40+
unsigned int nofs_flag;
3841

3942
if (!page || page->index != index) {
4043
erofs_put_metabuf(buf);
41-
page = read_cache_page_gfp(mapping, index,
42-
mapping_gfp_constraint(mapping, ~__GFP_FS));
43-
if (IS_ERR(page))
44-
return page;
44+
45+
nofs_flag = memalloc_nofs_save();
46+
folio = read_cache_folio(mapping, index, NULL, NULL);
47+
memalloc_nofs_restore(nofs_flag);
48+
if (IS_ERR(folio))
49+
return folio;
50+
4551
/* should already be PageUptodate, no need to lock page */
52+
page = folio_file_page(folio, index);
4653
buf->page = page;
4754
}
4855
if (buf->kmap_type == EROFS_NO_KMAP) {
@@ -63,6 +70,10 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode,
6370
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
6471
erofs_blk_t blkaddr, enum erofs_kmap_type type)
6572
{
73+
if (erofs_is_fscache_mode(sb))
74+
return erofs_bread(buf, EROFS_SB(sb)->s_fscache->inode,
75+
blkaddr, type);
76+
6677
return erofs_bread(buf, sb->s_bdev->bd_inode, blkaddr, type);
6778
}
6879

fs/erofs/fscache.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,32 @@ static int erofs_fscache_read_folios(struct fscache_cookie *cookie,
5959
return ret;
6060
}
6161

62+
static int erofs_fscache_meta_readpage(struct file *data, struct page *page)
63+
{
64+
int ret;
65+
struct folio *folio = page_folio(page);
66+
struct super_block *sb = folio_mapping(folio)->host->i_sb;
67+
struct erofs_map_dev mdev = {
68+
.m_deviceid = 0,
69+
.m_pa = folio_pos(folio),
70+
};
71+
72+
ret = erofs_map_dev(sb, &mdev);
73+
if (ret)
74+
goto out;
75+
76+
ret = erofs_fscache_read_folios(mdev.m_fscache->cookie,
77+
folio_mapping(folio), folio_pos(folio),
78+
folio_size(folio), mdev.m_pa);
79+
if (!ret)
80+
folio_mark_uptodate(folio);
81+
out:
82+
folio_unlock(folio);
83+
return ret;
84+
}
85+
6286
static const struct address_space_operations erofs_fscache_meta_aops = {
87+
.readpage = erofs_fscache_meta_readpage,
6388
};
6489

6590
int erofs_fscache_register_cookie(struct super_block *sb,

0 commit comments

Comments
 (0)