Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

btrfs: add and use helper to compute the available space for a block group

We have currently three places that compute how much available space a
block group has. Add a helper function for this and use it in those
places.

Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
c208aa0e b322fa5f

+11 -9
+2 -7
fs/btrfs/block-group.c
··· 1376 1376 goto out; 1377 1377 } 1378 1378 1379 - num_bytes = cache->length - cache->reserved - cache->pinned - 1380 - cache->bytes_super - cache->zone_unusable - cache->used; 1379 + num_bytes = btrfs_block_group_available_space(cache); 1381 1380 1382 1381 /* 1383 1382 * Data never overcommits, even in mixed mode, so do just the straight ··· 3088 3089 void btrfs_dec_block_group_ro(struct btrfs_block_group *cache) 3089 3090 { 3090 3091 struct btrfs_space_info *sinfo = cache->space_info; 3091 - u64 num_bytes; 3092 3092 3093 3093 BUG_ON(!cache->ro); 3094 3094 ··· 3103 3105 btrfs_space_info_update_bytes_zone_unusable(sinfo, cache->zone_unusable); 3104 3106 sinfo->bytes_readonly -= cache->zone_unusable; 3105 3107 } 3106 - num_bytes = cache->length - cache->reserved - 3107 - cache->pinned - cache->bytes_super - 3108 - cache->zone_unusable - cache->used; 3109 - sinfo->bytes_readonly -= num_bytes; 3108 + sinfo->bytes_readonly -= btrfs_block_group_available_space(cache); 3110 3109 list_del_init(&cache->ro_list); 3111 3110 } 3112 3111 spin_unlock(&cache->lock);
+8
fs/btrfs/block-group.h
··· 295 295 !(block_group->flags & BTRFS_BLOCK_GROUP_METADATA); 296 296 } 297 297 298 + static inline u64 btrfs_block_group_available_space(const struct btrfs_block_group *bg) 299 + { 300 + lockdep_assert_held(&bg->lock); 301 + 302 + return (bg->length - bg->used - bg->pinned - bg->reserved - 303 + bg->bytes_super - bg->zone_unusable); 304 + } 305 + 298 306 #ifdef CONFIG_BTRFS_DEBUG 299 307 int btrfs_should_fragment_free_space(const struct btrfs_block_group *block_group); 300 308 #endif
+1 -2
fs/btrfs/space-info.c
··· 656 656 u64 avail; 657 657 658 658 spin_lock(&cache->lock); 659 - avail = cache->length - cache->used - cache->pinned - 660 - cache->reserved - cache->bytes_super - cache->zone_unusable; 659 + avail = btrfs_block_group_available_space(cache); 661 660 btrfs_info(fs_info, 662 661 "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu delalloc %llu super %llu zone_unusable (%llu bytes available) %s", 663 662 cache->start, cache->length, cache->used, cache->pinned,