btrfs: factor out check_removing_space_info() from btrfs_free_block_groups()
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 23 Apr 2025 02:43:45 +0000 (11:43 +0900)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:53 +0000 (14:30 +0200)
Factor out check_removing_space_info() from btrfs_free_block_groups(). It
sanity checks a to-be-removed space_info. There is no functional change.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c

index e3b912d539e294bab6bf774ff97886352e50dad1..eaf431b9b44cc0676aeaa80fe4759484a666f3d1 100644 (file)
@@ -4400,6 +4400,32 @@ void btrfs_put_block_group_cache(struct btrfs_fs_info *info)
        }
 }
 
+static void check_removing_space_info(struct btrfs_space_info *space_info)
+{
+       struct btrfs_fs_info *info = space_info->fs_info;
+
+       /*
+        * Do not hide this behind enospc_debug, this is actually important and
+        * indicates a real bug if this happens.
+        */
+       if (WARN_ON(space_info->bytes_pinned > 0 || space_info->bytes_may_use > 0))
+               btrfs_dump_space_info(info, space_info, 0, 0);
+
+       /*
+        * If there was a failure to cleanup a log tree, very likely due to an
+        * IO failure on a writeback attempt of one or more of its extent
+        * buffers, we could not do proper (and cheap) unaccounting of their
+        * reserved space, so don't warn on bytes_reserved > 0 in that case.
+        */
+       if (!(space_info->flags & BTRFS_BLOCK_GROUP_METADATA) ||
+           !BTRFS_FS_LOG_CLEANUP_ERROR(info)) {
+               if (WARN_ON(space_info->bytes_reserved > 0))
+                       btrfs_dump_space_info(info, space_info, 0, 0);
+       }
+
+       WARN_ON(space_info->reclaim_size > 0);
+}
+
 /*
  * Must be called only after stopping all workers, since we could have block
  * group caching kthreads running, and therefore they could race with us if we
@@ -4500,28 +4526,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
                space_info = list_first_entry(&info->space_info,
                                              struct btrfs_space_info, list);
 
-               /*
-                * Do not hide this behind enospc_debug, this is actually
-                * important and indicates a real bug if this happens.
-                */
-               if (WARN_ON(space_info->bytes_pinned > 0 ||
-                           space_info->bytes_may_use > 0))
-                       btrfs_dump_space_info(info, space_info, 0, 0);
-
-               /*
-                * If there was a failure to cleanup a log tree, very likely due
-                * to an IO failure on a writeback attempt of one or more of its
-                * extent buffers, we could not do proper (and cheap) unaccounting
-                * of their reserved space, so don't warn on bytes_reserved > 0 in
-                * that case.
-                */
-               if (!(space_info->flags & BTRFS_BLOCK_GROUP_METADATA) ||
-                   !BTRFS_FS_LOG_CLEANUP_ERROR(info)) {
-                       if (WARN_ON(space_info->bytes_reserved > 0))
-                               btrfs_dump_space_info(info, space_info, 0, 0);
-               }
-
-               WARN_ON(space_info->reclaim_size > 0);
+               check_removing_space_info(space_info);
                list_del(&space_info->list);
                btrfs_sysfs_remove_space_info(space_info);
        }