Skip to content

Commit 2b6dda6

Browse files
fdmananakdave
authored andcommitted
btrfs: abort transaction in the process_one_buffer() log tree walk callback
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 <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 03a717b commit 2b6dda6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

fs/btrfs/tree-log.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ static int process_one_buffer(struct btrfs_root *log,
348348
struct extent_buffer *eb,
349349
struct walk_control *wc, u64 gen, int level)
350350
{
351+
struct btrfs_trans_handle *trans = wc->trans;
351352
struct btrfs_fs_info *fs_info = log->fs_info;
352353
int ret = 0;
353354

@@ -362,18 +363,35 @@ static int process_one_buffer(struct btrfs_root *log,
362363
};
363364

364365
ret = btrfs_read_extent_buffer(eb, &check);
365-
if (ret)
366+
if (ret) {
367+
if (trans)
368+
btrfs_abort_transaction(trans, ret);
369+
else
370+
btrfs_handle_fs_error(fs_info, ret, NULL);
366371
return ret;
372+
}
367373
}
368374

369375
if (wc->pin) {
370-
ret = btrfs_pin_extent_for_log_replay(wc->trans, eb);
371-
if (ret)
376+
ret = btrfs_pin_extent_for_log_replay(trans, eb);
377+
if (ret) {
378+
if (trans)
379+
btrfs_abort_transaction(trans, ret);
380+
else
381+
btrfs_handle_fs_error(fs_info, ret, NULL);
372382
return ret;
383+
}
373384

374385
if (btrfs_buffer_uptodate(eb, gen, 0) &&
375-
btrfs_header_level(eb) == 0)
386+
btrfs_header_level(eb) == 0) {
376387
ret = btrfs_exclude_logged_extents(eb);
388+
if (ret) {
389+
if (trans)
390+
btrfs_abort_transaction(trans, ret);
391+
else
392+
btrfs_handle_fs_error(fs_info, ret, NULL);
393+
}
394+
}
377395
}
378396
return ret;
379397
}

0 commit comments

Comments
 (0)