@@ -354,9 +354,8 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
{
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
struct btrfs_space_info *sinfo = block_rsv->space_info;
- struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
- struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0);
- u64 num_bytes;
+ struct btrfs_root *root, *tmp;
+ u64 num_bytes = btrfs_root_used(&fs_info->tree_root->root_item);
unsigned min_items;
/*
@@ -364,9 +363,14 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
* checksum tree and the root tree. If the fs is empty we want to set
* it to a minimal amount for safety.
*/
- num_bytes = btrfs_root_used(&extent_root->root_item) +
- btrfs_root_used(&csum_root->root_item) +
- btrfs_root_used(&fs_info->tree_root->root_item);
+ read_lock(&fs_info->global_root_lock);
+ rbtree_postorder_for_each_entry_safe(root, tmp, &fs_info->global_root_tree,
+ rb_node) {
+ if (root->root_key.objectid == BTRFS_EXTENT_TREE_OBJECTID ||
+ root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID)
+ num_bytes += btrfs_root_used(&root->root_item);
+ }
+ read_unlock(&fs_info->global_root_lock);
/*
* We at a minimum are going to modify the csum root, the tree root, and
With multiple csum and extent roots it makes it tricky to figure out the total used across all of the different global roots. Instead just use the total metadata usage as a guide for the global rsv size. This will be adjusted up for the truncate minimum size, and clamped down to 512mb if it's too much. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/block-rsv.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)