public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root()
@ 2025-05-19 10:42 fdmanana
  2025-05-19 10:42 ` [PATCH 1/2] btrfs: unfold transaction abort at btrfs_copy_root() fdmanana
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fdmanana @ 2025-05-19 10:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

A couple simple cleanups, details in the change logs.

Filipe Manana (2):
  btrfs: unfold transaction abort at btrfs_copy_root()
  btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

 fs/btrfs/ctree.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] btrfs: unfold transaction abort at btrfs_copy_root()
  2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
@ 2025-05-19 10:42 ` fdmanana
  2025-05-19 10:42 ` [PATCH 2/2] btrfs: abort transaction on unexpected eb generation " fdmanana
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: fdmanana @ 2025-05-19 10:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

Instead of having a common btrfs_abort_transaction() call for when any of
the two btrfs_inc_ref() calls fail, move the btrfs_abort_transaction() to
happen immediately after each one of the calls, so that when analysing a
stack trace with a transaction abort we know which call failed.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 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 a2e7979372cc..ae6cd77282f5 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -284,14 +284,18 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
 
 	WARN_ON(btrfs_header_generation(buf) > trans->transid);
-	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
+	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		ret = btrfs_inc_ref(trans, root, cow, 1);
-	else
+		if (ret)
+			btrfs_abort_transaction(trans, ret);
+	} else {
 		ret = btrfs_inc_ref(trans, root, cow, 0);
+		if (ret)
+			btrfs_abort_transaction(trans, ret);
+	}
 	if (ret) {
 		btrfs_tree_unlock(cow);
 		free_extent_buffer(cow);
-		btrfs_abort_transaction(trans, ret);
 		return ret;
 	}
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()
  2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
  2025-05-19 10:42 ` [PATCH 1/2] btrfs: unfold transaction abort at btrfs_copy_root() fdmanana
@ 2025-05-19 10:42 ` fdmanana
  2025-05-27 11:01 ` [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() Daniel Vacek
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: fdmanana @ 2025-05-19 10:42 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

If we find an unexpected generation for the extent buffer we are cloning
at btrfs_copy_root(), we just WARN_ON() and don't error out and abort the
transaction, meaning we allow to persist metadata with an unexpected
generation. Instead of warning only, abort the transaction and return
-EUCLEAN.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/ctree.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index ae6cd77282f5..a5ee6ce312cf 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -283,7 +283,14 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 
 	write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
 
-	WARN_ON(btrfs_header_generation(buf) > trans->transid);
+	if (unlikely(btrfs_header_generation(buf) > trans->transid)) {
+		btrfs_tree_unlock(cow);
+		free_extent_buffer(cow);
+		ret = -EUCLEAN;
+		btrfs_abort_transaction(trans, ret);
+		return ret;
+	}
+
 	if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		ret = btrfs_inc_ref(trans, root, cow, 1);
 		if (ret)
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root()
  2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
  2025-05-19 10:42 ` [PATCH 1/2] btrfs: unfold transaction abort at btrfs_copy_root() fdmanana
  2025-05-19 10:42 ` [PATCH 2/2] btrfs: abort transaction on unexpected eb generation " fdmanana
@ 2025-05-27 11:01 ` Daniel Vacek
  2025-05-27 22:27 ` Qu Wenruo
  2025-05-28 13:51 ` David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: Daniel Vacek @ 2025-05-27 11:01 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Mon, 19 May 2025 at 12:42, <fdmanana@kernel.org> wrote:
>
> From: Filipe Manana <fdmanana@suse.com>
>
> A couple simple cleanups, details in the change logs.
>
> Filipe Manana (2):
>   btrfs: unfold transaction abort at btrfs_copy_root()
>   btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()
>
>  fs/btrfs/ctree.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)

Looks good to me.

Reviewed-by: Daniel Vacek <neelx@suse.com>

> --
> 2.47.2
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root()
  2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
                   ` (2 preceding siblings ...)
  2025-05-27 11:01 ` [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() Daniel Vacek
@ 2025-05-27 22:27 ` Qu Wenruo
  2025-05-28 13:51 ` David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: Qu Wenruo @ 2025-05-27 22:27 UTC (permalink / raw)
  To: fdmanana, linux-btrfs



在 2025/5/19 20:12, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
> 
> A couple simple cleanups, details in the change logs.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> 
> Filipe Manana (2):
>    btrfs: unfold transaction abort at btrfs_copy_root()
>    btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()
> 
>   fs/btrfs/ctree.c | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root()
  2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
                   ` (3 preceding siblings ...)
  2025-05-27 22:27 ` Qu Wenruo
@ 2025-05-28 13:51 ` David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2025-05-28 13:51 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Mon, May 19, 2025 at 11:42:03AM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> A couple simple cleanups, details in the change logs.
> 
> Filipe Manana (2):
>   btrfs: unfold transaction abort at btrfs_copy_root()
>   btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()

Reviewed-by: David Sterba <dsterba@suse.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-28 13:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-19 10:42 [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() fdmanana
2025-05-19 10:42 ` [PATCH 1/2] btrfs: unfold transaction abort at btrfs_copy_root() fdmanana
2025-05-19 10:42 ` [PATCH 2/2] btrfs: abort transaction on unexpected eb generation " fdmanana
2025-05-27 11:01 ` [PATCH 0/2] btrfs: some cleanups for btrfs_copy_root() Daniel Vacek
2025-05-27 22:27 ` Qu Wenruo
2025-05-28 13:51 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox