Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@meta.com>
To: <dsterba@suse.com>, <cem@kernel.org>,
	<linux-btrfs@vger.kernel.org>, <linux-xfs@vger.kernel.org>,
	<hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>, Chris Mason <clm@fb.com>
Subject: [PATCH 2/2] btrfs: handle bio split errors for append
Date: Mon, 20 Oct 2025 07:43:56 -0700	[thread overview]
Message-ID: <20251020144356.693288-2-kbusch@meta.com> (raw)
In-Reply-To: <20251020144356.693288-1-kbusch@meta.com>

From: Keith Busch <kbusch@kernel.org>

bio_split_rw_at may return a negative error value if the bio can not be
split into anything that adheres to the block device's queue limits.
Check for that condition and fail the bio accordingly.

Reported-by: Chris Mason <clm@fb.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 fs/btrfs/bio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 21df48e6c4fa2..0ca86526a8bd8 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -646,6 +646,8 @@ static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length)
 	sector_offset = bio_split_rw_at(&bbio->bio, &bbio->fs_info->limits,
 					&nr_segs, map_length);
 	if (sector_offset) {
+		if (unlikely(sector_offset < 0))
+			return sector_offset;
 		/*
 		 * bio_split_rw_at() could split at a size smaller than our
 		 * sectorsize and thus cause unaligned I/Os.  Fix that by
@@ -685,8 +687,14 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num)
 	}
 
 	map_length = min(map_length, length);
-	if (use_append)
+	if (use_append) {
 		map_length = btrfs_append_map_length(bbio, map_length);
+		if (IS_ERR_VALUE(map_length)) {
+			status = errno_to_blk_status(map_length);
+			btrfs_bio_counter_dec(fs_info);
+			goto end_bbio;
+		}
+	}
 
 	if (map_length < length) {
 		struct btrfs_bio *split;
-- 
2.47.3


  reply	other threads:[~2025-10-20 14:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 14:43 [PATCH 1/2] xfs: handle bio split errors during gc Keith Busch
2025-10-20 14:43 ` Keith Busch [this message]
2025-10-21 21:03   ` [PATCH 2/2] btrfs: handle bio split errors for append kernel test robot
2025-10-20 14:45 ` [PATCH 1/2] xfs: handle bio split errors during gc Christoph Hellwig
2025-10-20 14:54   ` Keith Busch
2025-10-20 14:57     ` Christoph Hellwig
2025-10-20 15:05       ` Keith Busch
2025-10-20 15:16       ` Chris Mason
2025-10-21  5:28         ` Christoph Hellwig

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=20251020144356.693288-2-kbusch@meta.com \
    --to=kbusch@meta.com \
    --cc=cem@kernel.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-xfs@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