Lines Matching full:ref
10 #include "delayed-ref.h"
72 * btrfs_delayed_refs_rsv_release - release a ref head's reservation.
76 * This drops the delayed ref head's count from the delayed refs rsv and frees
276 /* insert a new ref to head ref rbtree */
356 * Find a head entry based on bytenr. This returns the delayed ref head if it
417 struct btrfs_delayed_ref_node *ref) in drop_delayed_ref() argument
420 rb_erase_cached(&ref->ref_node, &head->ref_tree); in drop_delayed_ref()
421 RB_CLEAR_NODE(&ref->ref_node); in drop_delayed_ref()
422 if (!list_empty(&ref->add_list)) in drop_delayed_ref()
423 list_del(&ref->add_list); in drop_delayed_ref()
424 ref->in_tree = 0; in drop_delayed_ref()
425 btrfs_put_delayed_ref(ref); in drop_delayed_ref()
432 struct btrfs_delayed_ref_node *ref, in merge_ref() argument
436 struct rb_node *node = rb_next(&ref->ref_node); in merge_ref()
446 if (comp_refs(ref, next, false)) in merge_ref()
449 if (ref->action == next->action) { in merge_ref()
452 if (ref->ref_mod < next->ref_mod) { in merge_ref()
453 swap(ref, next); in merge_ref()
460 ref->ref_mod += mod; in merge_ref()
461 if (ref->ref_mod == 0) { in merge_ref()
462 drop_delayed_ref(trans, delayed_refs, head, ref); in merge_ref()
466 * Can't have multiples of the same ref on a tree block. in merge_ref()
468 WARN_ON(ref->type == BTRFS_TREE_BLOCK_REF_KEY || in merge_ref()
469 ref->type == BTRFS_SHARED_BLOCK_REF_KEY); in merge_ref()
481 struct btrfs_delayed_ref_node *ref; in btrfs_merge_delayed_refs() local
507 ref = rb_entry(node, struct btrfs_delayed_ref_node, ref_node); in btrfs_merge_delayed_refs()
508 if (seq && ref->seq >= seq) in btrfs_merge_delayed_refs()
510 if (merge_ref(trans, delayed_refs, head, ref, seq)) in btrfs_merge_delayed_refs()
597 struct btrfs_delayed_ref_node *ref) in insert_delayed_ref() argument
604 exist = tree_insert(&href->ref_tree, ref); in insert_delayed_ref()
610 if (exist->action == ref->action) { in insert_delayed_ref()
611 mod = ref->ref_mod; in insert_delayed_ref()
614 if (exist->ref_mod < ref->ref_mod) { in insert_delayed_ref()
615 exist->action = ref->action; in insert_delayed_ref()
617 exist->ref_mod = ref->ref_mod; in insert_delayed_ref()
618 if (ref->action == BTRFS_ADD_DELAYED_REF) in insert_delayed_ref()
621 else if (ref->action == BTRFS_DROP_DELAYED_REF) { in insert_delayed_ref()
628 mod = -ref->ref_mod; in insert_delayed_ref()
638 if (ref->action == BTRFS_ADD_DELAYED_REF) in insert_delayed_ref()
639 list_add_tail(&ref->add_list, &href->ref_add_list); in insert_delayed_ref()
646 * helper function to update the accounting in the head ref
664 * reallocated before the delayed ref in update_existing_head_ref()
666 * with an existing head ref without in update_existing_head_ref()
710 * If we are going to from a positive ref mod to a negative or vice in update_existing_head_ref()
743 * The head node stores the sum of all the mods, so dropping a ref in init_delayed_ref_head()
754 * modification deletes the delayed ref without ever inserting the in init_delayed_ref_head()
755 * extent into the extent allocation tree. ref->must_insert_reserved in init_delayed_ref_head()
827 * we've updated the existing ref, free the newly in add_delayed_ref_head()
828 * allocated ref in add_delayed_ref_head()
860 * @ref: The structure which is going to be initialized.
880 struct btrfs_delayed_ref_node *ref, in init_delayed_ref_common() argument
892 refcount_set(&ref->refs, 1); in init_delayed_ref_common()
893 ref->bytenr = bytenr; in init_delayed_ref_common()
894 ref->num_bytes = num_bytes; in init_delayed_ref_common()
895 ref->ref_mod = 1; in init_delayed_ref_common()
896 ref->action = action; in init_delayed_ref_common()
897 ref->is_head = 0; in init_delayed_ref_common()
898 ref->in_tree = 1; in init_delayed_ref_common()
899 ref->seq = seq; in init_delayed_ref_common()
900 ref->type = ref_type; in init_delayed_ref_common()
901 RB_CLEAR_NODE(&ref->ref_node); in init_delayed_ref_common()
902 INIT_LIST_HEAD(&ref->add_list); in init_delayed_ref_common()
906 * add a delayed tree ref. This does all of the accounting required
907 * to make sure the delayed ref is eventually processed before this
916 struct btrfs_delayed_tree_ref *ref; in btrfs_add_delayed_tree_ref() local
934 ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS); in btrfs_add_delayed_tree_ref()
935 if (!ref) in btrfs_add_delayed_tree_ref()
940 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); in btrfs_add_delayed_tree_ref()
950 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); in btrfs_add_delayed_tree_ref()
961 init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes, in btrfs_add_delayed_tree_ref()
963 ref->root = generic_ref->tree_ref.root; in btrfs_add_delayed_tree_ref()
964 ref->parent = parent; in btrfs_add_delayed_tree_ref()
965 ref->level = level; in btrfs_add_delayed_tree_ref()
976 * insert both the head node and the new ref without dropping in btrfs_add_delayed_tree_ref()
983 ret = insert_delayed_ref(trans, delayed_refs, head_ref, &ref->node); in btrfs_add_delayed_tree_ref()
992 trace_add_delayed_tree_ref(fs_info, &ref->node, ref, in btrfs_add_delayed_tree_ref()
996 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); in btrfs_add_delayed_tree_ref()
1005 * add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref.
1013 struct btrfs_delayed_data_ref *ref; in btrfs_add_delayed_data_ref() local
1029 ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS); in btrfs_add_delayed_data_ref()
1030 if (!ref) in btrfs_add_delayed_data_ref()
1037 init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes, in btrfs_add_delayed_data_ref()
1039 ref->root = ref_root; in btrfs_add_delayed_data_ref()
1040 ref->parent = parent; in btrfs_add_delayed_data_ref()
1041 ref->objectid = owner; in btrfs_add_delayed_data_ref()
1042 ref->offset = offset; in btrfs_add_delayed_data_ref()
1047 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); in btrfs_add_delayed_data_ref()
1057 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); in btrfs_add_delayed_data_ref()
1072 * insert both the head node and the new ref without dropping in btrfs_add_delayed_data_ref()
1079 ret = insert_delayed_ref(trans, delayed_refs, head_ref, &ref->node); in btrfs_add_delayed_data_ref()
1088 trace_add_delayed_data_ref(trans->fs_info, &ref->node, ref, in btrfs_add_delayed_data_ref()
1092 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); in btrfs_add_delayed_data_ref()