summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorJosef Bacik2015-03-02 22:37:31 +0100
committerJosef Bacik2015-03-17 15:56:55 +0100
commitdcdf7f6ddba006f3482ebee73dfa6b75aec5f07b (patch)
treea91a5105b64f8d0c6ea5f653ea0000b295050b2a /fs/btrfs/extent-tree.c
parentBtrfs: fix ASSERT(list_empty(&cur_trans->dirty_bgs_list) (diff)
downloadkernel-qcow2-linux-dcdf7f6ddba006f3482ebee73dfa6b75aec5f07b.tar.gz
kernel-qcow2-linux-dcdf7f6ddba006f3482ebee73dfa6b75aec5f07b.tar.xz
kernel-qcow2-linux-dcdf7f6ddba006f3482ebee73dfa6b75aec5f07b.zip
Btrfs: prepare block group cache before writing
Writing the block group cache will modify the extent tree quite a bit because it truncates the old space cache and pre-allocates new stuff. To try and cut down on the churn lets do the setup dance first, then later on hopefully we can avoid looping with newly dirtied roots. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 96c613bfe157..3ac3fefb1625 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3325,6 +3325,32 @@ out:
return ret;
}
+int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root)
+{
+ struct btrfs_block_group_cache *cache, *tmp;
+ struct btrfs_transaction *cur_trans = trans->transaction;
+ struct btrfs_path *path;
+
+ if (list_empty(&cur_trans->dirty_bgs) ||
+ !btrfs_test_opt(root, SPACE_CACHE))
+ return 0;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ /* Could add new block groups, use _safe just in case */
+ list_for_each_entry_safe(cache, tmp, &cur_trans->dirty_bgs,
+ dirty_list) {
+ if (cache->disk_cache_state == BTRFS_DC_CLEAR)
+ cache_save_setup(cache, trans, path);
+ }
+
+ btrfs_free_path(path);
+ return 0;
+}
+
int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
struct btrfs_root *root)
{