Commit 0e022ea8 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: introduce __get_node_page to reuse common code

There are duplicated code in between get_node_page and get_node_page_ra,
introduce __get_node_page to includes common parts of these two, and
export get_node_page and get_node_page_ra by reusing __get_node_page.
Signed-off-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent e8458725
...@@ -1060,56 +1060,35 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid) ...@@ -1060,56 +1060,35 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid)
f2fs_put_page(apage, err ? 1 : 0); f2fs_put_page(apage, err ? 1 : 0);
} }
struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) /*
* readahead MAX_RA_NODE number of node pages.
*/
void ra_node_pages(struct page *parent, int start)
{ {
struct page *page; struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
int err; struct blk_plug plug;
int i, end;
nid_t nid;
if (!nid) blk_start_plug(&plug);
return ERR_PTR(-ENOENT);
f2fs_bug_on(sbi, check_nid_range(sbi, nid));
repeat:
page = grab_cache_page(NODE_MAPPING(sbi), nid);
if (!page)
return ERR_PTR(-ENOMEM);
err = read_node_page(page, READ_SYNC); /* Then, try readahead for siblings of the desired node */
if (err < 0) { end = start + MAX_RA_NODE;
f2fs_put_page(page, 1); end = min(end, NIDS_PER_BLOCK);
return ERR_PTR(err); for (i = start; i < end; i++) {
} else if (err == LOCKED_PAGE) { nid = get_nid(parent, i, false);
goto page_hit; ra_node_page(sbi, nid);
} }
lock_page(page); blk_finish_plug(&plug);
if (unlikely(!PageUptodate(page))) {
f2fs_put_page(page, 1);
return ERR_PTR(-EIO);
}
if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
f2fs_put_page(page, 1);
goto repeat;
}
page_hit:
f2fs_bug_on(sbi, nid != nid_of_node(page));
return page;
} }
/* struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid,
* Return a locked page for the desired node page. struct page *parent, int start)
* And, readahead MAX_RA_NODE number of node pages.
*/
struct page *get_node_page_ra(struct page *parent, int start)
{ {
struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
struct blk_plug plug;
struct page *page; struct page *page;
int err, i, end; int err;
nid_t nid;
/* First, try getting the desired direct node. */
nid = get_nid(parent, start, false);
if (!nid) if (!nid)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
f2fs_bug_on(sbi, check_nid_range(sbi, nid)); f2fs_bug_on(sbi, check_nid_range(sbi, nid));
...@@ -1126,21 +1105,11 @@ struct page *get_node_page_ra(struct page *parent, int start) ...@@ -1126,21 +1105,11 @@ struct page *get_node_page_ra(struct page *parent, int start)
goto page_hit; goto page_hit;
} }
blk_start_plug(&plug); if (parent)
ra_node_pages(parent, start + 1);
/* Then, try readahead for siblings of the desired node */
end = start + MAX_RA_NODE;
end = min(end, NIDS_PER_BLOCK);
for (i = start + 1; i < end; i++) {
nid_t tnid;
tnid = get_nid(parent, i, false);
ra_node_page(sbi, tnid);
}
blk_finish_plug(&plug);
lock_page(page); lock_page(page);
if (unlikely(!PageUptodate(page))) { if (unlikely(!PageUptodate(page))) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
...@@ -1154,6 +1123,19 @@ struct page *get_node_page_ra(struct page *parent, int start) ...@@ -1154,6 +1123,19 @@ struct page *get_node_page_ra(struct page *parent, int start)
return page; return page;
} }
struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
{
return __get_node_page(sbi, nid, NULL, 0);
}
struct page *get_node_page_ra(struct page *parent, int start)
{
struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
nid_t nid = get_nid(parent, start, false);
return __get_node_page(sbi, nid, parent, start);
}
void sync_inode_page(struct dnode_of_data *dn) void sync_inode_page(struct dnode_of_data *dn)
{ {
if (IS_INODE(dn->node_page) || dn->inode_page == dn->node_page) { if (IS_INODE(dn->node_page) || dn->inode_page == dn->node_page) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment