Lines Matching refs:ref
11 #include "delayed-ref.h"
57 * Release a ref head's reservation.
62 * Drops the delayed ref head's count from the delayed refs rsv and free any
287 /* insert a new ref to head ref rbtree */
367 * Find a head entry based on bytenr. This returns the delayed ref head if it
427 struct btrfs_delayed_ref_node *ref)
430 rb_erase_cached(&ref->ref_node, &head->ref_tree);
431 RB_CLEAR_NODE(&ref->ref_node);
432 if (!list_empty(&ref->add_list))
433 list_del(&ref->add_list);
434 btrfs_put_delayed_ref(ref);
440 struct btrfs_delayed_ref_node *ref,
444 struct rb_node *node = rb_next(&ref->ref_node);
454 if (comp_refs(ref, next, false))
457 if (ref->action == next->action) {
460 if (ref->ref_mod < next->ref_mod) {
461 swap(ref, next);
468 ref->ref_mod += mod;
469 if (ref->ref_mod == 0) {
470 drop_delayed_ref(delayed_refs, head, ref);
474 * Can't have multiples of the same ref on a tree block.
476 WARN_ON(ref->type == BTRFS_TREE_BLOCK_REF_KEY ||
477 ref->type == BTRFS_SHARED_BLOCK_REF_KEY);
488 struct btrfs_delayed_ref_node *ref;
505 ref = rb_entry(node, struct btrfs_delayed_ref_node, ref_node);
506 if (seq && ref->seq >= seq)
508 if (merge_ref(delayed_refs, head, ref, seq))
583 * Return false if the ref was inserted.
584 * Return true if the ref was merged into an existing one (and therefore can be
589 struct btrfs_delayed_ref_node *ref)
595 exist = tree_insert(&href->ref_tree, ref);
597 if (ref->action == BTRFS_ADD_DELAYED_REF)
598 list_add_tail(&ref->add_list, &href->ref_add_list);
605 if (exist->action == ref->action) {
606 mod = ref->ref_mod;
609 if (exist->ref_mod < ref->ref_mod) {
610 exist->action = ref->action;
612 exist->ref_mod = ref->ref_mod;
613 if (ref->action == BTRFS_ADD_DELAYED_REF)
616 else if (ref->action == BTRFS_DROP_DELAYED_REF) {
623 mod = -ref->ref_mod;
635 * helper function to update the accounting in the head ref
652 * reallocated before the delayed ref
654 * with an existing head ref without
696 * If we are going to from a positive ref mod to a negative or vice
735 * The head node stores the sum of all the mods, so dropping a ref
744 * later modification deletes the delayed ref without ever
746 * ref->must_insert_reserved is the flag used to record that
816 * we've updated the existing ref, free the newly
817 * allocated ref
845 * @ref: The structure which is going to be initialized.
865 struct btrfs_delayed_ref_node *ref,
877 refcount_set(&ref->refs, 1);
878 ref->bytenr = bytenr;
879 ref->num_bytes = num_bytes;
880 ref->ref_mod = 1;
881 ref->action = action;
882 ref->seq = seq;
883 ref->type = ref_type;
884 RB_CLEAR_NODE(&ref->ref_node);
885 INIT_LIST_HEAD(&ref->add_list);
889 * add a delayed tree ref. This does all of the accounting required
890 * to make sure the delayed ref is eventually processed before this
898 struct btrfs_delayed_tree_ref *ref;
915 ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS);
916 if (!ref)
921 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref);
929 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref);
940 init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
943 ref->root = generic_ref->tree_ref.owning_root;
944 ref->parent = parent;
945 ref->level = level;
956 * insert both the head node and the new ref without dropping
962 merged = insert_delayed_ref(delayed_refs, head_ref, &ref->node);
971 trace_add_delayed_tree_ref(fs_info, &ref->node, ref,
975 kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref);
984 * add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref.
991 struct btrfs_delayed_data_ref *ref;
1007 ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS);
1008 if (!ref)
1015 init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
1017 ref->root = ref_root;
1018 ref->parent = parent;
1019 ref->objectid = owner;
1020 ref->offset = offset;
1025 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
1033 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
1048 * insert both the head node and the new ref without dropping
1054 merged = insert_delayed_ref(delayed_refs, head_ref, &ref->node);
1063 trace_add_delayed_data_ref(trans->fs_info, &ref->node, ref,
1067 kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);