mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miroslav Cimerman <mc@raidlab.org>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
	Naohiro Aota <naohiro.aota@wdc.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] btrfs: zoned: take the RAID1 zone capacity from a present stripe
Date: Thu, 19 Nov 2026 21:38:34 +0000	[thread overview]
Message-ID: <20261119213835.103131-4-mc@raidlab.org> (raw)
In-Reply-To: <20261119213835.103131-1-mc@raidlab.org>

btrfs_load_block_group_raid1() takes the zone capacity of the block
group from stripes 0 and 1. A missing device has a capacity of 0, which
min_not_zero() skips, but a RAID1C3 or RAID1C4 block group with both
stripes missing gets a capacity of 0. Once it has been written to, it
fails to load, and a degraded mount fails although a copy is left:

  BTRFS error (device nb4): zoned: invalid write pointer 98304 (larger than zone capacity 0) in block group 83886080
  BTRFS error (device nb4): zoned: failed to load zone info of bg 83886080
  BTRFS error (device nb4): failed to read block groups: -EIO

In that case, take the smallest non-zero capacity of the other stripes.

Fixes: 568220fa9657 ("btrfs: zoned: support RAID0/1/10 on top of raid stripe tree")
CC: stable@vger.kernel.org # 6.7+
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
Found in an LLM review of the previous patches. The fix and the commit
message were prepared with the help of an LLM, which also tested it. I
reviewed everything.

Taking the smallest capacity of all stripes would also cover a third or
fourth stripe with a smaller capacity, but a block group written past
it would then fail to load, so it is not done here.

 fs/btrfs/zoned.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 8bd44dd260a4..5722e16a5432 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1535,6 +1535,12 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
 
 	/* In case a device is missing we have a cap of 0, so don't use it. */
 	bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity);
+	/* RAID1C3 and RAID1C4 can miss both of them, take the others then. */
+	if (!bg->zone_capacity) {
+		for (i = 2; i < map->num_stripes; i++)
+			bg->zone_capacity = min_not_zero(bg->zone_capacity,
+							 zone_info[i].capacity);
+	}
 
 	/*
 	 * When the last extent is removed, last_alloc can be smaller than the other write
-- 
2.53.0


  parent reply	other threads:[~2026-11-19 21:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 21:38 [PATCH 0/4] btrfs: zoned: RAID1 block groups with missing or stale stripes Miroslav Cimerman
2026-11-19 21:38 ` [PATCH 1/4] btrfs: zoned: take the RAID1 active state from the first present stripe Miroslav Cimerman
2026-11-19 21:38 ` [PATCH 2/4] btrfs: zoned: use the highest RAID1 write pointer on degraded mounts Miroslav Cimerman
2026-11-19 21:38 ` Miroslav Cimerman [this message]
2026-11-19 21:38 ` [PATCH 4/4] btrfs: tests: zoned: add degraded RAID1 cases Miroslav Cimerman

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=20261119213835.103131-4-mc@raidlab.org \
    --to=mc@raidlab.org \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=naohiro.aota@wdc.com \
    /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®