]> git.hungrycats.org Git - linux/commitdiff
Btrfs: add bytes_readonly to the spaceinfo at once
authorJosef Bacik <jbacik@fb.com>
Mon, 21 Sep 2015 21:12:14 +0000 (17:12 -0400)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Wed, 30 Sep 2015 20:43:12 +0000 (16:43 -0400)
For some reason we're adding bytes_readonly to the space info after we update
the space info with the block group info.  This creates a tiny race where we
could over-reserve space because we haven't yet taken out the bytes_readonly
bit.  Since we already know this information at the time we call
update_space_info, just pass it along so it can be updated all at once.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
(cherry picked from commit 64bab231b9aa453e737b96a781aa344c4ce85092)

Conflicts:
fs/btrfs/extent-tree.c

fs/btrfs/extent-tree.c

index b25fff304ff7c38e75c0209424b246df28a348d9..936be80051d5e79697de81543cb5923025482635 100644 (file)
@@ -3673,6 +3673,7 @@ static const char *alloc_name(u64 flags)
 
 static int update_space_info(struct btrfs_fs_info *info, u64 flags,
                             u64 total_bytes, u64 bytes_used,
+                            u64 bytes_readonly,
                             struct btrfs_space_info **space_info)
 {
        struct btrfs_space_info *found;
@@ -3693,7 +3694,9 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
                found->disk_total += total_bytes * factor;
                found->bytes_used += bytes_used;
                found->disk_used += bytes_used * factor;
-               found->full = 0;
+               found->bytes_readonly += bytes_readonly;
+               if (total_bytes > 0)
+                       found->full = 0;
                spin_unlock(&found->lock);
                *space_info = found;
                return 0;
@@ -3719,7 +3722,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
        found->disk_used = bytes_used * factor;
        found->bytes_pinned = 0;
        found->bytes_reserved = 0;
-       found->bytes_readonly = 0;
+       found->bytes_readonly = bytes_readonly;
        found->bytes_may_use = 0;
        found->full = 0;
        found->force_alloc = CHUNK_ALLOC_NO_FORCE;
@@ -4149,7 +4152,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,
        space_info = __find_space_info(extent_root->fs_info, flags);
        if (!space_info) {
                ret = update_space_info(extent_root->fs_info, flags,
-                                       0, 0, &space_info);
+                                       0, 0, 0, &space_info);
                BUG_ON(ret); /* -ENOMEM */
        }
        BUG_ON(!space_info); /* Logic error */
@@ -9430,7 +9433,7 @@ int btrfs_read_block_groups(struct btrfs_root *root)
 
                ret = update_space_info(info, cache->flags, found_key.offset,
                                        btrfs_block_group_used(&cache->item),
-                                       &space_info);
+                                       cache->bytes_super, &space_info);
                if (ret) {
                        btrfs_remove_free_space_cache(cache);
                        spin_lock(&info->block_group_cache_lock);
@@ -9443,9 +9446,6 @@ int btrfs_read_block_groups(struct btrfs_root *root)
                }
 
                cache->space_info = space_info;
-               spin_lock(&cache->space_info->lock);
-               cache->space_info->bytes_readonly += cache->bytes_super;
-               spin_unlock(&cache->space_info->lock);
 
                __link_block_group(space_info, cache);
 
@@ -9532,7 +9532,6 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
        int ret;
        struct btrfs_root *extent_root;
        struct btrfs_block_group_cache *cache;
-
        extent_root = root->fs_info->extent_root;
 
        btrfs_set_log_full_commit(root->fs_info, trans);
@@ -9564,6 +9563,19 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
 
        free_excluded_extents(root, cache);
 
+       /*
+        * Call to ensure the corresponding space_info object is created and
+        * assigned to our block group, but don't update its counters just yet.
+        * We want our bg to be added to the rbtree with its ->space_info set.
+        */
+       ret = update_space_info(root->fs_info, cache->flags, 0, 0, 0,
+                               &cache->space_info);
+       if (ret) {
+               btrfs_remove_free_space_cache(cache);
+               btrfs_put_block_group(cache);
+               return ret;
+       }
+
        ret = btrfs_add_block_group_cache(root->fs_info, cache);
        if (ret) {
                btrfs_remove_free_space_cache(cache);
@@ -9572,7 +9584,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
        }
 
        ret = update_space_info(root->fs_info, cache->flags, size, bytes_used,
-                               &cache->space_info);
+                               cache->bytes_super, &cache->space_info);
        if (ret) {
                btrfs_remove_free_space_cache(cache);
                spin_lock(&root->fs_info->block_group_cache_lock);
@@ -9585,16 +9597,11 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
        }
        update_global_block_rsv(root->fs_info);
 
-       spin_lock(&cache->space_info->lock);
-       cache->space_info->bytes_readonly += cache->bytes_super;
-       spin_unlock(&cache->space_info->lock);
-
        __link_block_group(cache->space_info, cache);
 
        list_add_tail(&cache->bg_list, &trans->new_bgs);
 
        set_avail_alloc_bits(extent_root->fs_info, type);
-
        return 0;
 }
 
@@ -10051,21 +10058,21 @@ int btrfs_init_space_info(struct btrfs_fs_info *fs_info)
                mixed = 1;
 
        flags = BTRFS_BLOCK_GROUP_SYSTEM;
-       ret = update_space_info(fs_info, flags, 0, 0, &space_info);
+       ret = update_space_info(fs_info, flags, 0, 0, 0, &space_info);
        if (ret)
                goto out;
 
        if (mixed) {
                flags = BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA;
-               ret = update_space_info(fs_info, flags, 0, 0, &space_info);
+               ret = update_space_info(fs_info, flags, 0, 0, 0, &space_info);
        } else {
                flags = BTRFS_BLOCK_GROUP_METADATA;
-               ret = update_space_info(fs_info, flags, 0, 0, &space_info);
+               ret = update_space_info(fs_info, flags, 0, 0, 0, &space_info);
                if (ret)
                        goto out;
 
                flags = BTRFS_BLOCK_GROUP_DATA;
-               ret = update_space_info(fs_info, flags, 0, 0, &space_info);
+               ret = update_space_info(fs_info, flags, 0, 0, 0, &space_info);
        }
 out:
        return ret;