mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yangtao Li <frank.li@vivo.com>
To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yangtao Li <frank.li@vivo.com>
Subject: [PATCH 3/4] btrfs: Fix transaction abort during failure in insert_balance_item()
Date: Tue,  8 Apr 2025 06:29:32 -0600	[thread overview]
Message-ID: <20250408122933.121056-3-frank.li@vivo.com> (raw)
In-Reply-To: <20250408122933.121056-1-frank.li@vivo.com>

Handle insert_empty_item errors by adding explicit
btrfs_abort_transaction/btrfs_end_transaction calls.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/btrfs/volumes.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 375d92720e17..347c475028e0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3733,7 +3733,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
 	BTRFS_PATH_AUTO_FREE(path);
 	struct extent_buffer *leaf;
 	struct btrfs_key key;
-	int ret, err;
+	int ret;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -3749,8 +3749,11 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
 
 	ret = btrfs_insert_empty_item(trans, root, path, &key,
 				      sizeof(*item));
-	if (ret)
-		goto out;
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		btrfs_end_transaction(trans);
+		return ret;
+	}
 
 	leaf = path->nodes[0];
 	item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
@@ -3764,11 +3767,8 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
 	btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
 	btrfs_set_balance_sys(leaf, item, &disk_bargs);
 	btrfs_set_balance_flags(leaf, item, bctl->flags);
-out:
-	err = btrfs_commit_transaction(trans);
-	if (err && !ret)
-		ret = err;
-	return ret;
+
+	return btrfs_commit_transaction(trans);
 }
 
 static int del_balance_item(struct btrfs_fs_info *fs_info)
-- 
2.39.0


  parent reply	other threads:[~2025-04-08 12:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-08 12:29 [PATCH 1/4] btrfs: use BTRFS_PATH_AUTO_FREE " Yangtao Li
2025-04-08 12:29 ` [PATCH 2/4] btrfs: use BTRFS_PATH_AUTO_FREE in del_balance_item() Yangtao Li
2025-04-08 14:47   ` Filipe Manana
2025-04-08 12:29 ` Yangtao Li [this message]
2025-04-08 14:50   ` [PATCH 3/4] btrfs: Fix transaction abort during failure in insert_balance_item() Filipe Manana
2025-04-08 12:29 ` [PATCH 4/4] btrfs: Fix transaction abort during failure in del_balance_item() Yangtao Li
2025-04-08 14:53   ` Filipe Manana
2025-04-08 23:04     ` David Sterba
2025-04-09  9:50       ` Filipe Manana
2025-04-08 14:44 ` [PATCH 1/4] btrfs: use BTRFS_PATH_AUTO_FREE in insert_balance_item() Filipe Manana
2025-04-08 17:36   ` Daniel Vacek
2025-04-08 17:40     ` Filipe Manana
2025-04-08 17:47       ` Daniel Vacek
2025-04-08 17:52         ` Filipe Manana
2025-04-08 18:00           ` Daniel Vacek
2025-04-09 12:19   ` 回复: " 李扬韬
2025-04-08 22:47 ` David Sterba
2025-04-09  9:45   ` Filipe Manana

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=20250408122933.121056-3-frank.li@vivo.com \
    --to=frank.li@vivo.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®