backref.c (4dae077a83dd8944ed351b09a0651c1283f46185) backref.c (e0c476b128e37daa37d630dd68da5681e9c16bab)
1/*
2 * Copyright (C) 2011 STRATO. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 373 unchanged lines hidden (view full) ---

382 }
383
384 return 0;
385}
386
387/*
388 * this structure records all encountered refs on the way up to the root
389 */
1/*
2 * Copyright (C) 2011 STRATO. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 373 unchanged lines hidden (view full) ---

382 }
383
384 return 0;
385}
386
387/*
388 * this structure records all encountered refs on the way up to the root
389 */
390struct __prelim_ref {
390struct prelim_ref {
391 struct list_head list;
392 u64 root_id;
393 struct btrfs_key key_for_search;
394 int level;
395 int count;
396 struct extent_inode_elem *inode_list;
397 u64 parent;
398 u64 wanted_disk_byte;
399};
400
401static struct kmem_cache *btrfs_prelim_ref_cache;
402
403int __init btrfs_prelim_ref_init(void)
404{
405 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
391 struct list_head list;
392 u64 root_id;
393 struct btrfs_key key_for_search;
394 int level;
395 int count;
396 struct extent_inode_elem *inode_list;
397 u64 parent;
398 u64 wanted_disk_byte;
399};
400
401static struct kmem_cache *btrfs_prelim_ref_cache;
402
403int __init btrfs_prelim_ref_init(void)
404{
405 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
406 sizeof(struct __prelim_ref),
406 sizeof(struct prelim_ref),
407 0,
408 SLAB_MEM_SPREAD,
409 NULL);
410 if (!btrfs_prelim_ref_cache)
411 return -ENOMEM;
412 return 0;
413}
414

--- 29 unchanged lines hidden (view full) ---

444 * --------------------+--------+----------+--------+----------
445 * parent logical | y | - | y | -
446 * key to resolve | - | - | - | y
447 * tree block logical | y | y | y | y
448 * root for resolving | - | y | y | y
449 *
450 * - column 1, 3: we've the parent -> done
451 * - column 2: we take the first key from the block to find the parent
407 0,
408 SLAB_MEM_SPREAD,
409 NULL);
410 if (!btrfs_prelim_ref_cache)
411 return -ENOMEM;
412 return 0;
413}
414

--- 29 unchanged lines hidden (view full) ---

444 * --------------------+--------+----------+--------+----------
445 * parent logical | y | - | y | -
446 * key to resolve | - | - | - | y
447 * tree block logical | y | y | y | y
448 * root for resolving | - | y | y | y
449 *
450 * - column 1, 3: we've the parent -> done
451 * - column 2: we take the first key from the block to find the parent
452 * (see __add_missing_keys)
452 * (see add_missing_keys)
453 * - column 4: we use the key to find the parent
454 *
455 * additional information that's available but not required to find the parent
456 * block might help in merging entries to gain some speed.
457 */
453 * - column 4: we use the key to find the parent
454 *
455 * additional information that's available but not required to find the parent
456 * block might help in merging entries to gain some speed.
457 */
458
459static int __add_prelim_ref(struct list_head *head, u64 root_id,
460 const struct btrfs_key *key, int level,
461 u64 parent, u64 wanted_disk_byte, int count,
462 gfp_t gfp_mask)
458static int add_prelim_ref(struct list_head *head, u64 root_id,
459 const struct btrfs_key *key, int level, u64 parent,
460 u64 wanted_disk_byte, int count, gfp_t gfp_mask)
463{
461{
464 struct __prelim_ref *ref;
462 struct prelim_ref *ref;
465
466 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID)
467 return 0;
468
469 ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask);
470 if (!ref)
471 return -ENOMEM;
472

--- 32 unchanged lines hidden (view full) ---

505 ref->parent = parent;
506 ref->wanted_disk_byte = wanted_disk_byte;
507 list_add_tail(&ref->list, head);
508
509 return 0;
510}
511
512static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
463
464 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID)
465 return 0;
466
467 ref = kmem_cache_alloc(btrfs_prelim_ref_cache, gfp_mask);
468 if (!ref)
469 return -ENOMEM;
470

--- 32 unchanged lines hidden (view full) ---

