19 #include <linux/sched.h>
20 #include <linux/slab.h>
104 if (ref1->
seq < ref2->
seq)
106 if (ref1->
seq > ref2->
seq)
111 return comp_tree_refs(btrfs_delayed_node_to_tree_ref(ref2),
112 btrfs_delayed_node_to_tree_ref(ref1));
115 return comp_data_refs(btrfs_delayed_node_to_data_ref(ref2),
116 btrfs_delayed_node_to_data_ref(ref1));
142 cmp = comp_entry(entry, ins, 1);
151 rb_link_node(node, parent_node, p);
180 if (bytenr < entry->bytenr)
182 else if (bytenr > entry->
bytenr)
184 else if (!btrfs_delayed_ref_is_head(entry))
196 if (entry && return_bigger) {
223 spin_unlock(&delayed_refs->
lock);
226 spin_lock(&delayed_refs->
lock);
227 if (!head->
node.in_tree) {
229 btrfs_put_delayed_ref(&head->
node);
232 btrfs_put_delayed_ref(&head->
node);
242 btrfs_put_delayed_ref(ref);
265 if (seq && next->
seq >= seq)
267 if (comp_entry(ref, next, 0))
285 drop_delayed_ref(trans, delayed_refs, next);
288 drop_delayed_ref(trans, delayed_refs, ref);
335 if (seq && ref->
seq >= seq)
337 if (merge_ref(trans, delayed_refs, ref, seq))
355 if (seq >= elem->
seq) {
356 pr_debug(
"holding back delayed_ref %llu, lowest is "
357 "%llu (%p)\n", seq, elem->
seq, delayed_refs);
380 find_ref_head(&delayed_refs->
root, start + 1, &ref, 1);
387 while (node && count < 32) {
389 if (btrfs_delayed_ref_is_head(ref)) {
390 head = btrfs_delayed_node_to_head(ref);
391 if (list_empty(&head->
cluster)) {
448 drop_delayed_ref(trans, delayed_refs, existing);
477 existing_ref = btrfs_delayed_node_to_head(existing);
478 ref = btrfs_delayed_node_to_head(update);
512 existing_ref->
extent_op->update_flags = 1;
538 int must_insert_reserved = 0;
561 must_insert_reserved = 1;
563 must_insert_reserved = 0;
578 head_ref = btrfs_delayed_node_to_head(ref);
582 INIT_LIST_HEAD(&head_ref->
cluster);
585 trace_btrfs_delayed_ref_head(ref, head_ref, action);
587 existing = tree_insert(&delayed_refs->
root, &ref->
rb_node);
590 update_existing_head_ref(existing, ref);
611 u64 ref_root,
int level,
int action,
633 if (need_ref_seq(for_cow, ref_root))
637 full_ref = btrfs_delayed_node_to_tree_ref(ref);
638 full_ref->
parent = parent;
639 full_ref->
root = ref_root;
646 trace_btrfs_delayed_tree_ref(ref, full_ref, action);
648 existing = tree_insert(&delayed_refs->
root, &ref->
rb_node);
651 update_existing_ref(trans, delayed_refs, existing, ref);
671 int action,
int for_cow)
692 if (need_ref_seq(for_cow, ref_root))
696 full_ref = btrfs_delayed_node_to_data_ref(ref);
697 full_ref->
parent = parent;
698 full_ref->
root = ref_root;
707 trace_btrfs_delayed_data_ref(ref, full_ref, action);
709 existing = tree_insert(&delayed_refs->
root, &ref->
rb_node);
712 update_existing_ref(trans, delayed_refs, existing, ref);
732 u64 ref_root,
int level,
int action,
754 spin_lock(&delayed_refs->
lock);
760 add_delayed_ref_head(fs_info, trans, &head_ref->
node, bytenr,
761 num_bytes, action, 0);
763 add_delayed_tree_ref(fs_info, trans, &ref->
node, bytenr,
764 num_bytes, parent, ref_root, level, action,
766 spin_unlock(&delayed_refs->
lock);
767 if (need_ref_seq(for_cow, ref_root))
778 u64 bytenr,
u64 num_bytes,
780 u64 owner,
u64 offset,
int action,
802 spin_lock(&delayed_refs->
lock);
808 add_delayed_ref_head(fs_info, trans, &head_ref->
node, bytenr,
809 num_bytes, action, 1);
811 add_delayed_data_ref(fs_info, trans, &ref->
node, bytenr,
812 num_bytes, parent, ref_root, owner, offset,
814 spin_unlock(&delayed_refs->
lock);
815 if (need_ref_seq(for_cow, ref_root))
823 u64 bytenr,
u64 num_bytes,
836 spin_lock(&delayed_refs->
lock);
838 add_delayed_ref_head(fs_info, trans, &head_ref->
node, bytenr,
842 spin_unlock(&delayed_refs->
lock);
858 ref = find_ref_head(&delayed_refs->
root, bytenr,
NULL, 0);
860 return btrfs_delayed_node_to_head(ref);