btrfs: move btrfs_account_ro_block_groups_free_space into space-info.c
authorJosef Bacik <josef@toxicpanda.com>
Mon, 24 Oct 2022 18:46:56 +0000 (14:46 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:44 +0000 (18:00 +0100)
This was prototyped in ctree.h and the code existed in extent-tree.c,
but it's space-info related so move it into space-info.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c
fs/btrfs/space-info.c
fs/btrfs/space-info.h

index a430577cf8b7bd08b2d92a7d05c7eaf44f99b373..07f876961da1d771286863b8ac93eb829a22b8e6 100644 (file)
@@ -576,7 +576,6 @@ void btrfs_delalloc_release_extents(struct btrfs_inode *inode, u64 num_bytes);
 
 int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes,
                                    u64 disk_num_bytes, bool noflush);
-u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
                                   u64 start, u64 end);
 int btrfs_discard_extent(struct btrfs_fs_info *fs_info, u64 bytenr,
index 8d28ba360e9a5f0c5d1469353f0f8de536f68010..b97c99a8dd4cae0e0f05bf4fed72acd604dfde1c 100644 (file)
@@ -5975,40 +5975,6 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
        return ret;
 }
 
-/*
- * helper to account the unused space of all the readonly block group in the
- * space_info. takes mirrors into account.
- */
-u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo)
-{
-       struct btrfs_block_group *block_group;
-       u64 free_bytes = 0;
-       int factor;
-
-       /* It's df, we don't care if it's racy */
-       if (list_empty(&sinfo->ro_bgs))
-               return 0;
-
-       spin_lock(&sinfo->lock);
-       list_for_each_entry(block_group, &sinfo->ro_bgs, ro_list) {
-               spin_lock(&block_group->lock);
-
-               if (!block_group->ro) {
-                       spin_unlock(&block_group->lock);
-                       continue;
-               }
-
-               factor = btrfs_bg_type_to_factor(block_group->flags);
-               free_bytes += (block_group->length -
-                              block_group->used) * factor;
-
-               spin_unlock(&block_group->lock);
-       }
-       spin_unlock(&sinfo->lock);
-
-       return free_bytes;
-}
-
 int btrfs_error_unpin_extent_range(struct btrfs_fs_info *fs_info,
                                   u64 start, u64 end)
 {
index 94d73485454a258793e2491b38b490f158bdd35a..45404798ee8c2c8857b5fa5ad4e4118bd822e2e4 100644 (file)
@@ -1814,3 +1814,37 @@ __cold void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info)
        }
        dump_global_block_rsv(fs_info);
 }
+
+/*
+ * Account the unused space of all the readonly block group in the space_info.
+ * takes mirrors into account.
+ */
+u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo)
+{
+       struct btrfs_block_group *block_group;
+       u64 free_bytes = 0;
+       int factor;
+
+       /* It's df, we don't care if it's racy */
+       if (list_empty(&sinfo->ro_bgs))
+               return 0;
+
+       spin_lock(&sinfo->lock);
+       list_for_each_entry(block_group, &sinfo->ro_bgs, ro_list) {
+               spin_lock(&block_group->lock);
+
+               if (!block_group->ro) {
+                       spin_unlock(&block_group->lock);
+                       continue;
+               }
+
+               factor = btrfs_bg_type_to_factor(block_group->flags);
+               free_bytes += (block_group->length -
+                              block_group->used) * factor;
+
+               spin_unlock(&block_group->lock);
+       }
+       spin_unlock(&sinfo->lock);
+
+       return free_bytes;
+}
index f28bd2c051d497c870c8c5a4e7660009c2811cea..fc99ea2b0c34fc2187813dffc2a206577e65ee22 100644 (file)
@@ -236,5 +236,6 @@ int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes,
                             enum btrfs_reserve_flush_enum flush);
 void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info);
 void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info);
+u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
 
 #endif /* BTRFS_SPACE_INFO_H */