Skip to content

Commit eced687

Browse files
fdmananakdave
authored andcommitted
btrfs: abort transaction at update_ref_for_cow() when ref count is zero
At update_ref_for_cow() we are calling btrfs_handle_fs_error() if we find that the extent buffer has an unexpected ref count of zero, however we can simply use btrfs_abort_transaction(), which achieves the same purposes: to turn the fs to error state, abort the current transaction and turn the fs to RO mode as well. Besides that, btrfs_abort_transaction() also prints a stack trace which makes it more useful. Also, as this is a very unexpected situation, indicating a serious corruption/inconsistency, tag the if branch as 'unlikely', set the error code to -EUCLEAN instead of -EROFS, and log an explicit message. 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>
1 parent 725026e commit eced687

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,13 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
421421
&refs, &flags);
422422
if (ret)
423423
return ret;
424-
if (refs == 0) {
425-
ret = -EROFS;
426-
btrfs_handle_fs_error(fs_info, ret, NULL);
424+
if (unlikely(refs == 0)) {
425+
btrfs_crit(fs_info,
426+
"found 0 references for tree block at bytenr %llu level %d root %llu",
427+
buf->start, btrfs_header_level(buf),
428+
btrfs_root_id(root));
429+
ret = -EUCLEAN;
430+
btrfs_abort_transaction(trans, ret);
427431
return ret;
428432
}
429433
} else {

0 commit comments

Comments
 (0)