Skip to content

Commit

Permalink
btrfs: change handle_fs_error in recover_log_trees to aborts
Browse files Browse the repository at this point in the history
During inspection of the return path for replay I noticed that we don't
actually abort the transaction if we get a failure during replay.  This
isn't a problem necessarily, as we properly return the error and will
fail to mount.  However we still leave this dangling transaction that
could conceivably be committed without thinking there was an error.

We were using btrfs_handle_fs_error() here, but that pre-dates the
transaction abort code.  Simply replace the btrfs_handle_fs_error()
calls with transaction aborts, so we still know where exactly things
went wrong, and add a few in some other un-handled error cases.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Josef Bacik authored and David Sterba committed Oct 26, 2021
1 parent 64259ba commit ba51e2a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions fs/btrfs/tree-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -6548,8 +6548,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)

ret = walk_log_tree(trans, log_root_tree, &wc);
if (ret) {
btrfs_handle_fs_error(fs_info, ret,
"Failed to pin buffers while recovering log root tree.");
btrfs_abort_transaction(trans, ret);
goto error;
}

Expand All @@ -6562,8 +6561,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
ret = btrfs_search_slot(NULL, log_root_tree, &key, path, 0, 0);

if (ret < 0) {
btrfs_handle_fs_error(fs_info, ret,
"Couldn't find tree log root.");
btrfs_abort_transaction(trans, ret);
goto error;
}
if (ret > 0) {
Expand All @@ -6580,8 +6578,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
log = btrfs_read_tree_root(log_root_tree, &found_key);
if (IS_ERR(log)) {
ret = PTR_ERR(log);
btrfs_handle_fs_error(fs_info, ret,
"Couldn't read tree log root.");
btrfs_abort_transaction(trans, ret);
goto error;
}

Expand Down Expand Up @@ -6609,23 +6606,23 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)

if (!ret)
goto next;
btrfs_handle_fs_error(fs_info, ret,
"Couldn't read target root for tree log recovery.");
btrfs_abort_transaction(trans, ret);
goto error;
}

wc.replay_dest->log_root = log;
ret = btrfs_record_root_in_trans(trans, wc.replay_dest);
if (ret)
/* The loop needs to continue due to the root refs */
btrfs_handle_fs_error(fs_info, ret,
"failed to record the log root in transaction");
btrfs_abort_transaction(trans, ret);
else
ret = walk_log_tree(trans, log, &wc);

if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) {
ret = fixup_inode_link_counts(trans, wc.replay_dest,
path);
if (ret)
btrfs_abort_transaction(trans, ret);
}

if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) {
Expand All @@ -6642,6 +6639,8 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
* could only happen during mount.
*/
ret = btrfs_init_root_free_objectid(root);
if (ret)
btrfs_abort_transaction(trans, ret);
}

wc.replay_dest->log_root = NULL;
Expand Down

0 comments on commit ba51e2a

Please sign in to comment.