f2fs: introduce __check_rb_tree_consistence
Introduce __check_rb_tree_consistence to check consistence of rb-tree based discard cache in runtime. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
0243a5f9da
commit
df0f6b44dd
3 changed files with 47 additions and 2 deletions
|
@ -159,6 +159,38 @@ struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root,
|
|||
return re;
|
||||
}
|
||||
|
||||
bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi,
|
||||
struct rb_root *root)
|
||||
{
|
||||
#ifdef CONFIG_F2FS_CHECK_FS
|
||||
struct rb_node *cur = rb_first(root), *next;
|
||||
struct rb_entry *cur_re, *next_re;
|
||||
|
||||
if (!cur)
|
||||
return true;
|
||||
|
||||
while (cur) {
|
||||
next = rb_next(cur);
|
||||
if (!next)
|
||||
return true;
|
||||
|
||||
cur_re = rb_entry(cur, struct rb_entry, rb_node);
|
||||
next_re = rb_entry(next, struct rb_entry, rb_node);
|
||||
|
||||
if (cur_re->ofs + cur_re->len > next_re->ofs) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO, "inconsistent rbtree, "
|
||||
"cur(%u, %u) next(%u, %u)",
|
||||
cur_re->ofs, cur_re->len,
|
||||
next_re->ofs, next_re->len);
|
||||
return false;
|
||||
}
|
||||
|
||||
cur = next;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct kmem_cache *extent_tree_slab;
|
||||
static struct kmem_cache *extent_node_slab;
|
||||
|
||||
|
|
|
@ -2620,6 +2620,8 @@ struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root,
|
|||
struct rb_entry **prev_entry, struct rb_entry **next_entry,
|
||||
struct rb_node ***insert_p, struct rb_node **insert_parent,
|
||||
bool force);
|
||||
bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi,
|
||||
struct rb_root *root);
|
||||
unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
|
||||
bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
|
||||
void f2fs_drop_extent_tree(struct inode *inode);
|
||||
|
|
|
@ -833,6 +833,7 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
|
|||
if (blkaddr > di.lstart) {
|
||||
dc->len = blkaddr - dc->lstart;
|
||||
__relocate_discard_cmd(dcc, dc);
|
||||
f2fs_bug_on(sbi, !__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
modified = true;
|
||||
}
|
||||
|
||||
|
@ -842,11 +843,15 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
|
|||
di.start + blkaddr + 1 - di.lstart,
|
||||
di.lstart + di.len - 1 - blkaddr,
|
||||
NULL, NULL);
|
||||
f2fs_bug_on(sbi,
|
||||
!__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
} else {
|
||||
dc->lstart++;
|
||||
dc->len--;
|
||||
dc->start++;
|
||||
__relocate_discard_cmd(dcc, dc);
|
||||
f2fs_bug_on(sbi,
|
||||
!__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -906,6 +911,8 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,
|
|||
__is_discard_back_mergeable(&di, &prev_dc->di)) {
|
||||
prev_dc->di.len += di.len;
|
||||
__relocate_discard_cmd(dcc, prev_dc);
|
||||
f2fs_bug_on(sbi,
|
||||
!__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
di = prev_dc->di;
|
||||
tdc = prev_dc;
|
||||
merged = true;
|
||||
|
@ -920,13 +927,17 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,
|
|||
__relocate_discard_cmd(dcc, next_dc);
|
||||
if (tdc)
|
||||
__remove_discard_cmd(sbi, tdc);
|
||||
|
||||
f2fs_bug_on(sbi,
|
||||
!__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
merged = true;
|
||||
}
|
||||
|
||||
if (!merged)
|
||||
if (!merged) {
|
||||
__insert_discard_tree(sbi, bdev, di.lstart, di.start,
|
||||
di.len, NULL, NULL);
|
||||
f2fs_bug_on(sbi,
|
||||
!__check_rb_tree_consistence(sbi, &dcc->root));
|
||||
}
|
||||
next:
|
||||
prev_dc = next_dc;
|
||||
if (!prev_dc)
|
||||
|
|
Loading…
Reference in a new issue