Skip to content

Commit 2e9b2bb

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: support 64-bits key in f2fs rb-tree node entry
then, we can add specified entry into rb-tree with 64-bits segment time as key. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c5d0278 commit 2e9b2bb

3 files changed

Lines changed: 49 additions & 7 deletions

File tree

‎fs/f2fs/extent_cache.c‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root,
5858
return re;
5959
}
6060

61+
struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi,
62+
struct rb_root_cached *root,
63+
struct rb_node **parent,
64+
unsigned long long key, bool *leftmost)
65+
{
66+
struct rb_node **p = &root->rb_root.rb_node;
67+
struct rb_entry *re;
68+
69+
while (*p) {
70+
*parent = *p;
71+
re = rb_entry(*parent, struct rb_entry, rb_node);
72+
73+
if (key < re->key) {
74+
p = &(*p)->rb_left;
75+
} else {
76+
p = &(*p)->rb_right;
77+
*leftmost = false;
78+
}
79+
}
80+
81+
return p;
82+
}
83+
6184
struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
6285
struct rb_root_cached *root,
6386
struct rb_node **parent,
@@ -166,7 +189,7 @@ struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root,
166189
}
167190

168191
bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
169-
struct rb_root_cached *root)
192+
struct rb_root_cached *root, bool check_key)
170193
{
171194
#ifdef CONFIG_F2FS_CHECK_FS
172195
struct rb_node *cur = rb_first_cached(root), *next;
@@ -183,13 +206,23 @@ bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
183206
cur_re = rb_entry(cur, struct rb_entry, rb_node);
184207
next_re = rb_entry(next, struct rb_entry, rb_node);
185208

209+
if (check_key) {
210+
if (cur_re->key > next_re->key) {
211+
f2fs_info(sbi, "inconsistent rbtree, "
212+
"cur(%llu) next(%llu)",
213+
cur_re->key, next_re->key);
214+
return false;
215+
}
216+
goto next;
217+
}
218+
186219
if (cur_re->ofs + cur_re->len > next_re->ofs) {
187220
f2fs_info(sbi, "inconsistent rbtree, cur(%u, %u) next(%u, %u)",
188221
cur_re->ofs, cur_re->len,
189222
next_re->ofs, next_re->len);
190223
return false;
191224
}
192-
225+
next:
193226
cur = next;
194227
}
195228
#endif

‎fs/f2fs/f2fs.h‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,13 @@ enum {
612612

613613
struct rb_entry {
614614
struct rb_node rb_node; /* rb node located in rb-tree */
615-
unsigned int ofs; /* start offset of the entry */
616-
unsigned int len; /* length of the entry */
615+
union {
616+
struct {
617+
unsigned int ofs; /* start offset of the entry */
618+
unsigned int len; /* length of the entry */
619+
};
620+
unsigned long long key; /* 64-bits key */
621+
};
617622
};
618623

619624
struct extent_info {
@@ -3806,6 +3811,10 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
38063811
*/
38073812
struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root,
38083813
struct rb_entry *cached_re, unsigned int ofs);
3814+
struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi,
3815+
struct rb_root_cached *root,
3816+
struct rb_node **parent,
3817+
unsigned long long key, bool *left_most);
38093818
struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
38103819
struct rb_root_cached *root,
38113820
struct rb_node **parent,
@@ -3816,7 +3825,7 @@ struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root,
38163825
struct rb_node ***insert_p, struct rb_node **insert_parent,
38173826
bool force, bool *leftmost);
38183827
bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
3819-
struct rb_root_cached *root);
3828+
struct rb_root_cached *root, bool check_key);
38203829
unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
38213830
void f2fs_init_extent_tree(struct inode *inode, struct page *ipage);
38223831
void f2fs_drop_extent_tree(struct inode *inode);

‎fs/f2fs/segment.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
15251525
goto next;
15261526
if (unlikely(dcc->rbtree_check))
15271527
f2fs_bug_on(sbi, !f2fs_check_rb_tree_consistence(sbi,
1528-
&dcc->root));
1528+
&dcc->root, false));
15291529
blk_start_plug(&plug);
15301530
list_for_each_entry_safe(dc, tmp, pend_list, list) {
15311531
f2fs_bug_on(sbi, dc->state != D_PREP);
@@ -2892,7 +2892,7 @@ static unsigned int __issue_discard_cmd_range(struct f2fs_sb_info *sbi,
28922892
mutex_lock(&dcc->cmd_lock);
28932893
if (unlikely(dcc->rbtree_check))
28942894
f2fs_bug_on(sbi, !f2fs_check_rb_tree_consistence(sbi,
2895-
&dcc->root));
2895+
&dcc->root, false));
28962896

28972897
dc = (struct discard_cmd *)f2fs_lookup_rb_tree_ret(&dcc->root,
28982898
NULL, start,

0 commit comments

Comments
 (0)