]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: abort transaction in the process_one_buffer() log tree walk callback
authorFilipe Manana <fdmanana@suse.com>
Wed, 16 Jul 2025 14:49:31 +0000 (15:49 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Sep 2025 08:54:29 +0000 (10:54 +0200)
In the process_one_buffer() log tree walk callback we return errors to the
log tree walk caller and then the caller aborts the transaction, if we
have one, or turns the fs into error state if we don't have one. While
this reduces code it makes it harder to figure out where exactly an error
came from. So add the transaction aborts after every failure inside the
process_one_buffer() callback, so that it helps figuring out why failures
happen.

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 6d92326a1a0c74a8753c9e8c85cb9e68351daee4..50ed84cb68a69623e17aa0374c0516db57332d42 100644 (file)
@@ -347,6 +347,7 @@ static int process_one_buffer(struct btrfs_root *log,
                              struct extent_buffer *eb,
                              struct walk_control *wc, u64 gen, int level)
 {
+       struct btrfs_trans_handle *trans = wc->trans;
        struct btrfs_fs_info *fs_info = log->fs_info;
        int ret = 0;
 
@@ -361,18 +362,29 @@ static int process_one_buffer(struct btrfs_root *log,
                };
 
                ret = btrfs_read_extent_buffer(eb, &check);
-               if (ret)
+               if (ret) {
+                       if (trans)
+                               btrfs_abort_transaction(trans, ret);
+                       else
+                               btrfs_handle_fs_error(fs_info, ret, NULL);
                        return ret;
+               }
        }
 
        if (wc->pin) {
-               ret = btrfs_pin_extent_for_log_replay(wc->trans, eb);
-               if (ret)
+               ASSERT(trans != NULL);
+               ret = btrfs_pin_extent_for_log_replay(trans, eb);
+               if (ret) {
+                       btrfs_abort_transaction(trans, ret);
                        return ret;
+               }
 
                if (btrfs_buffer_uptodate(eb, gen, 0) &&
-                   btrfs_header_level(eb) == 0)
+                   btrfs_header_level(eb) == 0) {
                        ret = btrfs_exclude_logged_extents(eb);
+                       if (ret)
+                               btrfs_abort_transaction(trans, ret);
+               }
        }
        return ret;
 }