Skip to content

Commit 0a9df0d

Browse files
Lu Fengqikdave
authored andcommitted
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: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> [ reformat comment ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 5ce5555 commit 0a9df0d

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

fs/btrfs/delayed-ref.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,27 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
164164
return NULL;
165165
}
166166

167+
static struct btrfs_delayed_ref_head *find_first_ref_head(
168+
struct btrfs_delayed_ref_root *dr)
169+
{
170+
struct rb_node *n;
171+
struct btrfs_delayed_ref_head *entry;
172+
173+
n = rb_first_cached(&dr->href_root);
174+
if (!n)
175+
return NULL;
176+
177+
entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node);
178+
179+
return entry;
180+
}
181+
167182
/*
168-
* find an head entry based on bytenr. This returns the delayed ref
169-
* head if it was able to find one, or NULL if nothing was in that spot.
170-
* If return_bigger is given, the next bigger entry is returned if no exact
171-
* match is found. But if no bigger one is found then the first node of the
172-
* ref head tree will be returned.
183+
* Find a head entry based on bytenr. This returns the delayed ref head if it
184+
* was able to find one, or NULL if nothing was in that spot. If return_bigger
185+
* is given, the next bigger entry is returned if no exact match is found.
173186
*/
174-
static struct btrfs_delayed_ref_head* find_ref_head(
187+
static struct btrfs_delayed_ref_head *find_ref_head(
175188
struct btrfs_delayed_ref_root *dr, u64 bytenr,
176189
bool return_bigger)
177190
{
@@ -195,10 +208,9 @@ static struct btrfs_delayed_ref_head* find_ref_head(
195208
if (bytenr > entry->bytenr) {
196209
n = rb_next(&entry->href_node);
197210
if (!n)
198-
n = rb_first_cached(&dr->href_root);
211+
return NULL;
199212
entry = rb_entry(n, struct btrfs_delayed_ref_head,
200213
href_node);
201-
return entry;
202214
}
203215
return entry;
204216
}
@@ -355,33 +367,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(
355367
struct btrfs_delayed_ref_root *delayed_refs)
356368
{
357369
struct btrfs_delayed_ref_head *head;
358-
u64 start;
359-
bool loop = false;
360370

361371
again:
362-
start = delayed_refs->run_delayed_start;
363-
head = find_ref_head(delayed_refs, start, true);
364-
if (!head && !loop) {
372+
head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start,
373+
true);
374+
if (!head && delayed_refs->run_delayed_start != 0) {
365375
delayed_refs->run_delayed_start = 0;
366-
start = 0;
367-
loop = true;
368-
head = find_ref_head(delayed_refs, start, true);
369-
if (!head)
370-
return NULL;
371-
} else if (!head && loop) {
372-
return NULL;
376+
head = find_first_ref_head(delayed_refs);
373377
}
378+
if (!head)
379+
return NULL;
374380

375381
while (head->processing) {
376382
struct rb_node *node;
377383

378384
node = rb_next(&head->href_node);
379385
if (!node) {
380-
if (loop)
386+
if (delayed_refs->run_delayed_start == 0)
381387
return NULL;
382388
delayed_refs->run_delayed_start = 0;
383-
start = 0;
384-
loop = true;
385389
goto again;
386390
}
387391
head = rb_entry(node, struct btrfs_delayed_ref_head,

0 commit comments

Comments
 (0)