@@ -164,14 +164,27 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
164
164
return NULL ;
165
165
}
166
166
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
+
167
182
/*
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.
173
186
*/
174
- static struct btrfs_delayed_ref_head * find_ref_head (
187
+ static struct btrfs_delayed_ref_head * find_ref_head (
175
188
struct btrfs_delayed_ref_root * dr , u64 bytenr ,
176
189
bool return_bigger )
177
190
{
@@ -195,10 +208,9 @@ static struct btrfs_delayed_ref_head* find_ref_head(
195
208
if (bytenr > entry -> bytenr ) {
196
209
n = rb_next (& entry -> href_node );
197
210
if (!n )
198
- n = rb_first_cached ( & dr -> href_root ) ;
211
+ return NULL ;
199
212
entry = rb_entry (n , struct btrfs_delayed_ref_head ,
200
213
href_node );
201
- return entry ;
202
214
}
203
215
return entry ;
204
216
}
@@ -355,33 +367,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(
355
367
struct btrfs_delayed_ref_root * delayed_refs )
356
368
{
357
369
struct btrfs_delayed_ref_head * head ;
358
- u64 start ;
359
- bool loop = false;
360
370
361
371
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 ) {
365
375
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 );
373
377
}
378
+ if (!head )
379
+ return NULL ;
374
380
375
381
while (head -> processing ) {
376
382
struct rb_node * node ;
377
383
378
384
node = rb_next (& head -> href_node );
379
385
if (!node ) {
380
- if (loop )
386
+ if (delayed_refs -> run_delayed_start == 0 )
381
387
return NULL ;
382
388
delayed_refs -> run_delayed_start = 0 ;
383
- start = 0 ;
384
- loop = true;
385
389
goto again ;
386
390
}
387
391
head = rb_entry (node , struct btrfs_delayed_ref_head ,
0 commit comments