]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: collapse unaccount_log_buffer() into clean_log_buffer()
authorFilipe Manana <fdmanana@suse.com>
Mon, 21 Jul 2025 16:43:41 +0000 (17:43 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Sep 2025 08:54:30 +0000 (10:54 +0200)
There's one only one caller of unaccount_log_buffer() and both this
function and the caller are short, so move its code into the caller.

Reviewed-by: Boris Burkov <boris@bur.io>
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>
fs/btrfs/tree-log.c

index 265ee7557ecb3d7ee7e5325f5bdcb7a9be95cb76..cbdc0c0b5e7c553c1921f6595fc239cff8c97850 100644 (file)
@@ -2731,35 +2731,11 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
        return ret;
 }
 
-/*
- * Correctly adjust the reserved bytes occupied by a log tree extent buffer
- */
-static int unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
-{
-       struct btrfs_block_group *cache;
-
-       cache = btrfs_lookup_block_group(fs_info, start);
-       if (!cache) {
-               btrfs_err(fs_info, "unable to find block group for %llu", start);
-               return -ENOENT;
-       }
-
-       spin_lock(&cache->space_info->lock);
-       spin_lock(&cache->lock);
-       cache->reserved -= fs_info->nodesize;
-       cache->space_info->bytes_reserved -= fs_info->nodesize;
-       spin_unlock(&cache->lock);
-       spin_unlock(&cache->space_info->lock);
-
-       btrfs_put_block_group(cache);
-
-       return 0;
-}
-
 static int clean_log_buffer(struct btrfs_trans_handle *trans,
                            struct extent_buffer *eb)
 {
-       int ret;
+       struct btrfs_fs_info *fs_info = eb->fs_info;
+       struct btrfs_block_group *bg;
 
        btrfs_tree_lock(eb);
        btrfs_clear_buffer_dirty(trans, eb);
@@ -2767,16 +2743,31 @@ static int clean_log_buffer(struct btrfs_trans_handle *trans,
        btrfs_tree_unlock(eb);
 
        if (trans) {
+               int ret;
+
                ret = btrfs_pin_reserved_extent(trans, eb);
                if (ret)
                        btrfs_abort_transaction(trans, ret);
                return ret;
        }
 
-       ret = unaccount_log_buffer(eb->fs_info, eb->start);
-       if (ret)
-               btrfs_handle_fs_error(eb->fs_info, ret, NULL);
-       return ret;
+       bg = btrfs_lookup_block_group(fs_info, eb->start);
+       if (!bg) {
+               btrfs_err(fs_info, "unable to find block group for %llu", eb->start);
+               btrfs_handle_fs_error(fs_info, -ENOENT, NULL);
+               return -ENOENT;
+       }
+
+       spin_lock(&bg->space_info->lock);
+       spin_lock(&bg->lock);
+       bg->reserved -= fs_info->nodesize;
+       bg->space_info->bytes_reserved -= fs_info->nodesize;
+       spin_unlock(&bg->lock);
+       spin_unlock(&bg->space_info->lock);
+
+       btrfs_put_block_group(bg);
+
+       return 0;
 }
 
 static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,