summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2017-06-28 23:56:57 -0400
committerDavid Sterba <dsterba@suse.com>2017-08-16 08:19:53 -0400
commite0c476b128e37daa37d630dd68da5681e9c16bab (patch)
tree80d0cbbd2c8ca67624f2f9ac9bf8c597d882075a /fs
parent4dae077a83dd8944ed351b09a0651c1283f46185 (diff)
btrfs: backref, cleanup __ namespace abuse
We typically use __ to indicate a helper routine that shouldn't be called directly without understanding the proper context required to do so. We use static functions to indicate that a function is private to a particular C file. The backref code uses static function and __ prefixes on nearly everything, which makes the code difficult to read and establishes a pattern for future code that shouldn't be followed. This patch drops all the unnecessary prefixes. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/backref.c225
1 files changed, 109 insertions, 116 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 4a7a4b032c2f..3725277f6e08 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -387,7 +387,7 @@ static int find_extent_in_eb(const struct extent_buffer *eb,
387/* 387/*
388 * this structure records all encountered refs on the way up to the root 388 * this structure records all encountered refs on the way up to the root
389 */ 389 */
390struct __prelim_ref { 390struct prelim_ref {
391 struct list_head list; 391 struct list_head list;
392 u64 root_id; 392 u64 root_id;
393 struct btrfs_key key_for_search; 393 struct btrfs_key key_for_search;
@@ -403,7 +403,7 @@ static struct kmem_cache *btrfs_prelim_ref_cache;
403int __init btrfs_prelim_ref_init(void) 403int __init btrfs_prelim_ref_init(void)
404{ 404{
405 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref", 405 btrfs_prelim_ref_cache = kmem_cache_create("btrfs_prelim_ref",
406 sizeof(struct __prelim_ref), 406 sizeof(struct prelim_ref),
407 0, 407 0,
408 SLAB_MEM_SPREAD, 408 SLAB_MEM_SPREAD,
409 NULL); 409 NULL);
@@ -449,19 +449,17 @@ void btrfs_prelim_ref_exit(void)
449 * 449 *
450 * - column 1, 3: we've the parent -> done 450 * - column 1, 3: we've the parent -> done
451 * - column 2: we take the first key from the block to find the parent 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 453 * - column 4: we use the key to find the parent
454 * 454 *
455 * additional information that's available but not required to find the parent 455 * additional information that's available but not required to find the parent
456 * block might help in merging entries to gain some speed. 456 * block might help in merging entries to gain some speed.
457 */ 457 */
458 458static int add_prelim_ref(struct list_head *head, u64 root_id,
459static int __add_prelim_ref(struct list_head *head, u64 root_id, 459 const struct btrfs_key *key, int level, u64 parent,
460 const struct btrfs_key *key, int level, 460 u64 wanted_disk_byte, int count, gfp_t gfp_mask)
461 u64 parent, u64 wanted_disk_byte, int count,
462 gfp_t gfp_mask)
463{ 461{
464 struct __prelim_ref *ref; 462 struct prelim_ref *ref;
465 463
466 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID) 464 if (root_id == BTRFS_DATA_RELOC_TREE_OBJECTID)
467 return 0; 465 return 0;
@@ -510,7 +508,7 @@ static int __add_prelim_ref(struct list_head *head, u64 root_id,
510} 508}
511 509
512static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path, 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, 512 int level, u64 time_seq, const u64 *extent_item_pos,
515 u64 total_refs) 513 u64 total_refs)
516{ 514{
@@ -600,11 +598,10 @@ next:
600 * resolve an indirect backref in the form (root_id, key, level) 598 * resolve an indirect backref in the form (root_id, key, level)
601 * to a logical address 599 * to a logical address
602 */ 600 */
603static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info, 601static int resolve_indirect_ref(struct btrfs_fs_info *fs_info,
604 struct btrfs_path *path, u64 time_seq, 602 struct btrfs_path *path, u64 time_seq,
605 struct __prelim_ref *ref, 603 struct prelim_ref *ref, struct ulist *parents,
606 struct ulist *parents, 604 const u64 *extent_item_pos, u64 total_refs)
607 const u64 *extent_item_pos, u64 total_refs)
608{ 605{
609 struct btrfs_root *root; 606 struct btrfs_root *root;
610 struct btrfs_key root_key; 607 struct btrfs_key root_key;
@@ -693,17 +690,17 @@ unode_aux_to_inode_list(struct ulist_node *node)
693/* 690/*
694 * resolve all indirect backrefs from the list 691 * resolve all indirect backrefs from the list
695 */ 692 */
696static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info, 693static int resolve_indirect_refs(struct btrfs_fs_info *fs_info,
697 struct btrfs_path *path, u64 time_seq, 694 struct btrfs_path *path, u64 time_seq,
698 struct list_head *head, 695 struct list_head *head,
699 const u64 *extent_item_pos, u64 total_refs, 696 const u64 *extent_item_pos, u64 total_refs,
700 u64 root_objectid) 697 u64 root_objectid)
701{ 698{
702 int err; 699 int err;
703 int ret = 0; 700 int ret = 0;
704 struct __prelim_ref *ref; 701 struct prelim_ref *ref;
705 struct __prelim_ref *ref_safe; 702 struct prelim_ref *ref_safe;
706 struct __prelim_ref *new_ref; 703 struct prelim_ref *new_ref;
707 struct ulist *parents; 704 struct ulist *parents;
708 struct ulist_node *node; 705 struct ulist_node *node;
709 struct ulist_iterator uiter; 706 struct ulist_iterator uiter;
@@ -726,9 +723,9 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
726 ret = BACKREF_FOUND_SHARED; 723 ret = BACKREF_FOUND_SHARED;
727 goto out; 724 goto out;
728 } 725 }
729 err = __resolve_indirect_ref(fs_info, path, time_seq, ref, 726 err = resolve_indirect_ref(fs_info, path, time_seq, ref,
730 parents, extent_item_pos, 727 parents, extent_item_pos,
731 total_refs); 728 total_refs);
732 /* 729 /*
733 * we can only tolerate ENOENT,otherwise,we should catch error 730 * we can only tolerate ENOENT,otherwise,we should catch error
734 * and return directly. 731 * and return directly.
@@ -766,8 +763,8 @@ out:
766 return ret; 763 return ret;
767} 764}
768 765
769static inline int ref_for_same_block(struct __prelim_ref *ref1, 766static inline int ref_for_same_block(struct prelim_ref *ref1,
770 struct __prelim_ref *ref2) 767 struct prelim_ref *ref2)
771{ 768{
772 if (ref1->level != ref2->level) 769 if (ref1->level != ref2->level)
773 return 0; 770 return 0;
@@ -788,10 +785,10 @@ static inline int ref_for_same_block(struct __prelim_ref *ref1,
788/* 785/*
789 * read tree blocks and add keys where required. 786 * read tree blocks and add keys where required.
790 */ 787 */
791static int __add_missing_keys(struct btrfs_fs_info *fs_info, 788static int add_missing_keys(struct btrfs_fs_info *fs_info,
792 struct list_head *head) 789 struct list_head *head)
793{ 790{
794 struct __prelim_ref *ref; 791 struct prelim_ref *ref;
795 struct extent_buffer *eb; 792 struct extent_buffer *eb;
796 793
797 list_for_each_entry(ref, head, list) { 794 list_for_each_entry(ref, head, list) {
@@ -821,20 +818,20 @@ static int __add_missing_keys(struct btrfs_fs_info *fs_info,
821/* 818/*
822 * merge backrefs and adjust counts accordingly 819 * merge backrefs and adjust counts accordingly
823 * 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 822 * 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 823 * range for the blocks we looked into to merge even more (-> replace
827 * unresolved refs by those having a parent). 824 * unresolved refs by those having a parent).
828 */ 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 829
833 list_for_each_entry(pos1, head, list) { 830 list_for_each_entry(pos1, head, list) {
834 struct __prelim_ref *pos2 = pos1, *tmp; 831 struct prelim_ref *pos2 = pos1, *tmp;
835 832
836 list_for_each_entry_safe_continue(pos2, tmp, head, list) { 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; 835 struct extent_inode_elem *eie;
839 836
840 if (!ref_for_same_block(ref1, ref2)) 837 if (!ref_for_same_block(ref1, ref2))
@@ -868,9 +865,9 @@ static void __merge_refs(struct list_head *head, enum merge_mode mode)
868 * add all currently queued delayed refs from this head whose seq nr is 865 * add all currently queued delayed refs from this head whose seq nr is
869 * smaller or equal that seq to the list 866 * smaller or equal that seq to the list
870 */ 867 */
871static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq, 868static int add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
872 struct list_head *prefs, u64 *total_refs, 869 struct list_head *prefs, u64 *total_refs,
873 u64 inum) 870 u64 inum)
874{ 871{
875 struct btrfs_delayed_ref_node *node; 872 struct btrfs_delayed_ref_node *node;
876 struct btrfs_delayed_extent_op *extent_op = head->extent_op; 873 struct btrfs_delayed_extent_op *extent_op = head->extent_op;
@@ -907,19 +904,18 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
907 struct btrfs_delayed_tree_ref *ref; 904 struct btrfs_delayed_tree_ref *ref;
908 905
909 ref = btrfs_delayed_node_to_tree_ref(node); 906 ref = btrfs_delayed_node_to_tree_ref(node);
910 ret = __add_prelim_ref(prefs, ref->root, &op_key, 907 ret = add_prelim_ref(prefs, ref->root, &op_key,
911 ref->level + 1, 0, node->bytenr, 908 ref->level + 1, 0, node->bytenr,
912 node->ref_mod * sgn, GFP_ATOMIC); 909 node->ref_mod * sgn, GFP_ATOMIC);
913 break; 910 break;
914 } 911 }
915 case BTRFS_SHARED_BLOCK_REF_KEY: { 912 case BTRFS_SHARED_BLOCK_REF_KEY: {
916 struct btrfs_delayed_tree_ref *ref; 913 struct btrfs_delayed_tree_ref *ref;
917 914
918 ref = btrfs_delayed_node_to_tree_ref(node); 915 ref = btrfs_delayed_node_to_tree_ref(node);
919 ret = __add_prelim_ref(prefs, 0, NULL, 916 ret = add_prelim_ref(prefs, 0, NULL, ref->level + 1,
920 ref->level + 1, ref->parent, 917 ref->parent, node->bytenr,
921 node->bytenr, 918 node->ref_mod * sgn, GFP_ATOMIC);
922 node->ref_mod * sgn, GFP_ATOMIC);
923 break; 919 break;
924 } 920 }
925 case BTRFS_EXTENT_DATA_REF_KEY: { 921 case BTRFS_EXTENT_DATA_REF_KEY: {
@@ -939,18 +935,18 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
939 break; 935 break;
940 } 936 }
941 937
942 ret = __add_prelim_ref(prefs, ref->root, &key, 0, 0, 938 ret = add_prelim_ref(prefs, ref->root, &key, 0, 0,
943 node->bytenr, 939 node->bytenr, node->ref_mod * sgn,
944 node->ref_mod * sgn, GFP_ATOMIC); 940 GFP_ATOMIC);
945 break; 941 break;
946 } 942 }
947 case BTRFS_SHARED_DATA_REF_KEY: { 943 case BTRFS_SHARED_DATA_REF_KEY: {
948 struct btrfs_delayed_data_ref *ref; 944 struct btrfs_delayed_data_ref *ref;
949 945
950 ref = btrfs_delayed_node_to_data_ref(node); 946 ref = btrfs_delayed_node_to_data_ref(node);
951 ret = __add_prelim_ref(prefs, 0, NULL, 0, 947 ret = add_prelim_ref(prefs, 0, NULL, 0, ref->parent,
952 ref->parent, node->bytenr, 948 node->bytenr, node->ref_mod * sgn,
953 node->ref_mod * sgn, GFP_ATOMIC); 949 GFP_ATOMIC);
954 break; 950 break;
955 } 951 }
956 default: 952 default:
@@ -966,10 +962,10 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
966/* 962/*
967 * add all inline backrefs for bytenr to the list 963 * add all inline backrefs for bytenr to the list
968 */ 964 */
969static int __add_inline_refs(struct btrfs_path *path, u64 bytenr, 965static int add_inline_refs(struct btrfs_path *path, u64 bytenr,
970 int *info_level, struct list_head *prefs, 966 int *info_level, struct list_head *prefs,
971 struct ref_root *ref_tree, 967 struct ref_root *ref_tree,
972 u64 *total_refs, u64 inum) 968 u64 *total_refs, u64 inum)
973{ 969{
974 int ret = 0; 970 int ret = 0;
975 int slot; 971 int slot;
@@ -1024,9 +1020,8 @@ static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
1024 1020
1025 switch (type) { 1021 switch (type) {
1026 case BTRFS_SHARED_BLOCK_REF_KEY: 1022 case BTRFS_SHARED_BLOCK_REF_KEY:
1027 ret = __add_prelim_ref(prefs, 0, NULL, 1023 ret = add_prelim_ref(prefs, 0, NULL, *info_level + 1,
1028 *info_level + 1, offset, 1024 offset, bytenr, 1, GFP_NOFS);
1029 bytenr, 1, GFP_NOFS);
1030 break; 1025 break;
1031 case BTRFS_SHARED_DATA_REF_KEY: { 1026 case BTRFS_SHARED_DATA_REF_KEY: {
1032 struct btrfs_shared_data_ref *sdref; 1027 struct btrfs_shared_data_ref *sdref;
@@ -1034,8 +1029,8 @@ static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
1034 1029
1035 sdref = (struct btrfs_shared_data_ref *)(iref + 1); 1030 sdref = (struct btrfs_shared_data_ref *)(iref + 1);
1036 count = btrfs_shared_data_ref_count(leaf, sdref); 1031 count = btrfs_shared_data_ref_count(leaf, sdref);
1037 ret = __add_prelim_ref(prefs, 0, NULL, 0, offset, 1032 ret = add_prelim_ref(prefs, 0, NULL, 0, offset,
1038 bytenr, count, GFP_NOFS); 1033 bytenr, count, GFP_NOFS);
1039 if (ref_tree) { 1034 if (ref_tree) {
1040 if (!ret) 1035 if (!ret)
1041 ret = ref_tree_add(ref_tree, 0, 0, 0, 1036 ret = ref_tree_add(ref_tree, 0, 0, 0,
@@ -1046,9 +1041,9 @@ static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
1046 break; 1041 break;
1047 } 1042 }
1048 case BTRFS_TREE_BLOCK_REF_KEY: 1043 case BTRFS_TREE_BLOCK_REF_KEY:
1049 ret = __add_prelim_ref(prefs, offset, NULL, 1044 ret = add_prelim_ref(prefs, offset, NULL,
1050 *info_level + 1, 0, 1045 *info_level + 1, 0,
1051 bytenr, 1, GFP_NOFS); 1046 bytenr, 1, GFP_NOFS);
1052 break; 1047 break;
1053 case BTRFS_EXTENT_DATA_REF_KEY: { 1048 case BTRFS_EXTENT_DATA_REF_KEY: {
1054 struct btrfs_extent_data_ref *dref; 1049 struct btrfs_extent_data_ref *dref;
@@ -1068,8 +1063,8 @@ static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
1068 } 1063 }
1069 1064
1070 root = btrfs_extent_data_ref_root(leaf, dref); 1065 root = btrfs_extent_data_ref_root(leaf, dref);
1071 ret = __add_prelim_ref(prefs, root, &key, 0, 0, 1066 ret = add_prelim_ref(prefs, root, &key, 0, 0,
1072 bytenr, count, GFP_NOFS); 1067 bytenr, count, GFP_NOFS);
1073 if (ref_tree) { 1068 if (ref_tree) {
1074 if (!ret) 1069 if (!ret)
1075 ret = ref_tree_add(ref_tree, root, 1070 ret = ref_tree_add(ref_tree, root,
@@ -1095,10 +1090,10 @@ static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
1095/* 1090/*
1096 * add all non-inline backrefs for bytenr to the list 1091 * add all non-inline backrefs for bytenr to the list
1097 */ 1092 */
1098static int __add_keyed_refs(struct btrfs_fs_info *fs_info, 1093static int add_keyed_refs(struct btrfs_fs_info *fs_info,
1099 struct btrfs_path *path, u64 bytenr, 1094 struct btrfs_path *path, u64 bytenr,
1100 int info_level, struct list_head *prefs, 1095 int info_level, struct list_head *prefs,
1101 struct ref_root *ref_tree, u64 inum) 1096 struct ref_root *ref_tree, u64 inum)
1102{ 1097{
1103 struct btrfs_root *extent_root = fs_info->extent_root; 1098 struct btrfs_root *extent_root = fs_info->extent_root;
1104 int ret; 1099 int ret;
@@ -1128,9 +1123,8 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
1128 1123
1129 switch (key.type) { 1124 switch (key.type) {
1130 case BTRFS_SHARED_BLOCK_REF_KEY: 1125 case BTRFS_SHARED_BLOCK_REF_KEY:
1131 ret = __add_prelim_ref(prefs, 0, NULL, 1126 ret = add_prelim_ref(prefs, 0, NULL, info_level + 1,
1132 info_level + 1, key.offset, 1127 key.offset, bytenr, 1, GFP_NOFS);
1133 bytenr, 1, GFP_NOFS);
1134 break; 1128 break;
1135 case BTRFS_SHARED_DATA_REF_KEY: { 1129 case BTRFS_SHARED_DATA_REF_KEY: {
1136 struct btrfs_shared_data_ref *sdref; 1130 struct btrfs_shared_data_ref *sdref;
@@ -1139,8 +1133,8 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
1139 sdref = btrfs_item_ptr(leaf, slot, 1133 sdref = btrfs_item_ptr(leaf, slot,
1140 struct btrfs_shared_data_ref); 1134 struct btrfs_shared_data_ref);
1141 count = btrfs_shared_data_ref_count(leaf, sdref); 1135 count = btrfs_shared_data_ref_count(leaf, sdref);
1142 ret = __add_prelim_ref(prefs, 0, NULL, 0, key.offset, 1136 ret = add_prelim_ref(prefs, 0, NULL, 0, key.offset,
1143 bytenr, count, GFP_NOFS); 1137 bytenr, count, GFP_NOFS);
1144 if (ref_tree) { 1138 if (ref_tree) {
1145 if (!ret) 1139 if (!ret)
1146 ret = ref_tree_add(ref_tree, 0, 0, 0, 1140 ret = ref_tree_add(ref_tree, 0, 0, 0,
@@ -1151,9 +1145,9 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
1151 break; 1145 break;
1152 } 1146 }
1153 case BTRFS_TREE_BLOCK_REF_KEY: 1147 case BTRFS_TREE_BLOCK_REF_KEY:
1154 ret = __add_prelim_ref(prefs, key.offset, NULL, 1148 ret = add_prelim_ref(prefs, key.offset, NULL,
1155 info_level + 1, 0, 1149 info_level + 1, 0,
1156 bytenr, 1, GFP_NOFS); 1150 bytenr, 1, GFP_NOFS);
1157 break; 1151 break;
1158 case BTRFS_EXTENT_DATA_REF_KEY: { 1152 case BTRFS_EXTENT_DATA_REF_KEY: {
1159 struct btrfs_extent_data_ref *dref; 1153 struct btrfs_extent_data_ref *dref;
@@ -1174,8 +1168,8 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
1174 } 1168 }
1175 1169
1176 root = btrfs_extent_data_ref_root(leaf, dref); 1170 root = btrfs_extent_data_ref_root(leaf, dref);
1177 ret = __add_prelim_ref(prefs, root, &key, 0, 0, 1171 ret = add_prelim_ref(prefs, root, &key, 0, 0,
1178 bytenr, count, GFP_NOFS); 1172 bytenr, count, GFP_NOFS);
1179 if (ref_tree) { 1173 if (ref_tree) {
1180 if (!ret) 1174 if (!ret)
1181 ret = ref_tree_add(ref_tree, root, 1175 ret = ref_tree_add(ref_tree, root,
@@ -1230,7 +1224,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
1230 int ret; 1224 int ret;
1231 struct list_head prefs_delayed; 1225 struct list_head prefs_delayed;
1232 struct list_head prefs; 1226 struct list_head prefs;
1233 struct __prelim_ref *ref; 1227 struct prelim_ref *ref;
1234 struct extent_inode_elem *eie = NULL; 1228 struct extent_inode_elem *eie = NULL;
1235 struct ref_root *ref_tree = NULL; 1229 struct ref_root *ref_tree = NULL;
1236 u64 total_refs = 0; 1230 u64 total_refs = 0;
@@ -1311,9 +1305,9 @@ again:
1311 goto again; 1305 goto again;
1312 } 1306 }
1313 spin_unlock(&delayed_refs->lock); 1307 spin_unlock(&delayed_refs->lock);
1314 ret = __add_delayed_refs(head, time_seq, 1308 ret = add_delayed_refs(head, time_seq,
1315 &prefs_delayed, &total_refs, 1309 &prefs_delayed, &total_refs,
1316 inum); 1310 inum);
1317 mutex_unlock(&head->mutex); 1311 mutex_unlock(&head->mutex);
1318 if (ret) 1312 if (ret)
1319 goto out; 1313 goto out;
@@ -1363,15 +1357,13 @@ again:
1363 if (key.objectid == bytenr && 1357 if (key.objectid == bytenr &&
1364 (key.type == BTRFS_EXTENT_ITEM_KEY || 1358 (key.type == BTRFS_EXTENT_ITEM_KEY ||
1365 key.type == BTRFS_METADATA_ITEM_KEY)) { 1359 key.type == BTRFS_METADATA_ITEM_KEY)) {
1366 ret = __add_inline_refs(path, bytenr, 1360 ret = add_inline_refs(path, bytenr, &info_level,
1367 &info_level, &prefs, 1361 &prefs, ref_tree, &total_refs,
1368 ref_tree, &total_refs, 1362 inum);
1369 inum);
1370 if (ret) 1363 if (ret)
1371 goto out; 1364 goto out;
1372 ret = __add_keyed_refs(fs_info, path, bytenr, 1365 ret = add_keyed_refs(fs_info, path, bytenr, info_level,
1373 info_level, &prefs, 1366 &prefs, ref_tree, inum);
1374 ref_tree, inum);
1375 if (ret) 1367 if (ret)
1376 goto out; 1368 goto out;
1377 } 1369 }
@@ -1380,22 +1372,22 @@ again:
1380 1372
1381 list_splice_init(&prefs_delayed, &prefs); 1373 list_splice_init(&prefs_delayed, &prefs);
1382 1374
1383 ret = __add_missing_keys(fs_info, &prefs); 1375 ret = add_missing_keys(fs_info, &prefs);
1384 if (ret) 1376 if (ret)
1385 goto out; 1377 goto out;
1386 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, 1381 ret = resolve_indirect_refs(fs_info, path, time_seq, &prefs,
1390 extent_item_pos, total_refs, 1382 extent_item_pos, total_refs,
1391 root_objectid); 1383 root_objectid);
1392 if (ret) 1384 if (ret)
1393 goto out; 1385 goto out;
1394 1386
1395 __merge_refs(&prefs, MERGE_IDENTICAL_PARENTS); 1387 merge_refs(&prefs, MERGE_IDENTICAL_PARENTS);
1396 1388
1397 while (!list_empty(&prefs)) { 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); 1391 WARN_ON(ref->count < 0);
1400 if (roots && ref->count && ref->root_id && ref->parent == 0) { 1392 if (roots && ref->count && ref->root_id && ref->parent == 0) {
1401 if (root_objectid && ref->root_id != root_objectid) { 1393 if (root_objectid && ref->root_id != root_objectid) {
@@ -1457,12 +1449,12 @@ out:
1457 btrfs_free_path(path); 1449 btrfs_free_path(path);
1458 ref_root_free(ref_tree); 1450 ref_root_free(ref_tree);
1459 while (!list_empty(&prefs)) { 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); 1453 list_del(&ref->list);
1462 kmem_cache_free(btrfs_prelim_ref_cache, ref); 1454 kmem_cache_free(btrfs_prelim_ref_cache, ref);
1463 } 1455 }
1464 while (!list_empty(&prefs_delayed)) { 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); 1458 list);
1467 list_del(&ref->list); 1459 list_del(&ref->list);
1468 kmem_cache_free(btrfs_prelim_ref_cache, ref); 1460 kmem_cache_free(btrfs_prelim_ref_cache, ref);
@@ -1532,9 +1524,9 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
1532 * 1524 *
1533 * returns 0 on success, < 0 on error. 1525 * returns 0 on success, < 0 on error.
1534 */ 1526 */
1535static int __btrfs_find_all_roots(struct btrfs_trans_handle *trans, 1527static int btrfs_find_all_roots_safe(struct btrfs_trans_handle *trans,
1536 struct btrfs_fs_info *fs_info, u64 bytenr, 1528 struct btrfs_fs_info *fs_info, u64 bytenr,
1537 u64 time_seq, struct ulist **roots) 1529 u64 time_seq, struct ulist **roots)
1538{ 1530{
1539 struct ulist *tmp; 1531 struct ulist *tmp;
1540 struct ulist_node *node = NULL; 1532 struct ulist_node *node = NULL;
@@ -1578,7 +1570,8 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
1578 1570
1579 if (!trans) 1571 if (!trans)
1580 down_read(&fs_info->commit_root_sem); 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) 1575 if (!trans)
1583 up_read(&fs_info->commit_root_sem); 1576 up_read(&fs_info->commit_root_sem);
1584 return ret; 1577 return ret;
@@ -1877,17 +1870,17 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
1877 * helper function to iterate extent inline refs. ptr must point to a 0 value 1870 * 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. 1871 * 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 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. 1874 * next ref. after the last ref was processed, 1 is returned.
1882 * returns <0 on error 1875 * returns <0 on error
1883 */ 1876 */
1884static int __get_extent_inline_ref(unsigned long *ptr, 1877static int get_extent_inline_ref(unsigned long *ptr,
1885 const struct extent_buffer *eb, 1878 const struct extent_buffer *eb,
1886 const struct btrfs_key *key, 1879 const struct btrfs_key *key,
1887 const struct btrfs_extent_item *ei, 1880 const struct btrfs_extent_item *ei,
1888 u32 item_size, 1881 u32 item_size,
1889 struct btrfs_extent_inline_ref **out_eiref, 1882 struct btrfs_extent_inline_ref **out_eiref,
1890 int *out_type) 1883 int *out_type)
1891{ 1884{
1892 unsigned long end; 1885 unsigned long end;
1893 u64 flags; 1886 u64 flags;
@@ -1930,7 +1923,7 @@ static int __get_extent_inline_ref(unsigned long *ptr,
1930/* 1923/*
1931 * reads the tree block backref for an extent. tree level and root are returned 1924 * 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 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 1927 * returns 0 if data was provided, 1 if there was no more data to provide or
1935 * <0 on error. 1928 * <0 on error.
1936 */ 1929 */
@@ -1946,7 +1939,7 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1946 return 1; 1939 return 1;
1947 1940
1948 while (1) { 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); 1943 &eiref, &type);
1951 if (ret < 0) 1944 if (ret < 0)
1952 return ret; 1945 return ret;
@@ -2043,8 +2036,8 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
2043 2036
2044 ULIST_ITER_INIT(&ref_uiter); 2037 ULIST_ITER_INIT(&ref_uiter);
2045 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) { 2038 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
2046 ret = __btrfs_find_all_roots(trans, fs_info, ref_node->val, 2039 ret = btrfs_find_all_roots_safe(trans, fs_info, ref_node->val,
2047 tree_mod_seq_elem.seq, &roots); 2040 tree_mod_seq_elem.seq, &roots);
2048 if (ret) 2041 if (ret)
2049 break; 2042 break;
2050 ULIST_ITER_INIT(&root_uiter); 2043 ULIST_ITER_INIT(&root_uiter);