diff options
author | Chao Yu <chao2.yu@samsung.com> | 2014-12-08 01:59:17 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-12-08 17:19:08 -0500 |
commit | 66b00c186764e29765e8962a03556c329dee48e5 (patch) | |
tree | 7be01f708ec36bc988815e1dc3631672d0df0f22 /fs/f2fs/checkpoint.c | |
parent | 13da549460d549aec78a943e589f4ffc3fdc716c (diff) |
f2fs: introduce is_valid_blkaddr to cleanup codes in ra_meta_pages
This patch does cleanup work, it introduces is_valid_blkaddr() to include
verification code for blkaddr with upper and down boundary value which were in
ra_meta_pages previous.
Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/checkpoint.c')
-rw-r--r-- | fs/f2fs/checkpoint.c | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index f3ebfb5a8431..b2d5431d6850 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -87,22 +87,36 @@ struct page *get_meta_page_ra(struct f2fs_sb_info *sbi, pgoff_t index) | |||
87 | return get_meta_page(sbi, index); | 87 | return get_meta_page(sbi, index); |
88 | } | 88 | } |
89 | 89 | ||
90 | static inline block_t get_max_meta_blks(struct f2fs_sb_info *sbi, int type) | 90 | static inline bool is_valid_blkaddr(struct f2fs_sb_info *sbi, |
91 | block_t blkaddr, int type) | ||
91 | { | 92 | { |
92 | switch (type) { | 93 | switch (type) { |
93 | case META_NAT: | 94 | case META_NAT: |
94 | return NM_I(sbi)->max_nid / NAT_ENTRY_PER_BLOCK; | 95 | break; |
95 | case META_SIT: | 96 | case META_SIT: |
96 | return SIT_BLK_CNT(sbi); | 97 | if (unlikely(blkaddr >= SIT_BLK_CNT(sbi))) |
98 | return false; | ||
99 | break; | ||
97 | case META_SSA: | 100 | case META_SSA: |
98 | return MAIN_BLKADDR(sbi); | 101 | if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) || |
102 | blkaddr < SM_I(sbi)->ssa_blkaddr)) | ||
103 | return false; | ||
104 | break; | ||
99 | case META_CP: | 105 | case META_CP: |
100 | return SM_I(sbi)->sit_info->sit_base_addr; | 106 | if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr || |
107 | blkaddr < __start_cp_addr(sbi))) | ||
108 | return false; | ||
109 | break; | ||
101 | case META_POR: | 110 | case META_POR: |
102 | return MAX_BLKADDR(sbi); | 111 | if (unlikely(blkaddr >= MAX_BLKADDR(sbi) || |
112 | blkaddr < MAIN_BLKADDR(sbi))) | ||
113 | return false; | ||
114 | break; | ||
103 | default: | 115 | default: |
104 | BUG(); | 116 | BUG(); |
105 | } | 117 | } |
118 | |||
119 | return true; | ||
106 | } | 120 | } |
107 | 121 | ||
108 | /* | 122 | /* |
@@ -113,7 +127,6 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type | |||
113 | block_t prev_blk_addr = 0; | 127 | block_t prev_blk_addr = 0; |
114 | struct page *page; | 128 | struct page *page; |
115 | block_t blkno = start; | 129 | block_t blkno = start; |
116 | block_t max_blks = get_max_meta_blks(sbi, type); | ||
117 | 130 | ||
118 | struct f2fs_io_info fio = { | 131 | struct f2fs_io_info fio = { |
119 | .type = META, | 132 | .type = META, |
@@ -123,18 +136,20 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type | |||
123 | for (; nrpages-- > 0; blkno++) { | 136 | for (; nrpages-- > 0; blkno++) { |
124 | block_t blk_addr; | 137 | block_t blk_addr; |
125 | 138 | ||
139 | if (!is_valid_blkaddr(sbi, blkno, type)) | ||
140 | goto out; | ||
141 | |||
126 | switch (type) { | 142 | switch (type) { |
127 | case META_NAT: | 143 | case META_NAT: |
128 | /* get nat block addr */ | 144 | if (unlikely(blkno >= |
129 | if (unlikely(blkno >= max_blks)) | 145 | NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid))) |
130 | blkno = 0; | 146 | blkno = 0; |
147 | /* get nat block addr */ | ||
131 | blk_addr = current_nat_addr(sbi, | 148 | blk_addr = current_nat_addr(sbi, |
132 | blkno * NAT_ENTRY_PER_BLOCK); | 149 | blkno * NAT_ENTRY_PER_BLOCK); |
133 | break; | 150 | break; |
134 | case META_SIT: | 151 | case META_SIT: |
135 | /* get sit block addr */ | 152 | /* get sit block addr */ |
136 | if (unlikely(blkno >= max_blks)) | ||
137 | goto out; | ||
138 | blk_addr = current_sit_addr(sbi, | 153 | blk_addr = current_sit_addr(sbi, |
139 | blkno * SIT_ENTRY_PER_BLOCK); | 154 | blkno * SIT_ENTRY_PER_BLOCK); |
140 | if (blkno != start && prev_blk_addr + 1 != blk_addr) | 155 | if (blkno != start && prev_blk_addr + 1 != blk_addr) |
@@ -142,24 +157,8 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type | |||
142 | prev_blk_addr = blk_addr; | 157 | prev_blk_addr = blk_addr; |
143 | break; | 158 | break; |
144 | case META_SSA: | 159 | case META_SSA: |
145 | if (unlikely(blkno >= max_blks)) | ||
146 | goto out; | ||
147 | if (unlikely(blkno < SM_I(sbi)->ssa_blkaddr)) | ||
148 | goto out; | ||
149 | blk_addr = blkno; | ||
150 | break; | ||
151 | case META_CP: | 160 | case META_CP: |
152 | if (unlikely(blkno >= max_blks)) | ||
153 | goto out; | ||
154 | if (unlikely(blkno < __start_cp_addr(sbi))) | ||
155 | goto out; | ||
156 | blk_addr = blkno; | ||
157 | break; | ||
158 | case META_POR: | 161 | case META_POR: |
159 | if (unlikely(blkno >= max_blks)) | ||
160 | goto out; | ||
161 | if (unlikely(blkno < MAIN_BLKADDR(sbi))) | ||
162 | goto out; | ||
163 | blk_addr = blkno; | 162 | blk_addr = blkno; |
164 | break; | 163 | break; |
165 | default: | 164 | default: |