aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 3e2f969de42d..9ab099bc01a4 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1091,16 +1091,26 @@ out:
1091int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 1091int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1092 struct extent_buffer *buf, u32 nr_extents) 1092 struct extent_buffer *buf, u32 nr_extents)
1093{ 1093{
1094 u32 nritems;
1095 struct btrfs_key key; 1094 struct btrfs_key key;
1096 struct btrfs_file_extent_item *fi; 1095 struct btrfs_file_extent_item *fi;
1096 u64 root_gen;
1097 u32 nritems;
1097 int i; 1098 int i;
1098 int level; 1099 int level;
1099 int ret = 0; 1100 int ret = 0;
1101 int shared = 0;
1100 1102
1101 if (!root->ref_cows) 1103 if (!root->ref_cows)
1102 return 0; 1104 return 0;
1103 1105
1106 if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
1107 shared = 0;
1108 root_gen = root->root_key.offset;
1109 } else {
1110 shared = 1;
1111 root_gen = trans->transid - 1;
1112 }
1113
1104 level = btrfs_header_level(buf); 1114 level = btrfs_header_level(buf);
1105 nritems = btrfs_header_nritems(buf); 1115 nritems = btrfs_header_nritems(buf);
1106 1116
@@ -1114,7 +1124,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1114 goto out; 1124 goto out;
1115 } 1125 }
1116 1126
1117 ref->root_gen = root->root_key.offset; 1127 ref->root_gen = root_gen;
1118 ref->bytenr = buf->start; 1128 ref->bytenr = buf->start;
1119 ref->owner = btrfs_header_owner(buf); 1129 ref->owner = btrfs_header_owner(buf);
1120 ref->generation = btrfs_header_generation(buf); 1130 ref->generation = btrfs_header_generation(buf);
@@ -1143,8 +1153,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1143 info++; 1153 info++;
1144 } 1154 }
1145 1155
1146 BUG_ON(!root->ref_tree); 1156 ret = btrfs_add_leaf_ref(root, ref, shared);
1147 ret = btrfs_add_leaf_ref(root, ref);
1148 WARN_ON(ret); 1157 WARN_ON(ret);
1149 btrfs_free_leaf_ref(root, ref); 1158 btrfs_free_leaf_ref(root, ref);
1150 } 1159 }