]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/btrfs/extent-tree.c
Btrfs: make add_pinned_bytes() take an s64 num_bytes instead of u64
[mirror_ubuntu-bionic-kernel.git] / fs / btrfs / extent-tree.c
index 4e88df0b3f0a5681caf8f6a745e4b5c592bb9ded..d784ecef27c034468d965eefd54d767dc831a1da 100644 (file)
@@ -767,6 +767,26 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
        return NULL;
 }
 
+static void add_pinned_bytes(struct btrfs_fs_info *fs_info, s64 num_bytes,
+                            u64 owner, u64 root_objectid)
+{
+       struct btrfs_space_info *space_info;
+       u64 flags;
+
+       if (owner < BTRFS_FIRST_FREE_OBJECTID) {
+               if (root_objectid == BTRFS_CHUNK_TREE_OBJECTID)
+                       flags = BTRFS_BLOCK_GROUP_SYSTEM;
+               else
+                       flags = BTRFS_BLOCK_GROUP_METADATA;
+       } else {
+               flags = BTRFS_BLOCK_GROUP_DATA;
+       }
+
+       space_info = __find_space_info(fs_info, flags);
+       BUG_ON(!space_info); /* Logic bug */
+       percpu_counter_add(&space_info->total_bytes_pinned, num_bytes);
+}
+
 /*
  * after adding space to the filesystem, we need to clear the full flags
  * on all the space infos.
@@ -3972,7 +3992,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags,
        return ret;
 }
 
-static int update_space_info(struct btrfs_fs_info *info, u64 flags,
+static void 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)
@@ -3987,21 +4007,19 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
                factor = 1;
 
        found = __find_space_info(info, flags);
-       if (found) {
-               spin_lock(&found->lock);
-               found->total_bytes += total_bytes;
-               found->disk_total += total_bytes * factor;
-               found->bytes_used += bytes_used;
-               found->disk_used += bytes_used * factor;
-               found->bytes_readonly += bytes_readonly;
-               if (total_bytes > 0)
-                       found->full = 0;
-               space_info_add_new_bytes(info, found, total_bytes -
-                                        bytes_used - bytes_readonly);
-               spin_unlock(&found->lock);
-               *space_info = found;
-               return 0;
-       }
+       ASSERT(found);
+       spin_lock(&found->lock);
+       found->total_bytes += total_bytes;
+       found->disk_total += total_bytes * factor;
+       found->bytes_used += bytes_used;
+       found->disk_used += bytes_used * factor;
+       found->bytes_readonly += bytes_readonly;
+       if (total_bytes > 0)
+               found->full = 0;
+       space_info_add_new_bytes(info, found, total_bytes -
+                                bytes_used - bytes_readonly);
+       spin_unlock(&found->lock);
+       *space_info = found;
 }
 
 static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
@@ -4951,9 +4969,8 @@ btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
                           BTRFS_RESERVE_FLUSH_ALL, system_chunk))
                return 0;
 
-       used = space_info->bytes_used + space_info->bytes_reserved +
-              space_info->bytes_pinned + space_info->bytes_readonly +
-              space_info->bytes_may_use;
+       used = btrfs_space_info_used(space_info, true);
+
        if (can_overcommit(fs_info, space_info, SZ_1M,
                           BTRFS_RESERVE_FLUSH_ALL, system_chunk))
                expected = div_factor_fine(space_info->total_bytes, 95);
@@ -5400,9 +5417,7 @@ static void space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
         * overcommit, and if we can't then we just need to free up our space
         * and not satisfy any requests.
         */
-       used = space_info->bytes_used + space_info->bytes_reserved +
-               space_info->bytes_pinned + space_info->bytes_readonly +
-               space_info->bytes_may_use;
+       used = btrfs_space_info_used(space_info, true);
        if (used - num_bytes >= space_info->total_bytes)
                check_overcommit = true;
 again:
@@ -6813,27 +6828,6 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
        return 0;
 }
 
-static void add_pinned_bytes(struct btrfs_fs_info *fs_info, u64 num_bytes,
-                            u64 owner, u64 root_objectid)
-{
-       struct btrfs_space_info *space_info;
-       u64 flags;
-
-       if (owner < BTRFS_FIRST_FREE_OBJECTID) {
-               if (root_objectid == BTRFS_CHUNK_TREE_OBJECTID)
-                       flags = BTRFS_BLOCK_GROUP_SYSTEM;
-               else
-                       flags = BTRFS_BLOCK_GROUP_METADATA;
-       } else {
-               flags = BTRFS_BLOCK_GROUP_DATA;
-       }
-
-       space_info = __find_space_info(fs_info, flags);
-       BUG_ON(!space_info); /* Logic bug */
-       percpu_counter_add(&space_info->total_bytes_pinned, num_bytes);
-}
-
-
 static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
                                struct btrfs_fs_info *info,
                                struct btrfs_delayed_ref_node *node, u64 parent,
@@ -10078,19 +10072,9 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
                }
 
                trace_btrfs_add_block_group(info, cache, 0);
-               ret = update_space_info(info, cache->flags, found_key.offset,
-                                       btrfs_block_group_used(&cache->item),
-                                       cache->bytes_super, &space_info);
-               if (ret) {
-                       btrfs_remove_free_space_cache(cache);
-                       spin_lock(&info->block_group_cache_lock);
-                       rb_erase(&cache->cache_node,
-                                &info->block_group_cache_tree);
-                       RB_CLEAR_NODE(&cache->cache_node);
-                       spin_unlock(&info->block_group_cache_lock);
-                       btrfs_put_block_group(cache);
-                       goto error;
-               }
+               update_space_info(info, cache->flags, found_key.offset,
+                                 btrfs_block_group_used(&cache->item),
+                                 cache->bytes_super, &space_info);
 
                cache->space_info = space_info;
 
@@ -10249,18 +10233,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
         * the rbtree, update the space info's counters.
         */
        trace_btrfs_add_block_group(fs_info, cache, 1);
-       ret = update_space_info(fs_info, cache->flags, size, bytes_used,
+       update_space_info(fs_info, cache->flags, size, bytes_used,
                                cache->bytes_super, &cache->space_info);
-       if (ret) {
-               btrfs_remove_free_space_cache(cache);
-               spin_lock(&fs_info->block_group_cache_lock);
-               rb_erase(&cache->cache_node,
-                        &fs_info->block_group_cache_tree);
-               RB_CLEAR_NODE(&cache->cache_node);
-               spin_unlock(&fs_info->block_group_cache_lock);
-               btrfs_put_block_group(cache);
-               return ret;
-       }
        update_global_block_rsv(fs_info);
 
        __link_block_group(cache->space_info, cache);