* [PATCH 1/3] btrfs: don't BUG() on unexpected delayed ref type in run_one_delayed_ref()
2026-01-13 16:50 [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups fdmanana
@ 2026-01-13 16:50 ` fdmanana
2026-01-13 16:50 ` [PATCH 2/3] btrfs: remove unnecessary else branch " fdmanana
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: fdmanana @ 2026-01-13 16:50 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
There is no need to BUG(), we can just return an error and log an error
message.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent-tree.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1dcd69fe97ed..5ca65df8d04e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1761,32 +1761,36 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_extent_op *extent_op,
bool insert_reserved)
{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
int ret = 0;
if (TRANS_ABORTED(trans)) {
if (insert_reserved) {
btrfs_pin_extent(trans, node->bytenr, node->num_bytes);
- free_head_ref_squota_rsv(trans->fs_info, href);
+ free_head_ref_squota_rsv(fs_info, href);
}
return 0;
}
if (node->type == BTRFS_TREE_BLOCK_REF_KEY ||
- node->type == BTRFS_SHARED_BLOCK_REF_KEY)
+ node->type == BTRFS_SHARED_BLOCK_REF_KEY) {
ret = run_delayed_tree_ref(trans, href, node, extent_op,
insert_reserved);
- else if (node->type == BTRFS_EXTENT_DATA_REF_KEY ||
- node->type == BTRFS_SHARED_DATA_REF_KEY)
+ } else if (node->type == BTRFS_EXTENT_DATA_REF_KEY ||
+ node->type == BTRFS_SHARED_DATA_REF_KEY) {
ret = run_delayed_data_ref(trans, href, node, extent_op,
insert_reserved);
- else if (node->type == BTRFS_EXTENT_OWNER_REF_KEY)
+ } else if (node->type == BTRFS_EXTENT_OWNER_REF_KEY) {
ret = 0;
- else
- BUG();
+ } else {
+ ret = -EUCLEAN;
+ btrfs_err(fs_info, "unexpected delayed ref node type: %u", node->type);
+ }
+
if (ret && insert_reserved)
btrfs_pin_extent(trans, node->bytenr, node->num_bytes);
if (ret < 0)
- btrfs_err(trans->fs_info,
+ btrfs_err(fs_info,
"failed to run delayed ref for logical %llu num_bytes %llu type %u action %u ref_mod %d: %d",
node->bytenr, node->num_bytes, node->type,
node->action, node->ref_mod, ret);
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] btrfs: remove unnecessary else branch in run_one_delayed_ref()
2026-01-13 16:50 [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups fdmanana
2026-01-13 16:50 ` [PATCH 1/3] btrfs: don't BUG() on unexpected delayed ref type in run_one_delayed_ref() fdmanana
@ 2026-01-13 16:50 ` fdmanana
2026-01-13 16:50 ` [PATCH 3/3] btrfs: tag as unlikely error handling " fdmanana
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: fdmanana @ 2026-01-13 16:50 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
There is no need for an else branch to deal with an unexpected delayed ref
type. We can just change the previous branch to deal with this by checking
if the ref type is not BTRFS_EXTENT_OWNER_REF_KEY, since that branch is
useless as it only sets 'ret' to zero when it's already zero. So merge the
two branches.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent-tree.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 5ca65df8d04e..ffb62b58a919 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1780,9 +1780,7 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
node->type == BTRFS_SHARED_DATA_REF_KEY) {
ret = run_delayed_data_ref(trans, href, node, extent_op,
insert_reserved);
- } else if (node->type == BTRFS_EXTENT_OWNER_REF_KEY) {
- ret = 0;
- } else {
+ } else if (node->type != BTRFS_EXTENT_OWNER_REF_KEY) {
ret = -EUCLEAN;
btrfs_err(fs_info, "unexpected delayed ref node type: %u", node->type);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] btrfs: tag as unlikely error handling in run_one_delayed_ref()
2026-01-13 16:50 [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups fdmanana
2026-01-13 16:50 ` [PATCH 1/3] btrfs: don't BUG() on unexpected delayed ref type in run_one_delayed_ref() fdmanana
2026-01-13 16:50 ` [PATCH 2/3] btrfs: remove unnecessary else branch " fdmanana
@ 2026-01-13 16:50 ` fdmanana
2026-01-13 18:27 ` [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups Boris Burkov
2026-01-13 21:04 ` Qu Wenruo
4 siblings, 0 replies; 6+ messages in thread
From: fdmanana @ 2026-01-13 16:50 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
We don't expect to get errors unless we have a corrupted fs, bad ram or a
bug. So tag the error handling as unlikely.
This slightly reduces the module's text size on x86_64 using gcc 14.2.0-19
from Debian.
Before this change:
$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1939458 172512 15592 2127562 2076ca fs/btrfs/btrfs.ko
After this change:
$ size fs/btrfs/btrfs.ko
text data bss dec hex filename
1939398 172512 15592 2127502 20768e fs/btrfs/btrfs.ko
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/extent-tree.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index ffb62b58a919..01a796c536f2 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1785,13 +1785,15 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
btrfs_err(fs_info, "unexpected delayed ref node type: %u", node->type);
}
- if (ret && insert_reserved)
- btrfs_pin_extent(trans, node->bytenr, node->num_bytes);
- if (ret < 0)
+ if (unlikely(ret)) {
+ if (insert_reserved)
+ btrfs_pin_extent(trans, node->bytenr, node->num_bytes);
btrfs_err(fs_info,
"failed to run delayed ref for logical %llu num_bytes %llu type %u action %u ref_mod %d: %d",
node->bytenr, node->num_bytes, node->type,
node->action, node->ref_mod, ret);
+ }
+
return ret;
}
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups
2026-01-13 16:50 [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups fdmanana
` (2 preceding siblings ...)
2026-01-13 16:50 ` [PATCH 3/3] btrfs: tag as unlikely error handling " fdmanana
@ 2026-01-13 18:27 ` Boris Burkov
2026-01-13 21:04 ` Qu Wenruo
4 siblings, 0 replies; 6+ messages in thread
From: Boris Burkov @ 2026-01-13 18:27 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Tue, Jan 13, 2026 at 04:50:56PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Remove a BUG() call in run_one_delayed_ref() and a couple trivial cleanups
> in that function.
Reviewed-by: Boris Burkov <boris@bur.io>
>
> Filipe Manana (3):
> btrfs: don't BUG() on unexpected delayed ref type in run_one_delayed_ref()
> btrfs: remove unnecessary else branch in run_one_delayed_ref()
> btrfs: tag as unlikely error handling in run_one_delayed_ref()
>
> fs/btrfs/extent-tree.c | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
> --
> 2.47.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups
2026-01-13 16:50 [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups fdmanana
` (3 preceding siblings ...)
2026-01-13 18:27 ` [PATCH 0/3] btrfs: get rid of a BUG() in run_one_delayed_ref() and cleanups Boris Burkov
@ 2026-01-13 21:04 ` Qu Wenruo
4 siblings, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2026-01-13 21:04 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2026/1/14 03:20, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> Remove a BUG() call in run_one_delayed_ref() and a couple trivial cleanups
> in that function.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> Filipe Manana (3):
> btrfs: don't BUG() on unexpected delayed ref type in run_one_delayed_ref()
> btrfs: remove unnecessary else branch in run_one_delayed_ref()
> btrfs: tag as unlikely error handling in run_one_delayed_ref()
>
> fs/btrfs/extent-tree.c | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
^ permalink raw reply [flat|nested] 6+ messages in thread