]> git.hungrycats.org Git - linux/commitdiff
Btrfs: update free_chunk_space during allocting a new chunk
authorMiao Xie <miaox@cn.fujitsu.com>
Wed, 3 Sep 2014 13:35:37 +0000 (21:35 +0800)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Wed, 3 Dec 2014 15:16:49 +0000 (10:16 -0500)
We should update free_chunk_space in time when we allocate a new chunk,
not when we deal with the pending device update and block group insertion,
because we need the real free_chunk_space data to calculate the reserved
space, if we don't update it in time, we would consider the disk space which
has be allocated as free space, and would use it to do overcommit reservation.
Fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit 1c1161870c8bcb0d966ebbf1aec05a87a79a4175)

fs/btrfs/volumes.c

index 73295f69bdfac6835fdb4282fc40d38688be7abf..dd29da2ce0f96af2104980e617be9f51663779aa 100644 (file)
@@ -4429,6 +4429,11 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
        for (i = 0; i < map->num_stripes; i++)
                map->stripes[i].dev->bytes_used += stripe_size;
 
+       spin_lock(&extent_root->fs_info->free_chunk_lock);
+       extent_root->fs_info->free_chunk_space -= (stripe_size *
+                                                  map->num_stripes);
+       spin_unlock(&extent_root->fs_info->free_chunk_lock);
+
        free_extent_map(em);
        check_raid56_incompat_flag(extent_root->fs_info, type);
 
@@ -4512,11 +4517,6 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
                        goto out;
        }
 
-       spin_lock(&extent_root->fs_info->free_chunk_lock);
-       extent_root->fs_info->free_chunk_space -= (stripe_size *
-                                                  map->num_stripes);
-       spin_unlock(&extent_root->fs_info->free_chunk_lock);
-
        stripe = &chunk->stripe;
        for (i = 0; i < map->num_stripes; i++) {
                device = map->stripes[i].dev;