Lines Matching defs:ref

14 #include "delayed-ref.h"
117 * from the shared data ref, we only have the leaf but we need
160 * ref->count >0:
161 * - incremented when a ref->count transitions to >0
162 * - decremented when a ref->count transitions to <1
215 static void free_pref(struct prelim_ref *ref)
217 kmem_cache_free(btrfs_prelim_ref_cache, ref);
286 struct prelim_ref *ref;
295 ref = rb_entry(parent, struct prelim_ref, rbnode);
296 result = prelim_ref_compare(ref, newref);
304 struct extent_inode_elem *eie = ref->inode_list;
310 ref->inode_list = newref->inode_list;
313 trace_btrfs_prelim_ref_merge(fs_info, ref, newref,
316 * A delayed ref can have newref->count < 0.
317 * The ref->count is updated to follow any
320 update_share_count(sc, ref->count,
321 ref->count + newref->count, newref);
322 ref->count += newref->count;
341 struct prelim_ref *ref, *next_ref;
343 rbtree_postorder_for_each_entry_safe(ref, next_ref,
345 free_inode_elem_list(ref->inode_list);
346 free_pref(ref);
397 struct prelim_ref *ref;
402 ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask);
403 if (!ref)
406 ref->root_id = root_id;
408 ref->key_for_search = *key;
410 memset(&ref->key_for_search, 0, sizeof(ref->key_for_search));
412 ref->inode_list = NULL;
413 ref->level = level;
414 ref->count = count;
415 ref->parent = parent;
416 ref->wanted_disk_byte = wanted_disk_byte;
417 prelim_ref_insert(fs_info, preftree, ref, sc);
450 struct prelim_ref *ref = NULL;
458 ref = rb_entry(parent, struct prelim_ref, rbnode);
459 result = prelim_ref_compare(ref, &target);
474 struct preftrees *preftrees, struct prelim_ref *ref,
481 struct btrfs_key *key_for_search = &ref->key_for_search;
485 u64 wanted_disk_byte = ref->wanted_disk_byte;
511 ref->root_id != btrfs_header_owner(eb)) {
518 while (!ret && count < ref->count) {
535 ref->root_id != btrfs_header_owner(eb))) {
552 if (ref->key_for_search.offset == key.offset - data_offset)
597 struct prelim_ref *ref, struct ulist *parents)
603 int level = ref->level;
604 struct btrfs_key search_key = ref->key_for_search;
615 root = btrfs_get_fs_root_commit_root(ctx->fs_info, path, ref->root_id);
617 root = btrfs_get_fs_root(ctx->fs_info, ref->root_id, false);
673 "search slot in root %llu (level %d, ref count %d) returned %d for key (%llu %u %llu)",
674 ref->root_id, level, ref->count, ret,
675 ref->key_for_search.objectid, ref->key_for_search.type,
676 ref->key_for_search.offset);
690 ret = add_all_parents(ctx, root, path, parents, preftrees, ref, level);
726 * the ref is moved onto the tree for indirect refs. After all missing
727 * keys are thus located, we iterate over the indirect ref tree, resolve
758 struct prelim_ref *ref;
760 ref = rb_entry(rnode, struct prelim_ref, rbnode);
761 if (WARN(ref->parent,
762 "BUG: direct ref found in indirect tree")) {
767 rb_erase_cached(&ref->rbnode, &preftrees->indirect.root);
770 if (ref->count == 0) {
771 free_pref(ref);
775 if (sc && ref->root_id != sc->root->root_key.objectid) {
776 free_pref(ref);
780 err = resolve_indirect_ref(ctx, path, preftrees, ref, parents);
786 prelim_ref_insert(ctx->fs_info, &preftrees->direct, ref,
790 free_pref(ref);
795 /* we put the first parent into the ref at hand */
798 ref->parent = node ? node->val : 0;
799 ref->inode_list = unode_aux_to_inode_list(node);
808 free_pref(ref);
812 memcpy(new_ref, ref, sizeof(*ref));
820 * Now it's a direct ref, put it in the direct tree. We must
821 * do this last because the ref could be merged/freed here.
823 prelim_ref_insert(ctx->fs_info, &preftrees->direct, ref, NULL);
843 struct prelim_ref *ref;
851 ref = rb_entry(node, struct prelim_ref, rbnode);
854 BUG_ON(ref->parent); /* should not be a direct ref */
855 BUG_ON(ref->key_for_search.type);
856 BUG_ON(!ref->wanted_disk_byte);
858 check.level = ref->level - 1;
859 check.owner_root = ref->root_id;
861 eb = read_tree_block(fs_info, ref->wanted_disk_byte, &check);
863 free_pref(ref);
867 free_pref(ref);
875 btrfs_item_key_to_cpu(eb, &ref->key_for_search, 0);
877 btrfs_node_key_to_cpu(eb, &ref->key_for_search, 0);
881 prelim_ref_insert(fs_info, &preftrees->indirect, ref, NULL);
925 struct btrfs_delayed_tree_ref *ref;
933 ref = btrfs_delayed_node_to_tree_ref(node);
934 ret = add_indirect_ref(fs_info, preftrees, ref->root,
935 key_ptr, ref->level + 1,
942 struct btrfs_delayed_tree_ref *ref;
944 ref = btrfs_delayed_node_to_tree_ref(node);
946 ret = add_direct_ref(fs_info, preftrees, ref->level + 1,
947 ref->parent, node->bytenr, count,
953 struct btrfs_delayed_data_ref *ref;
954 ref = btrfs_delayed_node_to_data_ref(node);
956 key.objectid = ref->objectid;
958 key.offset = ref->offset;
978 ret = add_indirect_ref(fs_info, preftrees, ref->root,
985 struct btrfs_delayed_data_ref *ref;
987 ref = btrfs_delayed_node_to_data_ref(node);
989 ret = add_direct_ref(fs_info, preftrees, 0, ref->parent,
1397 struct prelim_ref *ref;
1445 * means we have the path lock, we need to grab the ref head and
1591 ref = rb_entry(node, struct prelim_ref, rbnode);
1592 node = rb_next(&ref->rbnode);
1594 * ref->count < 0 can happen here if there are delayed
1601 * and would retain their original ref->count < 0.
1603 if (ctx->roots && ref->count && ref->root_id && ref->parent == 0) {
1605 ret = ulist_add(ctx->roots, ref->root_id, 0, GFP_NOFS);
1609 if (ref->count && ref->parent) {
1610 if (!ctx->skip_inode_ref_list && !ref->inode_list &&
1611 ref->level == 0) {
1615 check.level = ref->level;
1617 eb = read_tree_block(ctx->fs_info, ref->parent,
1638 ref->inode_list = eie;
1640 * We transferred the list ownership to the ref,
1646 ret = ulist_add_merge_ptr(ctx->refs, ref->parent,
1647 ref->inode_list,
1667 eie->next = ref->inode_list;
1672 * this ref to the ref we added to the 'refs' ulist.
1673 * So set this ref's inode list to NULL to avoid
1677 ref->inode_list = NULL;
1846 * shared but do not need a ref count.
1968 * during relocation as we may get a shared tree block ref
1969 * (direct ref) and a non-shared tree block ref (indirect
1970 * ref) for the same node/leaf.
2094 * Check that we're still looking at an extended ref key for
2276 * next ref. after the last ref was processed, 1 is returned.
2360 /* we can treat both ref types equally here */
2389 "ref for %llu resolved, key (%llu EXTEND_DATA %llu), root %llu",
2624 "following ref at offset %u for inode %llu in tree %llu",
2909 /* No inline nor keyed ref */
2942 * Caller needs to check whether it's inline ref or not by iter->cur_key.
2965 /* Use inline ref type to determine the size */
3451 * Parent node found and matches current inline ref, no need to
3452 * rebuild this node for this inline ref
3470 * key.type == BTRFS_TREE_BLOCK_REF_KEY, inline ref