提交 0a9df0df 编写于 作者: L Lu Fengqi 提交者: David Sterba

btrfs: delayed-ref: extract find_first_ref_head from find_ref_head

The find_ref_head shouldn't return the first entry even if no exact match
is found. So move the hidden behavior to higher level.

Besides, remove the useless local variables in the btrfs_select_ref_head.
Reviewed-by: NNikolay Borisov <nborisov@suse.com>
Signed-off-by: NLu Fengqi <lufq.fnst@cn.fujitsu.com>
[ reformat comment ]
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 5ce55557
...@@ -164,14 +164,27 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root, ...@@ -164,14 +164,27 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
return NULL; return NULL;
} }
static struct btrfs_delayed_ref_head *find_first_ref_head(
struct btrfs_delayed_ref_root *dr)
{
struct rb_node *n;
struct btrfs_delayed_ref_head *entry;
n = rb_first_cached(&dr->href_root);
if (!n)
return NULL;
entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node);
return entry;
}
/* /*
* find an head entry based on bytenr. This returns the delayed ref * Find a head entry based on bytenr. This returns the delayed ref head if it
* head if it was able to find one, or NULL if nothing was in that spot. * was able to find one, or NULL if nothing was in that spot. If return_bigger
* If return_bigger is given, the next bigger entry is returned if no exact * is given, the next bigger entry is returned if no exact match is found.
* match is found. But if no bigger one is found then the first node of the
* ref head tree will be returned.
*/ */
static struct btrfs_delayed_ref_head* find_ref_head( static struct btrfs_delayed_ref_head *find_ref_head(
struct btrfs_delayed_ref_root *dr, u64 bytenr, struct btrfs_delayed_ref_root *dr, u64 bytenr,
bool return_bigger) bool return_bigger)
{ {
...@@ -195,10 +208,9 @@ static struct btrfs_delayed_ref_head* find_ref_head( ...@@ -195,10 +208,9 @@ static struct btrfs_delayed_ref_head* find_ref_head(
if (bytenr > entry->bytenr) { if (bytenr > entry->bytenr) {
n = rb_next(&entry->href_node); n = rb_next(&entry->href_node);
if (!n) if (!n)
n = rb_first_cached(&dr->href_root); return NULL;
entry = rb_entry(n, struct btrfs_delayed_ref_head, entry = rb_entry(n, struct btrfs_delayed_ref_head,
href_node); href_node);
return entry;
} }
return entry; return entry;
} }
...@@ -355,33 +367,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( ...@@ -355,33 +367,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(
struct btrfs_delayed_ref_root *delayed_refs) struct btrfs_delayed_ref_root *delayed_refs)
{ {
struct btrfs_delayed_ref_head *head; struct btrfs_delayed_ref_head *head;
u64 start;
bool loop = false;
again: again:
start = delayed_refs->run_delayed_start; head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start,
head = find_ref_head(delayed_refs, start, true); true);
if (!head && !loop) { if (!head && delayed_refs->run_delayed_start != 0) {
delayed_refs->run_delayed_start = 0; delayed_refs->run_delayed_start = 0;
start = 0; head = find_first_ref_head(delayed_refs);
loop = true;
head = find_ref_head(delayed_refs, start, true);
if (!head)
return NULL;
} else if (!head && loop) {
return NULL;
} }
if (!head)
return NULL;
while (head->processing) { while (head->processing) {
struct rb_node *node; struct rb_node *node;
node = rb_next(&head->href_node); node = rb_next(&head->href_node);
if (!node) { if (!node) {
if (loop) if (delayed_refs->run_delayed_start == 0)
return NULL; return NULL;
delayed_refs->run_delayed_start = 0; delayed_refs->run_delayed_start = 0;
start = 0;
loop = true;
goto again; goto again;
} }
head = rb_entry(node, struct btrfs_delayed_ref_head, head = rb_entry(node, struct btrfs_delayed_ref_head,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册