The Linux Kernel Mailing List
 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 1/4] btrfs: zoned: take the RAID1 active state from the first present stripe
Date: Thu, 19 Nov 2026 21:38:32 +0000	[thread overview]
Message-ID: <20261119213835.103131-2-mc@raidlab.org> (raw)
In-Reply-To: <20261119213835.103131-1-mc@raidlab.org>

btrfs_load_block_group_raid1() compares the active state of each
present stripe's zone with stripe 0's. A missing device has no active
zones, so with stripe 0 missing, an active zone of a present stripe
always mismatches, and a degraded mount neither activates the block
group nor marks it active. It is then not on the list of active block
groups, while its zones are active and count against their devices'
active zone limits.

If it is a data block group, writing data to it tries to activate it,
which fails when the active zones left are reserved for metadata. With
no other data block group with room left, the allocation then returns
-EAGAIN, and the write waits for a zone finish forever:

  task:dd              state:D
   btrfs_new_extent_direct
   btrfs_dio_iomap_next
   iomap_iter
   __iomap_dio_rw
   btrfs_direct_write
   btrfs_do_write_iter
   vfs_write

If it is a metadata block group, writing tree blocks to it activates it
with a warning:

  WARNING: fs/btrfs/zoned.c:2451 at btrfs_zone_activate+0x72a/0xa60, CPU#1: btrfs/157
   btrfs_check_meta_write_pointer
   write_meta_extent_buffer
   btree_writepages

Compare with the first present stripe instead.

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 by an LLM while testing the next patch. The fix and the commit
message were prepared with the help of an LLM, which also tested it. I
reviewed everything.

A mismatch between present stripes, like a stripe behind the others on
a degraded mount, is not changed. Depending on which stripe comes
first, the block group is marked active at load without the zone of the
other stripe accounted, or activated at its first write if it has room
left, which can fail as above when no active zone is left. Both happened
before too. I can look at the active zone accounting for these zones
separately.

btrfs_load_block_group_raid10() compares the active state with stripe
0's too, but activates the block group on a mismatch instead of
skipping it. With stripe 0 missing, that warns at mount for a metadata
block group, and can fail the mount for a data block group when no
active zone is left. RAID10 also adds a zone capacity of 0 for a
missing first stripe of a pair, which fails the degraded mount once a
block group holds more than the capacity that is left. Neither is
changed in this series. I will send fixes for both.

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

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e6ce6f05ad75..8eac6e2283a2 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1522,6 +1522,7 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
 					u64 last_alloc)
 {
 	struct btrfs_fs_info *fs_info = bg->fs_info;
+	int first = -1;
 	int i;
 
 	if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) {
@@ -1555,6 +1556,9 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
 		if (zone_info[i].alloc_offset == WP_CONVENTIONAL)
 			zone_info[i].alloc_offset = last_alloc;
 
+		if (first < 0)
+			first = i;
+
 		if (unlikely((zone_info[0].alloc_offset != zone_info[i].alloc_offset) &&
 			     !btrfs_test_opt(fs_info, DEGRADED))) {
 			btrfs_err(fs_info,
@@ -1562,13 +1566,13 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
 				  btrfs_bg_type_to_raid_name(map->type));
 			return -EIO;
 		}
-		if (test_bit(0, active) != test_bit(i, active)) {
+		if (test_bit(first, active) != test_bit(i, active)) {
 			if (unlikely(!btrfs_test_opt(fs_info, DEGRADED) &&
 				     !btrfs_zone_activate(bg))) {
 				return -EIO;
 			}
 		} else {
-			if (test_bit(0, active))
+			if (test_bit(first, active))
 				set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &bg->runtime_flags);
 		}
 	}
-- 
2.53.0


  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 ` Miroslav Cimerman [this message]
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 ` [PATCH 3/4] btrfs: zoned: take the RAID1 zone capacity from a present stripe Miroslav Cimerman
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-2-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