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.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index be2aef1cb7ae..ccd49322f793 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -934,7 +934,6 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
934 if (!root->ref_cows) 934 if (!root->ref_cows)
935 return 0; 935 return 0;
936 936
937 mutex_lock(&root->fs_info->alloc_mutex);
938 level = btrfs_header_level(buf); 937 level = btrfs_header_level(buf);
939 nritems = btrfs_header_nritems(buf); 938 nritems = btrfs_header_nritems(buf);
940 for (i = 0; i < nritems; i++) { 939 for (i = 0; i < nritems; i++) {
@@ -951,29 +950,36 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
951 disk_bytenr = btrfs_file_extent_disk_bytenr(buf, fi); 950 disk_bytenr = btrfs_file_extent_disk_bytenr(buf, fi);
952 if (disk_bytenr == 0) 951 if (disk_bytenr == 0)
953 continue; 952 continue;
953
954 mutex_lock(&root->fs_info->alloc_mutex);
954 ret = __btrfs_inc_extent_ref(trans, root, disk_bytenr, 955 ret = __btrfs_inc_extent_ref(trans, root, disk_bytenr,
955 btrfs_file_extent_disk_num_bytes(buf, fi), 956 btrfs_file_extent_disk_num_bytes(buf, fi),
956 root->root_key.objectid, trans->transid, 957 root->root_key.objectid, trans->transid,
957 key.objectid, key.offset); 958 key.objectid, key.offset);
959 mutex_unlock(&root->fs_info->alloc_mutex);
958 if (ret) { 960 if (ret) {
959 faili = i; 961 faili = i;
962 WARN_ON(1);
960 goto fail; 963 goto fail;
961 } 964 }
962 } else { 965 } else {
963 bytenr = btrfs_node_blockptr(buf, i); 966 bytenr = btrfs_node_blockptr(buf, i);
964 btrfs_node_key_to_cpu(buf, &key, i); 967 btrfs_node_key_to_cpu(buf, &key, i);
968
969 mutex_lock(&root->fs_info->alloc_mutex);
965 ret = __btrfs_inc_extent_ref(trans, root, bytenr, 970 ret = __btrfs_inc_extent_ref(trans, root, bytenr,
966 btrfs_level_size(root, level - 1), 971 btrfs_level_size(root, level - 1),
967 root->root_key.objectid, 972 root->root_key.objectid,
968 trans->transid, 973 trans->transid,
969 level - 1, key.objectid); 974 level - 1, key.objectid);
975 mutex_unlock(&root->fs_info->alloc_mutex);
970 if (ret) { 976 if (ret) {
971 faili = i; 977 faili = i;
978 WARN_ON(1);
972 goto fail; 979 goto fail;
973 } 980 }
974 } 981 }
975 } 982 }
976 mutex_unlock(&root->fs_info->alloc_mutex);
977 return 0; 983 return 0;
978fail: 984fail:
979 WARN_ON(1); 985 WARN_ON(1);
@@ -1004,7 +1010,6 @@ fail:
1004 } 1010 }
1005 } 1011 }
1006#endif 1012#endif
1007 mutex_unlock(&root->fs_info->alloc_mutex);
1008 return ret; 1013 return ret;
1009} 1014}
1010 1015
@@ -2180,6 +2185,8 @@ static int noinline drop_leaf_ref(struct btrfs_trans_handle *trans,
2180 leaf_owner = btrfs_header_owner(leaf); 2185 leaf_owner = btrfs_header_owner(leaf);
2181 leaf_generation = btrfs_header_generation(leaf); 2186 leaf_generation = btrfs_header_generation(leaf);
2182 2187
2188 mutex_unlock(&root->fs_info->alloc_mutex);
2189
2183 for (i = 0; i < nritems; i++) { 2190 for (i = 0; i < nritems; i++) {
2184 u64 disk_bytenr; 2191 u64 disk_bytenr;
2185 2192
@@ -2197,12 +2204,17 @@ static int noinline drop_leaf_ref(struct btrfs_trans_handle *trans,
2197 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); 2204 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
2198 if (disk_bytenr == 0) 2205 if (disk_bytenr == 0)
2199 continue; 2206 continue;
2207
2208 mutex_lock(&root->fs_info->alloc_mutex);
2200 ret = __btrfs_free_extent(trans, root, disk_bytenr, 2209 ret = __btrfs_free_extent(trans, root, disk_bytenr,
2201 btrfs_file_extent_disk_num_bytes(leaf, fi), 2210 btrfs_file_extent_disk_num_bytes(leaf, fi),
2202 leaf_owner, leaf_generation, 2211 leaf_owner, leaf_generation,
2203 key.objectid, key.offset, 0); 2212 key.objectid, key.offset, 0);
2213 mutex_unlock(&root->fs_info->alloc_mutex);
2204 BUG_ON(ret); 2214 BUG_ON(ret);
2205 } 2215 }
2216
2217 mutex_lock(&root->fs_info->alloc_mutex);
2206 return 0; 2218 return 0;
2207} 2219}
2208 2220