* [PATCH 1/2] btrfs: simplify setting the full backref flag at update_ref_for_cow()
2024-06-18 15:14 [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow() fdmanana
@ 2024-06-18 15:14 ` fdmanana
2024-06-18 15:14 ` [PATCH 2/2] btrfs: replace BUG_ON() with error handling " fdmanana
2024-06-19 9:05 ` [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow() Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2024-06-18 15:14 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
We keep a "new_flags" variable only to keep track if we need to update the
metadata extent's flags, and when we set BTRFS_BLOCK_FLAG_FULL_BACKREF in
the variable, we do it in an inner scope. Then check in an outer scope
if the variable is not 0 and if so call btrfs_set_disk_extent_flags().
The variable isn't used for anything else. This is somewhat confusing, so
to make it more straightforward update the extent's flags where we are
currently updating "new_flags" and remove the variable.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 763b9a1da428..7b2f1de845e7 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -417,7 +417,6 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
u64 refs;
u64 owner;
u64 flags;
- u64 new_flags = 0;
int ret;
/*
@@ -481,7 +480,10 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
if (ret)
return ret;
}
- new_flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
+ ret = btrfs_set_disk_extent_flags(trans, buf,
+ BTRFS_BLOCK_FLAG_FULL_BACKREF);
+ if (ret)
+ return ret;
} else {
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
@@ -491,11 +493,6 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
if (ret)
return ret;
}
- if (new_flags != 0) {
- ret = btrfs_set_disk_extent_flags(trans, buf, new_flags);
- if (ret)
- return ret;
- }
} else {
if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] btrfs: replace BUG_ON() with error handling at update_ref_for_cow()
2024-06-18 15:14 [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow() fdmanana
2024-06-18 15:14 ` [PATCH 1/2] btrfs: simplify setting the full backref flag at update_ref_for_cow() fdmanana
@ 2024-06-18 15:14 ` fdmanana
2024-06-19 9:05 ` [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow() Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2024-06-18 15:14 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
Instead of a BUG_ON() just return an error, log an error message and
abort the transaction in case we find an extent buffer belonging to the
relocation tree that doesn't have the full backref flag set. This is
unexpected and should never happen (save for bugs or a potential bad
memory).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/ctree.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 7b2f1de845e7..e33f9f5a228d 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -461,8 +461,16 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
}
owner = btrfs_header_owner(buf);
- BUG_ON(owner == BTRFS_TREE_RELOC_OBJECTID &&
- !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF));
+ if (unlikely(owner == BTRFS_TREE_RELOC_OBJECTID &&
+ !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))) {
+ btrfs_crit(fs_info,
+"found tree block at bytenr %llu level %d root %llu refs %llu flags %llx without full backref flag set",
+ buf->start, btrfs_header_level(buf),
+ btrfs_root_id(root), refs, flags);
+ ret = -EUCLEAN;
+ btrfs_abort_transaction(trans, ret);
+ return ret;
+ }
if (refs > 1) {
if ((owner == btrfs_root_id(root) ||
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow()
2024-06-18 15:14 [PATCH 0/2] btrfs: a few cleanups for update_ref_for_cow() fdmanana
2024-06-18 15:14 ` [PATCH 1/2] btrfs: simplify setting the full backref flag at update_ref_for_cow() fdmanana
2024-06-18 15:14 ` [PATCH 2/2] btrfs: replace BUG_ON() with error handling " fdmanana
@ 2024-06-19 9:05 ` Qu Wenruo
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2024-06-19 9:05 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2024/6/19 00:44, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> Detais in the change logs, trivial changes.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> Filipe Manana (2):
> btrfs: simplify setting the full backref flag at update_ref_for_cow()
> btrfs: replace BUG_ON() with error handling at update_ref_for_cow()
>
> fs/btrfs/ctree.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread