From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Filipe Manana <fdmanana@suse.com>, Qu Wenruo <wqu@suse.com>,
David Sterba <dsterba@suse.com>, Sasha Levin <sashal@kernel.org>,
clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.4 14/15] btrfs: abort transaction at update_ref_for_cow() when ref count is zero
Date: Sun, 2 Jul 2023 15:40:19 -0400 [thread overview]
Message-ID: <20230702194020.1776895-14-sashal@kernel.org> (raw)
In-Reply-To: <20230702194020.1776895-1-sashal@kernel.org>
From: Filipe Manana <fdmanana@suse.com>
[ Upstream commit eced687e224eb3cc5a501cf53ad9291337c8dbc5 ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/btrfs/ctree.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 2ff2961b11830..0ba4d1e6a94ec 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -417,9 +417,13 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
&refs, &flags);
if (ret)
return ret;
- if (refs == 0) {
- ret = -EROFS;
- btrfs_handle_fs_error(fs_info, ret, NULL);
+ if (unlikely(refs == 0)) {
+ btrfs_crit(fs_info,
+ "found 0 references for tree block at bytenr %llu level %d root %llu",
+ buf->start, btrfs_header_level(buf),
+ btrfs_root_id(root));
+ ret = -EUCLEAN;
+ btrfs_abort_transaction(trans, ret);
return ret;
}
} else {
--
2.39.2
next prev parent reply other threads:[~2023-07-02 19:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-02 19:40 [PATCH AUTOSEL 6.4 01/15] cpu/hotplug: Reset task stack state in _cpu_up() Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 02/15] x86/smpboot: Implement a bit spinlock to protect the realmode stack Sasha Levin
2023-07-03 9:19 ` [EXTERNAL] " David Woodhouse
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 03/15] io_uring: annotate offset timeout races Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 04/15] x86/amd_nb: Add MI200 PCI IDs Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 05/15] debugobjects: Recheck debug_objects_enabled before reporting Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 06/15] nbd: Add the maximum limit of allocated index in nbd_dev_add Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 07/15] md: fix data corruption for raid456 when reshape restart while grow up Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 08/15] md/raid10: prevent soft lockup while flush writes Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 09/15] scsi: sg: fix blktrace debugfs entries leakage Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 10/15] blk-mq: fix NULL dereference on q->elevator in blk_mq_elv_switch_none Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 11/15] posix-timers: Ensure timer ID search-loop limit is valid Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 12/15] btrfs: add xxhash to fast checksum implementations Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 13/15] btrfs: don't check PageError in __extent_writepage Sasha Levin
2023-07-02 19:40 ` Sasha Levin [this message]
2023-07-02 19:40 ` [PATCH AUTOSEL 6.4 15/15] erofs: Fix detection of atomic context Sasha Levin
2023-07-03 9:17 ` [PATCH AUTOSEL 6.4 01/15] cpu/hotplug: Reset task stack state in _cpu_up() David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230702194020.1776895-14-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox