aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h1
-rw-r--r--fs/btrfs/extent-tree.c32
2 files changed, 19 insertions, 14 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0f2a9b584fb6..166896dd44c2 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -580,6 +580,7 @@ struct btrfs_block_group_cache {
580 struct btrfs_block_group_item item; 580 struct btrfs_block_group_item item;
581 spinlock_t lock; 581 spinlock_t lock;
582 struct mutex alloc_mutex; 582 struct mutex alloc_mutex;
583 struct mutex cache_mutex;
583 u64 pinned; 584 u64 pinned;
584 u64 reserved; 585 u64 reserved;
585 u64 flags; 586 u64 flags;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index b33e0bfb99e1..a970472eab17 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -170,8 +170,8 @@ static int add_new_free_space(struct btrfs_block_group_cache *block_group,
170 start = extent_end + 1; 170 start = extent_end + 1;
171 } else if (extent_start > start && extent_start < end) { 171 } else if (extent_start > start && extent_start < end) {
172 size = extent_start - start; 172 size = extent_start - start;
173 ret = btrfs_add_free_space_lock(block_group, start, 173 ret = btrfs_add_free_space(block_group, start,
174 size); 174 size);
175 BUG_ON(ret); 175 BUG_ON(ret);
176 start = extent_end + 1; 176 start = extent_end + 1;
177 } else { 177 } else {
@@ -181,7 +181,7 @@ static int add_new_free_space(struct btrfs_block_group_cache *block_group,
181 181
182 if (start < end) { 182 if (start < end) {
183 size = end - start; 183 size = end - start;
184 ret = btrfs_add_free_space_lock(block_group, start, size); 184 ret = btrfs_add_free_space(block_group, start, size);
185 BUG_ON(ret); 185 BUG_ON(ret);
186 } 186 }
187 mutex_unlock(&info->pinned_mutex); 187 mutex_unlock(&info->pinned_mutex);
@@ -2842,17 +2842,19 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
2842 if (!block_group) 2842 if (!block_group)
2843 goto new_group_no_lock; 2843 goto new_group_no_lock;
2844 2844
2845 if (unlikely(!block_group->cached)) {
2846 mutex_lock(&block_group->cache_mutex);
2847 ret = cache_block_group(root, block_group);
2848 mutex_unlock(&block_group->cache_mutex);
2849 if (ret)
2850 break;
2851 }
2852
2845 mutex_lock(&block_group->alloc_mutex); 2853 mutex_lock(&block_group->alloc_mutex);
2846 if (unlikely(!block_group_bits(block_group, data))) 2854 if (unlikely(!block_group_bits(block_group, data)))
2847 goto new_group; 2855 goto new_group;
2848 2856
2849 ret = cache_block_group(root, block_group); 2857 if (unlikely(block_group->ro))
2850 if (ret) {
2851 mutex_unlock(&block_group->alloc_mutex);
2852 break;
2853 }
2854
2855 if (block_group->ro)
2856 goto new_group; 2858 goto new_group;
2857 2859
2858 free_space = btrfs_find_free_space(block_group, search_start, 2860 free_space = btrfs_find_free_space(block_group, search_start,
@@ -3273,12 +3275,12 @@ int btrfs_alloc_logged_extent(struct btrfs_trans_handle *trans,
3273 struct btrfs_block_group_cache *block_group; 3275 struct btrfs_block_group_cache *block_group;
3274 3276
3275 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid); 3277 block_group = btrfs_lookup_block_group(root->fs_info, ins->objectid);
3276 mutex_lock(&block_group->alloc_mutex); 3278 mutex_lock(&block_group->cache_mutex);
3277 cache_block_group(root, block_group); 3279 cache_block_group(root, block_group);
3280 mutex_unlock(&block_group->cache_mutex);
3278 3281
3279 ret = btrfs_remove_free_space_lock(block_group, ins->objectid, 3282 ret = btrfs_remove_free_space(block_group, ins->objectid,
3280 ins->offset); 3283 ins->offset);
3281 mutex_unlock(&block_group->alloc_mutex);
3282 BUG_ON(ret); 3284 BUG_ON(ret);
3283 ret = __btrfs_alloc_reserved_extent(trans, root, parent, root_objectid, 3285 ret = __btrfs_alloc_reserved_extent(trans, root, parent, root_objectid,
3284 ref_generation, owner, ins); 3286 ref_generation, owner, ins);
@@ -5801,6 +5803,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
5801 5803
5802 spin_lock_init(&cache->lock); 5804 spin_lock_init(&cache->lock);
5803 mutex_init(&cache->alloc_mutex); 5805 mutex_init(&cache->alloc_mutex);
5806 mutex_init(&cache->cache_mutex);
5804 INIT_LIST_HEAD(&cache->list); 5807 INIT_LIST_HEAD(&cache->list);
5805 read_extent_buffer(leaf, &cache->item, 5808 read_extent_buffer(leaf, &cache->item,
5806 btrfs_item_ptr_offset(leaf, path->slots[0]), 5809 btrfs_item_ptr_offset(leaf, path->slots[0]),
@@ -5854,6 +5857,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
5854 cache->key.offset = size; 5857 cache->key.offset = size;
5855 spin_lock_init(&cache->lock); 5858 spin_lock_init(&cache->lock);
5856 mutex_init(&cache->alloc_mutex); 5859 mutex_init(&cache->alloc_mutex);
5860 mutex_init(&cache->cache_mutex);
5857 INIT_LIST_HEAD(&cache->list); 5861 INIT_LIST_HEAD(&cache->list);
5858 btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY); 5862 btrfs_set_key_type(&cache->key, BTRFS_BLOCK_GROUP_ITEM_KEY);
5859 5863