btrfs: print available space across all block groups when dumping space info
authorFilipe Manana <fdmanana@suse.com>
Wed, 26 Jul 2023 15:57:02 +0000 (16:57 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2023 12:52:17 +0000 (14:52 +0200)
When dumping a space info also sum the available space for all block
groups and then print it. This often useful for debugging -ENOSPC
related problems.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c

index 54d78e8..de00442 100644 (file)
@@ -510,6 +510,7 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
                           int dump_block_groups)
 {
        struct btrfs_block_group *cache;
+       u64 total_avail = 0;
        int index = 0;
 
        spin_lock(&info->lock);
@@ -537,10 +538,13 @@ again:
                           avail, cache->ro ? "[readonly]" : "");
                spin_unlock(&cache->lock);
                btrfs_dump_free_space(cache, bytes);
+               total_avail += avail;
        }
        if (++index < BTRFS_NR_RAID_TYPES)
                goto again;
        up_read(&info->groups_sem);
+
+       btrfs_info(fs_info, "%llu bytes available across all block groups", total_avail);
 }
 
 static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info,