]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: use local variable for space_info in pin_down_extent()
authorFilipe Manana <fdmanana@suse.com>
Mon, 20 Oct 2025 12:40:56 +0000 (13:40 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:15:58 +0000 (22:15 +0100)
Instead of dereferencing the block group multiple times to access its
space_info, use a local variable to shorten the code horizontal wise and
make it easier to read. Also, while at it, also rename the block group
argument from 'cache' to 'bg', as the cache name is confusing and it's
from the old days where the block group structure was named as
'btrfs_block_group_cache'.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 70b77fe21b9fd68fe213451b6c472f172bceb3f1..4be20949f0ba1ba76dbf86eb95ace02ce2793f67 100644 (file)
@@ -2591,19 +2591,20 @@ static u64 first_logical_byte(struct btrfs_fs_info *fs_info)
 }
 
 static int pin_down_extent(struct btrfs_trans_handle *trans,
-                          struct btrfs_block_group *cache,
+                          struct btrfs_block_group *bg,
                           u64 bytenr, u64 num_bytes, int reserved)
 {
+       struct btrfs_space_info *space_info = bg->space_info;
        const u64 reserved_bytes = (reserved ? num_bytes : 0);
 
-       spin_lock(&cache->space_info->lock);
-       spin_lock(&cache->lock);
-       cache->pinned += num_bytes;
-       cache->reserved -= reserved_bytes;
-       spin_unlock(&cache->lock);
-       cache->space_info->bytes_reserved -= reserved_bytes;
-       btrfs_space_info_update_bytes_pinned(cache->space_info, num_bytes);
-       spin_unlock(&cache->space_info->lock);
+       spin_lock(&space_info->lock);
+       spin_lock(&bg->lock);
+       bg->pinned += num_bytes;
+       bg->reserved -= reserved_bytes;
+       spin_unlock(&bg->lock);
+       space_info->bytes_reserved -= reserved_bytes;
+       btrfs_space_info_update_bytes_pinned(space_info, num_bytes);
+       spin_unlock(&space_info->lock);
 
        btrfs_set_extent_bit(&trans->transaction->pinned_extents, bytenr,
                             bytenr + num_bytes - 1, EXTENT_DIRTY, NULL);