503 ref->parent = parent;
504 ref->wanted_disk_byte = wanted_disk_byte;
505 list_add_tail(&ref->list, head);
506
507 return 0;
508}
509
510static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
513 struct ulist *parents, struct __prelim_ref *ref,
511 struct ulist *parents, struct prelim_ref *ref,
514 int level, u64 time_seq, const u64 *extent_item_pos,
515 u64 total_refs)
516{
517 int ret = 0;
518 int slot;
519 struct extent_buffer *eb;
520 struct btrfs_key key;
521 struct btrfs_key *key_for_search = &ref->key_for_search;

--- 73 unchanged lines hidden (view full) ---

595 free_inode_elem_list(eie);
596 return ret;
597}
598
599/*
600 * resolve an indirect backref in the form (root_id, key, level)
601 * to a logical address
602 */
512 int level, u64 time_seq, const u64 *extent_item_pos,
513 u64 total_refs)
514{
515 int ret = 0;
516 int slot;
517 struct extent_buffer *eb;
518 struct btrfs_key key;
519 struct btrfs_key *key_for_search = &ref->key_for_search;

--- 73 unchanged lines hidden (view full) ---

593 free_inode_elem_list(eie);
594 return ret;
595}
596
597/*
598 * resolve an indirect backref in the form (root_id, key, level)
599 * to a logical address
600 */
603static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
604 struct btrfs_path *path, u64 time_seq,
605 struct __prelim_ref *ref,
606 struct ulist *parents,
607 const u64 *extent_item_pos, u64 total_refs)
601static int resolve_indirect_ref(struct btrfs_fs_info *fs_info,
602 struct btrfs_path *path, u64 time_seq,
603 struct prelim_ref *ref, struct ulist *parents,
604 const u64 *extent_item_pos, u64 total_refs)
608{
609 struct btrfs_root *root;
610 struct btrfs_key root_key;
611 struct extent_buffer *eb;
612 int ret = 0;
613 int root_level;
614 int level = ref->level;
615 int index;

--- 72 unchanged lines hidden (view full) ---

688 if (!node)
689 return NULL;
690 return (struct extent_inode_elem *)(uintptr_t)node->aux;
691}
692
693/*
694 * resolve all indirect backrefs from the list
695 */
605{
606 struct btrfs_root *root;
607 struct btrfs_key root_key;
608 struct extent_buffer *eb;
609 int ret = 0;
610 int root_level;
611 int level = ref->level;
612 int index;

--- 72 unchanged lines hidden (view full) ---

685 if (!node)
686 return NULL;
687 return (struct extent_inode_elem *)(uintptr_t)node->aux;
688}
689
690/*
691 * resolve all indirect backrefs from the list
692 */
696static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
697 struct btrfs_path *path, u64 time_seq,
698 struct list_head *head,
699 const u64 *extent_item_pos, u64 total_refs,
700 u64 root_objectid)
693static int resolve_indirect_refs(struct btrfs_fs_info *fs_info,
694 struct btrfs_path *path, u64 time_seq,
695 struct list_head *head,
696 const u64 *extent_item_pos, u64 total_refs,
697 u64 root_objectid)
701{
702 int err;
703 int ret = 0;
698{
699 int err;
700 int ret = 0;
704 struct __prelim_ref *ref;
705 struct __prelim_ref *ref_safe;
706 struct __prelim_ref *new_ref;
701 struct prelim_ref *ref;
702 struct prelim_ref *ref_safe;
703 struct prelim_ref *new_ref;
707 struct ulist *parents;
708 struct ulist_node *node;
709 struct ulist_iterator uiter;
710
711 parents = ulist_alloc(GFP_NOFS);
712 if (!parents)
713 return -ENOMEM;
714

--- 6 unchanged lines hidden (view full) ---

721 if (ref->parent) /* already direct */
722 continue;
723 if (ref->count == 0)
724 continue;
725 if (root_objectid && ref->root_id != root_objectid) {
726 ret = BACKREF_FOUND_SHARED;
727 goto out;
728 }
704 struct ulist *parents;
705 struct ulist_node *node;
706 struct ulist_iterator uiter;
707
708 parents = ulist_alloc(GFP_NOFS);
709 if (!parents)
710 return -ENOMEM;
711

--- 6 unchanged lines hidden (view full) ---

718 if (ref->parent) /* already direct */
719 continue;
720 if (ref->count == 0)
721 continue;
722 if (root_objectid && ref->root_id != root_objectid) {
723 ret = BACKREF_FOUND_SHARED;
724 goto out;
725 }
729 err = __resolve_indirect_ref(fs_info, path, time_seq, ref,
730 parents, extent_item_pos,
731 total_refs);
726 err = resolve_indirect_ref(fs_info, path, time_seq, ref,
727 parents, extent_item_pos,
728 total_refs);
732 /*
733 * we can only tolerate ENOENT,otherwise,we should catch error
734 * and return directly.
735 */
736 if (err == -ENOENT) {
737 continue;
738 } else if (err) {
739 ret = err;

--- 21 unchanged lines hidden (view full) ---

761 }
762 ulist_reinit(parents);
763 }
764out:
765 ulist_free(parents);
766 return ret;
767}
768
729 /*
730 * we can only tolerate ENOENT,otherwise,we should catch error
731 * and return directly.
732 */
733 if (err == -ENOENT) {
734 continue;
735 } else if (err) {
736 ret = err;

--- 21 unchanged lines hidden (view full) ---

758 }
759 ulist_reinit(parents);
760 }
761out:
762 ulist_free(parents);
763 return ret;
764}
765
769static inline int ref_for_same_block(struct __prelim_ref *ref1,
770 struct __prelim_ref *ref2)
766static inline int ref_for_same_block(struct prelim_ref *ref1,
767 struct prelim_ref *ref2)
771{
772 if (ref1->level != ref2->level)
773 return 0;
774 if (ref1->root_id != ref2->root_id)
775 return 0;
776 if (ref1->key_for_search.type != ref2->key_for_search.type)
777 return 0;
778 if (ref1->key_for_search.objectid != ref2->key_for_search.objectid)

--- 4 unchanged lines hidden (view full) ---

783 return 0;
784
785 return 1;
786}
787
788/*
789 * read tree blocks and add keys where required.
790 */
768{
769 if (ref1->level != ref2->level)
770 return 0;
771 if (ref1->root_id != ref2->root_id)
772 return 0;
773 if (ref1->key_for_search.type != ref2->key_for_search.type)
774 return 0;
775 if (ref1->key_for_search.objectid != ref2->key_for_search.objectid)

--- 4 unchanged lines hidden (view full) ---

780 return 0;
781
782 return 1;
783}
784
785/*
786 * read tree blocks and add keys where required.
787 */
791static int __add_missing_keys(struct btrfs_fs_info *fs_info,
792 struct list_head *head)
788static int add_missing_keys(struct btrfs_fs_info *fs_info,
789 struct list_head *head)
793{
790{
794 struct __prelim_ref *ref;
791 struct prelim_ref *ref;
795 struct extent_buffer *eb;
796
797 list_for_each_entry(ref, head, list) {
798 if (ref->parent)
799 continue;
800 if (ref->key_for_search.type)
801 continue;
802 BUG_ON(!ref->wanted_disk_byte);

--- 13 unchanged lines hidden (view full) ---

816 free_extent_buffer(eb);
817 }
818 return 0;
819}
820
821/*
822 * merge backrefs and adjust counts accordingly
823 *
792 struct extent_buffer *eb;
793
794 list_for_each_entry(ref, head, list) {
795 if (ref->parent)
796 continue;
797 if (ref->key_for_search.type)
798 continue;
799 BUG_ON(!ref->wanted_disk_byte);

--- 13 unchanged lines hidden (view full) ---

813 free_extent_buffer(eb);
814 }
815 return 0;
816}
817
818/*
819 * merge backrefs and adjust counts accordingly
820 *
824 * FIXME: For MERGE_IDENTICAL_KEYS, if we add more keys in __add_prelim_ref
821 * FIXME: For MERGE_IDENTICAL_KEYS, if we add more keys in add_prelim_ref
825 * then we can merge more here. Additionally, we could even add a key
826 * range for the blocks we looked into to merge even more (-> replace
827 * unresolved refs by those having a parent).
828 */
822 * then we can merge more here. Additionally, we could even add a key
823 * range for the blocks we looked into to merge even more (-> replace
824 * unresolved refs by those having a parent).
825 */
829static void __merge_refs(struct list_head *head, enum merge_mode mode)
826static void merge_refs(struct list_head *head, enum merge_mode mode)
830{
827{
831 struct __prelim_ref *pos1;
828 struct prelim_ref *pos1;
832
833 list_for_each_entry(pos1, head, list) {
829
830 list_for_each_entry(pos1, head, list) {
834 struct __prelim_ref *pos2 = pos1, *tmp;
831 struct prelim_ref *pos2 = pos1, *tmp;
835
836 list_for_each_entry_safe_continue(pos2, tmp, head, list) {
832
833 list_for_each_entry_safe_continue(pos2, tmp, head, list) {
837 struct __prelim_ref *ref1 = pos1, *ref2 = pos2;
834 struct prelim_ref *ref1 = pos1, *ref2 = pos2;
838 struct extent_inode_elem *eie;
839
840 if (!ref_for_same_block(ref1, ref2))
841 continue;
842 if (mode == MERGE_IDENTICAL_KEYS) {
843 if (!ref1->parent && ref2->parent)
844 swap(ref1, ref2);
845 } else {

--- 17 unchanged lines hidden (view full) ---

863
864 }
865}
866
867/*
868 * add all currently queued delayed refs from this head whose seq nr is
869 * smaller or equal that seq to the list
870 */
835 struct extent_inode_elem *eie;
836
837 if (!ref_for_same_block(ref1, ref2))
838 continue;
839 if (mode == MERGE_IDENTICAL_KEYS) {
840 if (!ref1->parent && ref2->parent)
841 swap(ref1, ref2);
842 } else {

--- 17 unchanged lines hidden (view full) ---

860
861 }
862}
863
864/*
865 * add all currently queued delayed refs from this head whose seq nr is
866 * smaller or equal that seq to the list
867 */
871static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
872 struct list_head *prefs, u64 *total_refs,
873 u64 inum)
868static int add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
869 struct list_head *prefs, u64 *total_refs,
870 u64 inum)
874{
875 struct btrfs_delayed_ref_node *node;
876 struct btrfs_delayed_extent_op *extent_op = head->extent_op;
877 struct btrfs_key key;
878 struct btrfs_key op_key = {0};
879 int sgn;
880 int ret = 0;
881

--- 20 unchanged lines hidden (view full) ---

902 BUG_ON(1);
903 }
904 *total_refs += (node->ref_mod * sgn);
905 switch (node->type) {
906 case BTRFS_TREE_BLOCK_REF_KEY: {
907 struct btrfs_delayed_tree_ref *ref;
908
909 ref = btrfs_delayed_node_to_tree_ref(node);
871{
872 struct btrfs_delayed_ref_node *node;
873 struct btrfs_delayed_extent_op *extent_op = head->extent_op;
874 struct btrfs_key key;
875 struct btrfs_key op_key = {0};
876 int sgn;
877 int ret = 0;
878

--- 20 unchanged lines hidden (view full) ---

899 BUG_ON(1);
900 }
901 *total_refs += (node->ref_mod * sgn);
902 switch (node->type) {
903 case BTRFS_TREE_BLOCK_REF_KEY: {
904 struct btrfs_delayed_tree_ref *ref;
905
906 ref = btrfs_delayed_node_to_tree_ref(node);
910 ret = __add_prelim_ref(prefs, ref->root, &op_key,
911 ref->level + 1, 0, node->bytenr,
912 node->ref_mod * sgn, GFP_ATOMIC);
907 ret = add_prelim_ref(prefs, ref->root, &op_key,
908 ref->level + 1, 0, node->bytenr,
909 node->ref_mod * sgn, GFP_ATOMIC);
913 break;
914 }
915 case BTRFS_SHARED_BLOCK_REF_KEY: {
916 struct btrfs_delayed_tree_ref *ref;
917
918 ref = btrfs_delayed_node_to_tree_ref(node);
910 break;
911 }
912 case BTRFS_SHARED_BLOCK_REF_KEY: {
913 struct btrfs_delayed_tree_ref *ref;
914
915 ref = btrfs_delayed_node_to_tree_ref(node);
919 ret = __add_prelim_ref(prefs, 0, NULL,
920 ref->level + 1, ref->parent,
921 node->bytenr,
922 node->ref_mod * sgn, GFP_ATOMIC);
916 ret = add_prelim_ref(prefs, 0, NULL, ref->level + 1,
917 ref->parent, node->bytenr,
918 node->ref_mod * sgn, GFP_ATOMIC);
923 break;
924 }
925 case BTRFS_EXTENT_DATA_REF_KEY: {
926 struct btrfs_delayed_data_ref *ref;
927 ref = btrfs_delayed_node_to_data_ref(node);
928
929 key.objectid = ref->objectid;
930 key.type = BTRFS_EXTENT_DATA_KEY;
931 key.offset = ref->offset;
932
933 /*
934 * Found a inum that doesn't match our known inum, we
935 * know it's shared.
936 */
937 if (inum && ref->objectid != inum) {
938 ret = BACKREF_FOUND_SHARED;
939 break;
940 }
941
919 break;
920 }
921 case BTRFS_EXTENT_DATA_REF_KEY: {
922 struct btrfs_delayed_data_ref *ref;
923 ref = btrfs_delayed_node_to_data_ref(node);
924
925 key.objectid = ref->objectid;
926 key.type = BTRFS_EXTENT_DATA_KEY;
927 key.offset = ref->offset;
928
929 /*
930 * Found a inum that doesn't match our known inum, we
931 * know it's shared.
932 */
933 if (inum && ref->objectid != inum) {
934 ret = BACKREF_FOUND_SHARED;
935 break;
936 }
937
942 ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0,
943 node->bytenr,
944 node->ref_mod * sgn, GFP_ATOMIC);
938 ret = add_prelim_ref(prefs, ref->root, &key, 0, 0,
939 node->bytenr, node->ref_mod * sgn,
940 GFP_ATOMIC);
945 break;
946 }
947 case BTRFS_SHARED_DATA_REF_KEY: {
948 struct btrfs_delayed_data_ref *ref;
949
950 ref = btrfs_delayed_node_to_data_ref(node);
941 break;
942 }
943 case BTRFS_SHARED_DATA_REF_KEY: {
944 struct btrfs_delayed_data_ref *ref;
945
946 ref = btrfs_delayed_node_to_data_ref(node);
951 ret = __add_prelim_ref(prefs, 0, NULL, 0,
952 ref->parent, node->bytenr,
953 node->ref_mod * sgn, GFP_ATOMIC);
947 ret = add_prelim_ref(prefs, 0, NULL, 0, ref->parent,
948 node->bytenr, node->ref_mod * sgn,
949 GFP_ATOMIC);
954 break;
955 }
956 default:
957 WARN_ON(1);
958 }
959 if (ret)
960 break;
961 }
962 spin_unlock(&head->lock);
963 return ret;
964}
965
966/*
967 * add all inline backrefs for bytenr to the list
968 */
950 break;
951 }
952 default:
953 WARN_ON(1);
954 }
955 if (ret)
956 break;
957 }
958 spin_unlock(&head->lock);
959 return ret;
960}
961
962/*
963 * add all inline backrefs for bytenr to the list
964 */
969static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
970 int *info_level, struct list_head *prefs,
971 struct ref_root *ref_tree,
972 u64 *total_refs, u64 inum)
965static int add_inline_refs(struct btrfs_path *path, u64 bytenr,
966 int *info_level, struct list_head *prefs,
967 struct ref_root *ref_tree,
968 u64 *total_refs, u64 inum)
973{
974 int ret = 0;
975 int slot;
976 struct extent_buffer *leaf;
977 struct btrfs_key key;
978 struct btrfs_key found_key;
979 unsigned long ptr;
980 unsigned long end;

--- 38 unchanged lines hidden (view full) ---

1019 int type;
1020
1021 iref = (struct btrfs_extent_inline_ref *)ptr;
1022 type = btrfs_extent_inline_ref_type(leaf, iref);
1023 offset = btrfs_extent_inline_ref_offset(leaf, iref);
1024
1025 switch (type) {
1026 case BTRFS_SHARED_BLOCK_REF_KEY:
969{
970 int ret = 0;
971 int slot;
972 struct extent_buffer *leaf;
973 struct btrfs_key key;
974 struct btrfs_key found_key;
975 unsigned long ptr;
976 unsigned long end;

--- 38 unchanged lines hidden (view full) ---

1015 int type;
1016
1017 iref = (struct btrfs_extent_inline_ref *)ptr;
1018 type = btrfs_extent_inline_ref_type(leaf, iref);
1019 offset = btrfs_extent_inline_ref_offset(leaf, iref);
1020
1021 switch (type) {
1022 case BTRFS_SHARED_BLOCK_REF_KEY:
1027 ret = __add_prelim_ref(prefs, 0, NULL,
1028 *info_level + 1, offset,
1029 bytenr, 1, GFP_NOFS);
1023 ret = add_prelim_ref(prefs, 0, NULL, *info_level + 1,
1024 offset, bytenr, 1, GFP_NOFS);
1030 break;
1031 case BTRFS_SHARED_DATA_REF_KEY: {
1032 struct btrfs_shared_data_ref *sdref;
1033 int count;
1034
1035 sdref = (struct btrfs_shared_data_ref *)(iref + 1);
1036 count = btrfs_shared_data_ref_count(leaf, sdref);
1025 break;
1026 case BTRFS_SHARED_DATA_REF_KEY: {
1027 struct btrfs_shared_data_ref *sdref;
1028 int count;
1029
1030 sdref = (struct btrfs_shared_data_ref *)(iref + 1);
1031 count = btrfs_shared_data_ref_count(leaf, sdref);
1037 ret = __add_prelim_ref(prefs, 0, NULL, 0, offset,
1038 bytenr, count, GFP_NOFS);
1032 ret = add_prelim_ref(prefs, 0, NULL, 0, offset,
1033 bytenr, count, GFP_NOFS);
1039 if (ref_tree) {
1040 if (!ret)
1041 ret = ref_tree_add(ref_tree, 0, 0, 0,
1042 bytenr, count);
1043 if (!ret && ref_tree->unique_refs > 1)
1044 ret = BACKREF_FOUND_SHARED;
1045 }
1046 break;
1047 }
1048 case BTRFS_TREE_BLOCK_REF_KEY:
1034 if (ref_tree) {
1035 if (!ret)
1036 ret = ref_tree_add(ref_tree, 0, 0, 0,
1037 bytenr, count);
1038 if (!ret && ref_tree->unique_refs > 1)
1039 ret = BACKREF_FOUND_SHARED;
1040 }
1041 break;
1042 }
1043 case BTRFS_TREE_BLOCK_REF_KEY:
1049 ret = __add_prelim_ref(prefs, offset, NULL,
1050 *info_level + 1, 0,
1051 bytenr, 1, GFP_NOFS);
1044 ret = add_prelim_ref(prefs, offset, NULL,
1045 *info_level + 1, 0,
1046 bytenr, 1, GFP_NOFS);
1052 break;
1053 case BTRFS_EXTENT_DATA_REF_KEY: {
1054 struct btrfs_extent_data_ref *dref;
1055 int count;
1056 u64 root;
1057
1058 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
1059 count = btrfs_extent_data_ref_count(leaf, dref);
1060 key.objectid = btrfs_extent_data_ref_objectid(leaf,
1061 dref);
1062 key.type = BTRFS_EXTENT_DATA_KEY;
1063 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
1064
1065 if (inum && key.objectid != inum) {
1066 ret = BACKREF_FOUND_SHARED;
1067 break;
1068 }
1069
1070 root = btrfs_extent_data_ref_root(leaf, dref);
1047 break;
1048 case BTRFS_EXTENT_DATA_REF_KEY: {
1049 struct btrfs_extent_data_ref *dref;
1050 int count;
1051 u64 root;
1052
1053 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
1054 count = btrfs_extent_data_ref_count(leaf, dref);
1055 key.objectid = btrfs_extent_data_ref_objectid(leaf,
1056 dref);
1057 key.type = BTRFS_EXTENT_DATA_KEY;
1058 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
1059
1060 if (inum && key.objectid != inum) {
1061 ret = BACKREF_FOUND_SHARED;
1062 break;
1063 }
1064
1065 root = btrfs_extent_data_ref_root(leaf, dref);
1071 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
1072 bytenr, count, GFP_NOFS);
1066 ret = add_prelim_ref(prefs, root, &key, 0, 0,
1067 bytenr, count, GFP_NOFS);
1073 if (ref_tree) {
1074 if (!ret)
1075 ret = ref_tree_add(ref_tree, root,
1076 key.objectid,
1077 key.offset, 0,
1078 count);
1079 if (!ret && ref_tree->unique_refs > 1)
1080 ret = BACKREF_FOUND_SHARED;

--- 9 unchanged lines hidden (view full) ---

1090 }
1091
1092 return 0;
1093}
1094
1095/*
1096 * add all non-inline backrefs for bytenr to the list
1097 */
1068 if (ref_tree) {
1069 if (!ret)
1070 ret = ref_tree_add(ref_tree, root,
1071 key.objectid,
1072 key.offset, 0,
1073 count);
1074 if (!ret && ref_tree->unique_refs > 1)
1075 ret = BACKREF_FOUND_SHARED;

--- 9 unchanged lines hidden (view full) ---

1085 }
1086
1087 return 0;
1088}
1089
1090/*
1091 * add all non-inline backrefs for bytenr to the list
1092 */
1098static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
1099 struct btrfs_path *path, u64 bytenr,
1100 int info_level, struct list_head *prefs,
1101 struct ref_root *ref_tree, u64 inum)
1093static int add_keyed_refs(struct btrfs_fs_info *fs_info,
1094 struct btrfs_path *path, u64 bytenr,
1095 int info_level, struct list_head *prefs,
1096 struct ref_root *ref_tree, u64 inum)
1102{
1103 struct btrfs_root *extent_root = fs_info->extent_root;
1104 int ret;
1105 int slot;
1106 struct extent_buffer *leaf;
1107 struct btrfs_key key;
1108
1109 while (1) {

--- 13 unchanged lines hidden (view full) ---

1123 break;
1124 if (key.type < BTRFS_TREE_BLOCK_REF_KEY)
1125 continue;
1126 if (key.type > BTRFS_SHARED_DATA_REF_KEY)
1127 break;
1128
1129 switch (key.type) {
1130 case BTRFS_SHARED_BLOCK_REF_KEY:
1097{
1098 struct btrfs_root *extent_root = fs_info->extent_root;
1099 int ret;
1100 int slot;
1101 struct extent_buffer *leaf;
1102 struct btrfs_key key;
1103
1104 while (1) {

--- 13 unchanged lines hidden (view full) ---

1118 break;
1119 if (key.type < BTRFS_TREE_BLOCK_REF_KEY)
1120 continue;
1121 if (key.type > BTRFS_SHARED_DATA_REF_KEY)
1122 break;
1123
1124 switch (key.type) {
1125 case BTRFS_SHARED_BLOCK_REF_KEY:
1131 ret = __add_prelim_ref(prefs, 0, NULL,
1132 info_level + 1, key.offset,
1133 bytenr, 1, GFP_NOFS);
1126 ret = add_prelim_ref(prefs, 0, NULL, info_level + 1,
1127 key.offset, bytenr, 1, GFP_NOFS);
1134 break;
1135 case BTRFS_SHARED_DATA_REF_KEY: {
1136 struct btrfs_shared_data_ref *sdref;
1137 int count;
1138
1139 sdref = btrfs_item_ptr(leaf, slot,
1140 struct btrfs_shared_data_ref);
1141 count = btrfs_shared_data_ref_count(leaf, sdref);
1128 break;
1129 case BTRFS_SHARED_DATA_REF_KEY: {
1130 struct btrfs_shared_data_ref *sdref;
1131 int count;
1132
1133 sdref = btrfs_item_ptr(leaf, slot,
1134 struct btrfs_shared_data_ref);
1135 count = btrfs_shared_data_ref_count(leaf, sdref);
1142 ret = __add_prelim_ref(prefs, 0, NULL, 0, key.offset,
1143 bytenr, count, GFP_NOFS);
1136 ret = add_prelim_ref(prefs, 0, NULL, 0, key.offset,
1137 bytenr, count, GFP_NOFS);
1144 if (ref_tree) {
1145 if (!ret)
1146 ret = ref_tree_add(ref_tree, 0, 0, 0,
1147 bytenr, count);
1148 if (!ret && ref_tree->unique_refs > 1)
1149 ret = BACKREF_FOUND_SHARED;
1150 }
1151 break;
1152 }
1153 case BTRFS_TREE_BLOCK_REF_KEY:
1138 if (ref_tree) {
1139 if (!ret)
1140 ret = ref_tree_add(ref_tree, 0, 0, 0,
1141 bytenr, count);
1142 if (!ret && ref_tree->unique_refs > 1)
1143 ret = BACKREF_FOUND_SHARED;
1144 }
1145 break;
1146 }
1147 case BTRFS_TREE_BLOCK_REF_KEY:
1154 ret = __add_prelim_ref(prefs, key.offset, NULL,
1155 info_level + 1, 0,
1156 bytenr, 1, GFP_NOFS);
1148 ret = add_prelim_ref(prefs, key.offset, NULL,
1149 info_level + 1, 0,
1150 bytenr, 1, GFP_NOFS);
1157 break;
1158 case BTRFS_EXTENT_DATA_REF_KEY: {
1159 struct btrfs_extent_data_ref *dref;
1160 int count;
1161 u64 root;
1162
1163 dref = btrfs_item_ptr(leaf, slot,
1164 struct btrfs_extent_data_ref);

--- 4 unchanged lines hidden (view full) ---

1169 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
1170
1171 if (inum && key.objectid != inum) {
1172 ret = BACKREF_FOUND_SHARED;
1173 break;
1174 }
1175
1176 root = btrfs_extent_data_ref_root(leaf, dref);
1151 break;
1152 case BTRFS_EXTENT_DATA_REF_KEY: {
1153 struct btrfs_extent_data_ref *dref;
1154 int count;
1155 u64 root;
1156
1157 dref = btrfs_item_ptr(leaf, slot,
1158 struct btrfs_extent_data_ref);

--- 4 unchanged lines hidden (view full) ---

1163 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
1164
1165 if (inum && key.objectid != inum) {
1166 ret = BACKREF_FOUND_SHARED;
1167 break;
1168 }
1169
1170 root = btrfs_extent_data_ref_root(leaf, dref);
1177 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
1178 bytenr, count, GFP_NOFS);
1171 ret = add_prelim_ref(prefs, root, &key, 0, 0,
1172 bytenr, count, GFP_NOFS);
1179 if (ref_tree) {
1180 if (!ret)
1181 ret = ref_tree_add(ref_tree, root,
1182 key.objectid,
1183 key.offset, 0,
1184 count);
1185 if (!ret && ref_tree->unique_refs > 1)
1186 ret = BACKREF_FOUND_SHARED;

--- 38 unchanged lines hidden (view full) ---

1225 struct btrfs_key key;
1226 struct btrfs_path *path;
1227 struct btrfs_delayed_ref_root *delayed_refs = NULL;
1228 struct btrfs_delayed_ref_head *head;
1229 int info_level = 0;
1230 int ret;
1231 struct list_head prefs_delayed;
1232 struct list_head prefs;
1173 if (ref_tree) {
1174 if (!ret)
1175 ret = ref_tree_add(ref_tree, root,
1176 key.objectid,
1177 key.offset, 0,
1178 count);
1179 if (!ret && ref_tree->unique_refs > 1)
1180 ret = BACKREF_FOUND_SHARED;

--- 38 unchanged lines hidden (view full) ---

1219 struct btrfs_key key;
1220 struct btrfs_path *path;
1221 struct btrfs_delayed_ref_root *delayed_refs = NULL;
1222 struct btrfs_delayed_ref_head *head;
1223 int info_level = 0;
1224 int ret;
1225 struct list_head prefs_delayed;
1226 struct list_head prefs;
1233 struct __prelim_ref *ref;
1227 struct prelim_ref *ref;
1234 struct extent_inode_elem *eie = NULL;
1235 struct ref_root *ref_tree = NULL;
1236 u64 total_refs = 0;
1237
1238 INIT_LIST_HEAD(&prefs);
1239 INIT_LIST_HEAD(&prefs_delayed);
1240
1241 key.objectid = bytenr;

--- 64 unchanged lines hidden (view full) ---

1306 * released and try again
1307 */
1308 mutex_lock(&head->mutex);
1309 mutex_unlock(&head->mutex);
1310 btrfs_put_delayed_ref(&head->node);
1311 goto again;
1312 }
1313 spin_unlock(&delayed_refs->lock);
1228 struct extent_inode_elem *eie = NULL;
1229 struct ref_root *ref_tree = NULL;
1230 u64 total_refs = 0;
1231
1232 INIT_LIST_HEAD(&prefs);
1233 INIT_LIST_HEAD(&prefs_delayed);
1234
1235 key.objectid = bytenr;

--- 64 unchanged lines hidden (view full) ---

1300 * released and try again
1301 */
1302 mutex_lock(&head->mutex);
1303 mutex_unlock(&head->mutex);
1304 btrfs_put_delayed_ref(&head->node);
1305 goto again;
1306 }
1307 spin_unlock(&delayed_refs->lock);
1314 ret = __add_delayed_refs(head, time_seq,
1315 &prefs_delayed, &total_refs,
1316 inum);
1308 ret = add_delayed_refs(head, time_seq,
1309 &prefs_delayed, &total_refs,
1310 inum);
1317 mutex_unlock(&head->mutex);
1318 if (ret)
1319 goto out;
1320 } else {
1321 spin_unlock(&delayed_refs->lock);
1322 }
1323
1324 if (check_shared && !list_empty(&prefs_delayed)) {

--- 33 unchanged lines hidden (view full) ---

1358
1359 path->slots[0]--;
1360 leaf = path->nodes[0];
1361 slot = path->slots[0];
1362 btrfs_item_key_to_cpu(leaf, &key, slot);
1363 if (key.objectid == bytenr &&
1364 (key.type == BTRFS_EXTENT_ITEM_KEY ||
1365 key.type == BTRFS_METADATA_ITEM_KEY)) {
1311 mutex_unlock(&head->mutex);
1312 if (ret)
1313 goto out;
1314 } else {
1315 spin_unlock(&delayed_refs->lock);
1316 }
1317
1318 if (check_shared && !list_empty(&prefs_delayed)) {

--- 33 unchanged lines hidden (view full) ---

1352
1353 path->slots[0]--;
1354 leaf = path->nodes[0];
1355 slot = path->slots[0];
1356 btrfs_item_key_to_cpu(leaf, &key, slot);
1357 if (key.objectid == bytenr &&
1358 (key.type == BTRFS_EXTENT_ITEM_KEY ||
1359 key.type == BTRFS_METADATA_ITEM_KEY)) {
1366 ret = __add_inline_refs(path, bytenr,
1367 &info_level, &prefs,
1368 ref_tree, &total_refs,
1369 inum);
1360 ret = add_inline_refs(path, bytenr, &info_level,
1361 &prefs, ref_tree, &total_refs,
1362 inum);
1370 if (ret)
1371 goto out;
1363 if (ret)
1364 goto out;
1372 ret = __add_keyed_refs(fs_info, path, bytenr,
1373 info_level, &prefs,
1374 ref_tree, inum);
1365 ret = add_keyed_refs(fs_info, path, bytenr, info_level,
1366 &prefs, ref_tree, inum);
1375 if (ret)
1376 goto out;
1377 }
1378 }
1379 btrfs_release_path(path);
1380
1381 list_splice_init(&prefs_delayed, &prefs);
1382
1367 if (ret)
1368 goto out;
1369 }
1370 }
1371 btrfs_release_path(path);
1372
1373 list_splice_init(&prefs_delayed, &prefs);
1374
1383 ret = __add_missing_keys(fs_info, &prefs);
1375 ret = add_missing_keys(fs_info, &prefs);
1384 if (ret)
1385 goto out;
1386
1376 if (ret)
1377 goto out;
1378
1387 __merge_refs(&prefs, MERGE_IDENTICAL_KEYS);
1379 merge_refs(&prefs, MERGE_IDENTICAL_KEYS);
1388
1380
1389 ret = __resolve_indirect_refs(fs_info, path, time_seq, &prefs,
1390 extent_item_pos, total_refs,
1391 root_objectid);
1381 ret = resolve_indirect_refs(fs_info, path, time_seq, &prefs,
1382 extent_item_pos, total_refs,
1383 root_objectid);
1392 if (ret)
1393 goto out;
1394
1384 if (ret)
1385 goto out;
1386
1395 __merge_refs(&prefs, MERGE_IDENTICAL_PARENTS);
1387 merge_refs(&prefs, MERGE_IDENTICAL_PARENTS);
1396
1397 while (!list_empty(&prefs)) {
1388
1389 while (!list_empty(&prefs)) {
1398 ref = list_first_entry(&prefs, struct __prelim_ref, list);
1390 ref = list_first_entry(&prefs, struct prelim_ref, list);
1399 WARN_ON(ref->count < 0);
1400 if (roots && ref->count && ref->root_id && ref->parent == 0) {
1401 if (root_objectid && ref->root_id != root_objectid) {
1402 ret = BACKREF_FOUND_SHARED;
1403 goto out;
1404 }
1405
1406 /* no parent == root of tree */

--- 45 unchanged lines hidden (view full) ---

1452 list_del(&ref->list);
1453 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1454 }
1455
1456out:
1457 btrfs_free_path(path);
1458 ref_root_free(ref_tree);
1459 while (!list_empty(&prefs)) {
1391 WARN_ON(ref->count < 0);
1392 if (roots && ref->count && ref->root_id && ref->parent == 0) {
1393 if (root_objectid && ref->root_id != root_objectid) {
1394 ret = BACKREF_FOUND_SHARED;
1395 goto out;
1396 }
1397
1398 /* no parent == root of tree */

--- 45 unchanged lines hidden (view full) ---

1444 list_del(&ref->list);
1445 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1446 }
1447
1448out:
1449 btrfs_free_path(path);
1450 ref_root_free(ref_tree);
1451 while (!list_empty(&prefs)) {
1460 ref = list_first_entry(&prefs, struct __prelim_ref, list);
1452 ref = list_first_entry(&prefs, struct prelim_ref, list);
1461 list_del(&ref->list);
1462 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1463 }
1464 while (!list_empty(&prefs_delayed)) {
1453 list_del(&ref->list);
1454 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1455 }
1456 while (!list_empty(&prefs_delayed)) {
1465 ref = list_first_entry(&prefs_delayed, struct __prelim_ref,
1457 ref = list_first_entry(&prefs_delayed, struct prelim_ref,
1466 list);
1467 list_del(&ref->list);
1468 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1469 }
1470 if (ret < 0)
1471 free_inode_elem_list(eie);
1472 return ret;
1473}

--- 53 unchanged lines hidden (view full) ---

1527 * find all referencing extents for the extent in question and put them on a
1528 * list. In turn, we find all referencing extents for those, further appending
1529 * to the list. The way we iterate the list allows adding more elements after
1530 * the current while iterating. The process stops when we reach the end of the
1531 * list. Found roots are added to the roots list.
1532 *
1533 * returns 0 on success, < 0 on error.
1534 */
1458 list);
1459 list_del(&ref->list);
1460 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1461 }
1462 if (ret < 0)
1463 free_inode_elem_list(eie);
1464 return ret;
1465}

--- 53 unchanged lines hidden (view full) ---

1519 * find all referencing extents for the extent in question and put them on a
1520 * list. In turn, we find all referencing extents for those, further appending
1521 * to the list. The way we iterate the list allows adding more elements after
1522 * the current while iterating. The process stops when we reach the end of the
1523 * list. Found roots are added to the roots list.
1524 *
1525 * returns 0 on success, < 0 on error.
1526 */
1535static int __btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1536 struct btrfs_fs_info *fs_info, u64 bytenr,
1537 u64 time_seq, struct ulist **roots)
1527static int btrfs_find_all_roots_safe(struct btrfs_trans_handle *trans,
1528 struct btrfs_fs_info *fs_info, u64 bytenr,
1529 u64 time_seq, struct ulist **roots)
1538{
1539 struct ulist *tmp;
1540 struct ulist_node *node = NULL;
1541 struct ulist_iterator uiter;
1542 int ret;
1543
1544 tmp = ulist_alloc(GFP_NOFS);
1545 if (!tmp)

--- 27 unchanged lines hidden (view full) ---

1573int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1574 struct btrfs_fs_info *fs_info, u64 bytenr,
1575 u64 time_seq, struct ulist **roots)
1576{
1577 int ret;
1578
1579 if (!trans)
1580 down_read(&fs_info->commit_root_sem);
1530{
1531 struct ulist *tmp;
1532 struct ulist_node *node = NULL;
1533 struct ulist_iterator uiter;
1534 int ret;
1535
1536 tmp = ulist_alloc(GFP_NOFS);
1537 if (!tmp)

--- 27 unchanged lines hidden (view full) ---

1565int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1566 struct btrfs_fs_info *fs_info, u64 bytenr,
1567 u64 time_seq, struct ulist **roots)
1568{
1569 int ret;
1570
1571 if (!trans)
1572 down_read(&fs_info->commit_root_sem);
1581 ret = __btrfs_find_all_roots(trans, fs_info, bytenr, time_seq, roots);
1573 ret = btrfs_find_all_roots_safe(trans, fs_info, bytenr,
1574 time_seq, roots);
1582 if (!trans)
1583 up_read(&fs_info->commit_root_sem);
1584 return ret;
1585}
1586
1587/**
1588 * btrfs_check_shared - tell us whether an extent is shared
1589 *

--- 282 unchanged lines hidden (view full) ---

1872
1873 return -EIO;
1874}
1875
1876/*
1877 * helper function to iterate extent inline refs. ptr must point to a 0 value
1878 * for the first call and may be modified. it is used to track state.
1879 * if more refs exist, 0 is returned and the next call to
1575 if (!trans)
1576 up_read(&fs_info->commit_root_sem);
1577 return ret;
1578}
1579
1580/**
1581 * btrfs_check_shared - tell us whether an extent is shared
1582 *

--- 282 unchanged lines hidden (view full) ---

1865
1866 return -EIO;
1867}
1868
1869/*
1870 * helper function to iterate extent inline refs. ptr must point to a 0 value
1871 * for the first call and may be modified. it is used to track state.
1872 * if more refs exist, 0 is returned and the next call to
1880 * __get_extent_inline_ref must pass the modified ptr parameter to get the
1873 * get_extent_inline_ref must pass the modified ptr parameter to get the
1881 * next ref. after the last ref was processed, 1 is returned.
1882 * returns <0 on error
1883 */
1874 * next ref. after the last ref was processed, 1 is returned.
1875 * returns <0 on error
1876 */
1884static int __get_extent_inline_ref(unsigned long *ptr,
1885 const struct extent_buffer *eb,
1886 const struct btrfs_key *key,
1887 const struct btrfs_extent_item *ei,
1888 u32 item_size,
1889 struct btrfs_extent_inline_ref **out_eiref,
1890 int *out_type)
1877static int get_extent_inline_ref(unsigned long *ptr,
1878 const struct extent_buffer *eb,
1879 const struct btrfs_key *key,
1880 const struct btrfs_extent_item *ei,
1881 u32 item_size,
1882 struct btrfs_extent_inline_ref **out_eiref,
1883 int *out_type)
1891{
1892 unsigned long end;
1893 u64 flags;
1894 struct btrfs_tree_block_info *info;
1895
1896 if (!*ptr) {
1897 /* first call */
1898 flags = btrfs_extent_flags(eb, ei);

--- 26 unchanged lines hidden (view full) ---

1925 return 1; /* last */
1926
1927 return 0;
1928}
1929
1930/*
1931 * reads the tree block backref for an extent. tree level and root are returned
1932 * through out_level and out_root. ptr must point to a 0 value for the first
1884{
1885 unsigned long end;
1886 u64 flags;
1887 struct btrfs_tree_block_info *info;
1888
1889 if (!*ptr) {
1890 /* first call */
1891 flags = btrfs_extent_flags(eb, ei);

--- 26 unchanged lines hidden (view full) ---

1918 return 1; /* last */
1919
1920 return 0;
1921}
1922
1923/*
1924 * reads the tree block backref for an extent. tree level and root are returned
1925 * through out_level and out_root. ptr must point to a 0 value for the first
1933 * call and may be modified (see __get_extent_inline_ref comment).
1926 * call and may be modified (see get_extent_inline_ref comment).
1934 * returns 0 if data was provided, 1 if there was no more data to provide or
1935 * <0 on error.
1936 */
1937int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1938 struct btrfs_key *key, struct btrfs_extent_item *ei,
1939 u32 item_size, u64 *out_root, u8 *out_level)
1940{
1941 int ret;
1942 int type;
1943 struct btrfs_extent_inline_ref *eiref;
1944
1945 if (*ptr == (unsigned long)-1)
1946 return 1;
1947
1948 while (1) {
1927 * returns 0 if data was provided, 1 if there was no more data to provide or
1928 * <0 on error.
1929 */
1930int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1931 struct btrfs_key *key, struct btrfs_extent_item *ei,
1932 u32 item_size, u64 *out_root, u8 *out_level)
1933{
1934 int ret;
1935 int type;
1936 struct btrfs_extent_inline_ref *eiref;
1937
1938 if (*ptr == (unsigned long)-1)
1939 return 1;
1940
1941 while (1) {
1949 ret = __get_extent_inline_ref(ptr, eb, key, ei, item_size,
1942 ret = get_extent_inline_ref(ptr, eb, key, ei, item_size,
1950 &eiref, &type);
1951 if (ret < 0)
1952 return ret;
1953
1954 if (type == BTRFS_TREE_BLOCK_REF_KEY ||
1955 type == BTRFS_SHARED_BLOCK_REF_KEY)
1956 break;
1957

--- 80 unchanged lines hidden (view full) ---

2038 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
2039 tree_mod_seq_elem.seq, &refs,
2040 &extent_item_pos);
2041 if (ret)
2042 goto out;
2043
2044 ULIST_ITER_INIT(&ref_uiter);
2045 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
1943 &eiref, &type);
1944 if (ret < 0)
1945 return ret;
1946
1947 if (type == BTRFS_TREE_BLOCK_REF_KEY ||
1948 type == BTRFS_SHARED_BLOCK_REF_KEY)
1949 break;
1950

--- 80 unchanged lines hidden (view full) ---

2031 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
2032 tree_mod_seq_elem.seq, &refs,
2033 &extent_item_pos);
2034 if (ret)
2035 goto out;
2036
2037 ULIST_ITER_INIT(&ref_uiter);
2038 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
2046 ret = __btrfs_find_all_roots(trans, fs_info, ref_node->val,
2047 tree_mod_seq_elem.seq, &roots);
2039 ret = btrfs_find_all_roots_safe(trans, fs_info, ref_node->val,
2040 tree_mod_seq_elem.seq, &roots);
2048 if (ret)
2049 break;
2050 ULIST_ITER_INIT(&root_uiter);
2051 while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
2052 btrfs_debug(fs_info,
2053 "root %llu references leaf %llu, data list %#llx",
2054 root_node->val, ref_node->val,
2055 ref_node->aux);

--- 315 unchanged lines hidden ---
2041 if (ret)
2042 break;
2043 ULIST_ITER_INIT(&root_uiter);
2044 while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
2045 btrfs_debug(fs_info,
2046 "root %llu references leaf %llu, data list %#llx",
2047 root_node->val, ref_node->val,
2048 ref_node->aux);

--- 315 unchanged lines hidden ---