@@ -85,6 +85,34 @@ static int comp_data_refs(struct btrfs_delayed_data_ref *ref1,
85
85
return 0 ;
86
86
}
87
87
88
+ static int comp_refs (struct btrfs_delayed_ref_node * ref1 ,
89
+ struct btrfs_delayed_ref_node * ref2 ,
90
+ bool check_seq )
91
+ {
92
+ int ret = 0 ;
93
+
94
+ if (ref1 -> type < ref2 -> type )
95
+ return -1 ;
96
+ if (ref1 -> type > ref2 -> type )
97
+ return 1 ;
98
+ if (ref1 -> type == BTRFS_TREE_BLOCK_REF_KEY ||
99
+ ref1 -> type == BTRFS_SHARED_BLOCK_REF_KEY )
100
+ ret = comp_tree_refs (btrfs_delayed_node_to_tree_ref (ref1 ),
101
+ btrfs_delayed_node_to_tree_ref (ref2 ));
102
+ else
103
+ ret = comp_data_refs (btrfs_delayed_node_to_data_ref (ref1 ),
104
+ btrfs_delayed_node_to_data_ref (ref2 ));
105
+ if (ret )
106
+ return ret ;
107
+ if (check_seq ) {
108
+ if (ref1 -> seq < ref2 -> seq )
109
+ return -1 ;
110
+ if (ref1 -> seq > ref2 -> seq )
111
+ return 1 ;
112
+ }
113
+ return 0 ;
114
+ }
115
+
88
116
/* insert a new ref to head ref rbtree */
89
117
static struct btrfs_delayed_ref_head * htree_insert (struct rb_root * root ,
90
118
struct rb_node * node )
@@ -217,18 +245,7 @@ static bool merge_ref(struct btrfs_trans_handle *trans,
217
245
if (seq && next -> seq >= seq )
218
246
goto next ;
219
247
220
- if (next -> type != ref -> type )
221
- goto next ;
222
-
223
- if ((ref -> type == BTRFS_TREE_BLOCK_REF_KEY ||
224
- ref -> type == BTRFS_SHARED_BLOCK_REF_KEY ) &&
225
- comp_tree_refs (btrfs_delayed_node_to_tree_ref (ref ),
226
- btrfs_delayed_node_to_tree_ref (next )))
227
- goto next ;
228
- if ((ref -> type == BTRFS_EXTENT_DATA_REF_KEY ||
229
- ref -> type == BTRFS_SHARED_DATA_REF_KEY ) &&
230
- comp_data_refs (btrfs_delayed_node_to_data_ref (ref ),
231
- btrfs_delayed_node_to_data_ref (next )))
248
+ if (comp_refs (ref , next , false))
232
249
goto next ;
233
250
234
251
if (ref -> action == next -> action ) {
@@ -402,18 +419,7 @@ add_delayed_ref_tail_merge(struct btrfs_trans_handle *trans,
402
419
exist = list_entry (href -> ref_list .prev , struct btrfs_delayed_ref_node ,
403
420
list );
404
421
/* No need to compare bytenr nor is_head */
405
- if (exist -> type != ref -> type || exist -> seq != ref -> seq )
406
- goto add_tail ;
407
-
408
- if ((exist -> type == BTRFS_TREE_BLOCK_REF_KEY ||
409
- exist -> type == BTRFS_SHARED_BLOCK_REF_KEY ) &&
410
- comp_tree_refs (btrfs_delayed_node_to_tree_ref (exist ),
411
- btrfs_delayed_node_to_tree_ref (ref )))
412
- goto add_tail ;
413
- if ((exist -> type == BTRFS_EXTENT_DATA_REF_KEY ||
414
- exist -> type == BTRFS_SHARED_DATA_REF_KEY ) &&
415
- comp_data_refs (btrfs_delayed_node_to_data_ref (exist ),
416
- btrfs_delayed_node_to_data_ref (ref )))
422
+ if (comp_refs (exist , ref , true))
417
423
goto add_tail ;
418
424
419
425
/* Now we are sure we can merge */
0 commit comments