diff options
author | Chao Yu <yuchao0@huawei.com> | 2018-02-03 04:44:39 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-03-12 19:05:40 -0400 |
commit | fb0e72c8b94903be3a7e742ab0a4b53b89e7ee35 (patch) | |
tree | fdbc7f7837aeec1a0f453a17b2640cb41249bc4b /fs/f2fs/recovery.c | |
parent | 0f9ec2a8f65d72a454e99fb4f7351d7e01070385 (diff) |
f2fs: fix to handle looped node chain during recovery
There is no checksum in node block now, so bit-transition from hardware
can make node_footer.next_blkaddr being corrupted w/o any detection,
result in node chain becoming looped one.
For this condition, during recovery, in order to avoid running into dead
loop, let's detect it and just skip out.
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/recovery.c')
-rw-r--r-- | fs/f2fs/recovery.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index c5e5c45130b5..1b23d3febe4c 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c | |||
@@ -242,6 +242,9 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, | |||
242 | struct curseg_info *curseg; | 242 | struct curseg_info *curseg; |
243 | struct page *page = NULL; | 243 | struct page *page = NULL; |
244 | block_t blkaddr; | 244 | block_t blkaddr; |
245 | unsigned int loop_cnt = 0; | ||
246 | unsigned int free_blocks = sbi->user_block_count - | ||
247 | valid_user_blocks(sbi); | ||
245 | int err = 0; | 248 | int err = 0; |
246 | 249 | ||
247 | /* get node pages in the current segment */ | 250 | /* get node pages in the current segment */ |
@@ -294,6 +297,17 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, | |||
294 | if (IS_INODE(page) && is_dent_dnode(page)) | 297 | if (IS_INODE(page) && is_dent_dnode(page)) |
295 | entry->last_dentry = blkaddr; | 298 | entry->last_dentry = blkaddr; |
296 | next: | 299 | next: |
300 | /* sanity check in order to detect looped node chain */ | ||
301 | if (++loop_cnt >= free_blocks || | ||
302 | blkaddr == next_blkaddr_of_node(page)) { | ||
303 | f2fs_msg(sbi->sb, KERN_NOTICE, | ||
304 | "%s: detect looped node chain, " | ||
305 | "blkaddr:%u, next:%u", | ||
306 | __func__, blkaddr, next_blkaddr_of_node(page)); | ||
307 | err = -EINVAL; | ||
308 | break; | ||
309 | } | ||
310 | |||
297 | /* check next segment */ | 311 | /* check next segment */ |
298 | blkaddr = next_blkaddr_of_node(page); | 312 | blkaddr = next_blkaddr_of_node(page); |
299 | f2fs_put_page(page, 1); | 313 | f2fs_put_page(page, 1); |