aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <chao2.yu@samsung.com>2016-01-05 03:52:46 -0500
committerJaegeuk Kim <jaegeuk@kernel.org>2016-01-08 14:45:20 -0500
commit0e022ea8fc49ed9c72ab9dcd9ca96414dc026184 (patch)
treeff499ae34af010d18034fb57101f764d920faa04
parente84587250ab7e38b7d85e93a8c317e065e5c0a1f (diff)
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: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/node.c88
1 files changed, 35 insertions, 53 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index c1ddf3d88dd9..5a2d800f4abc 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1060,56 +1060,35 @@ void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid)
1060 f2fs_put_page(apage, err ? 1 : 0); 1060 f2fs_put_page(apage, err ? 1 : 0);
1061} 1061}
1062 1062
1063struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) 1063/*
1064 * readahead MAX_RA_NODE number of node pages.
1065 */
1066void ra_node_pages(struct page *parent, int start)
1064{ 1067{
1065 struct page *page; 1068 struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
1066 int err; 1069 struct blk_plug plug;
1070 int i, end;
1071 nid_t nid;
1067 1072
1068 if (!nid) 1073 blk_start_plug(&plug);
1069 return ERR_PTR(-ENOENT);
1070 f2fs_bug_on(sbi, check_nid_range(sbi, nid));
1071repeat:
1072 page = grab_cache_page(NODE_MAPPING(sbi), nid);
1073 if (!page)
1074 return ERR_PTR(-ENOMEM);
1075 1074
1076 err = read_node_page(page, READ_SYNC); 1075 /* Then, try readahead for siblings of the desired node */
1077 if (err < 0) { 1076 end = start + MAX_RA_NODE;
1078 f2fs_put_page(page, 1); 1077 end = min(end, NIDS_PER_BLOCK);
1079 return ERR_PTR(err); 1078 for (i = start; i < end; i++) {
1080 } else if (err == LOCKED_PAGE) { 1079 nid = get_nid(parent, i, false);
1081 goto page_hit; 1080 ra_node_page(sbi, nid);
1082 } 1081 }
1083 1082
1084 lock_page(page); 1083 blk_finish_plug(&plug);
1085
1086 if (unlikely(!PageUptodate(page))) {
1087 f2fs_put_page(page, 1);
1088 return ERR_PTR(-EIO);
1089 }
1090 if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
1091 f2fs_put_page(page, 1);
1092 goto repeat;
1093 }
1094page_hit:
1095 f2fs_bug_on(sbi, nid != nid_of_node(page));
1096 return page;
1097} 1084}
1098 1085
1099/* 1086struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid,
1100 * Return a locked page for the desired node page. 1087 struct page *parent, int start)
1101 * And, readahead MAX_RA_NODE number of node pages.
1102 */
1103struct page *get_node_page_ra(struct page *parent, int start)
1104{ 1088{
1105 struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
1106 struct blk_plug plug;
1107 struct page *page; 1089 struct page *page;
1108 int err, i, end; 1090 int err;
1109 nid_t nid;
1110 1091
1111 /* First, try getting the desired direct node. */
1112 nid = get_nid(parent, start, false);
1113 if (!nid) 1092 if (!nid)
1114 return ERR_PTR(-ENOENT); 1093 return ERR_PTR(-ENOENT);
1115 f2fs_bug_on(sbi, check_nid_range(sbi, nid)); 1094 f2fs_bug_on(sbi, check_nid_range(sbi, nid));
@@ -1126,21 +1105,11 @@ repeat:
1126 goto page_hit; 1105 goto page_hit;
1127 } 1106 }
1128 1107
1129 blk_start_plug(&plug); 1108 if (parent)
1130 1109 ra_node_pages(parent, start + 1);
1131 /* Then, try readahead for siblings of the desired node */
1132 end = start + MAX_RA_NODE;
1133 end = min(end, NIDS_PER_BLOCK);
1134 for (i = start + 1; i < end; i++) {
1135 nid_t tnid;
1136
1137 tnid = get_nid(parent, i, false);
1138 ra_node_page(sbi, tnid);
1139 }
1140
1141 blk_finish_plug(&plug);
1142 1110
1143 lock_page(page); 1111 lock_page(page);
1112
1144 if (unlikely(!PageUptodate(page))) { 1113 if (unlikely(!PageUptodate(page))) {
1145 f2fs_put_page(page, 1); 1114 f2fs_put_page(page, 1);
1146 return ERR_PTR(-EIO); 1115 return ERR_PTR(-EIO);
@@ -1154,6 +1123,19 @@ page_hit:
1154 return page; 1123 return page;
1155} 1124}
1156 1125
1126struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid)
1127{
1128 return __get_node_page(sbi, nid, NULL, 0);
1129}
1130
1131struct page *get_node_page_ra(struct page *parent, int start)
1132{
1133 struct f2fs_sb_info *sbi = F2FS_P_SB(parent);
1134 nid_t nid = get_nid(parent, start, false);
1135
1136 return __get_node_page(sbi, nid, parent, start);
1137}
1138
1157void sync_inode_page(struct dnode_of_data *dn) 1139void sync_inode_page(struct dnode_of_data *dn)
1158{ 1140{
1159 if (IS_INODE(dn->node_page) || dn->inode_page == dn->node_page) { 1141 if (IS_INODE(dn->node_page) || dn->inode_page == dn->node_page) {