Skip to contentSkip to conversation

btrfs: zoned: fix zone management on degraded filesystems

PATCH In review Johannes Thumshirn 3 participants 5 messages Mar 17, 2025 – Mar 18, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: zoned: fix zone management on degraded filesystems

Two fixes around ZONE FINISH and ZONE ACTIVATE for multi device filesystems in degraded mode.

Both times we're dereferencing the btrfs_device::zone_info pointer without prior checking if the device is present.

Johannes Thumshirn (2):
btrfs: zoned: fix zone activation with missing devices
btrfs: zoned: fix zone finishing with missing devices

 fs/btrfs/zoned.c | 6 ++++++
 1 file changed, 6 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 btrfs: zoned: fix zone activation with missing devices

From: Johannes Thumshirn <[email protected]>

If btrfs_zone_activate() is called with a filesystem that has missing devices (e.g. a RAID file system mounted in degraded mode) it is accessing the btrfs_device::zone_info pointer, which will not be set if the device in question is missing.

Check if the device is present (by checking if it has a valid block device pointer associated) and if not, skip zone activation for it.

Fixes f9a912a3c45f ("btrfs: zoned: make zone activation multi stripe capable")
---
 fs/btrfs/zoned.c | 3 +++
 1 file changed, 3 insertions(+)
fs/btrfs/zoned.c +3 -0
index c21a97b32f9a..8924f58919e8 100644
@@ -2110,6 +2110,9 @@ bool btrfs_zone_activate(struct btrfs_block_group *block_group)
 		physical = map->stripes[i].physical;
 		zinfo = device->zone_info;
 
+		if (!device->bdev)
+			continue;
+
 		if (zinfo->max_active_zones == 0)
 			continue;
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 btrfs: zoned: fix zone finishing with missing devices

In reply to Johannes Thumshirn

From: Johannes Thumshirn <[email protected]>

If do_zone_finish() is called with a filesystem that has missing devices (e.g. a RAID file system mounted in degraded mode) it is accessing the btrfs_device::zone_info pointer, which will not be set if the device in question is missing.

Check if the device is present (by checking if it has a valid block device pointer associated) and if not, skip zone finishing for it.

Fixes 4dcbb8ab31c1 ("btrfs: zoned: make zone finishing multi stripe capable")
---
 fs/btrfs/zoned.c | 3 +++
 1 file changed, 3 insertions(+)
fs/btrfs/zoned.c +3 -0
index 8924f58919e8..7c502192cd6b 100644
@@ -2274,6 +2274,9 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
 		struct btrfs_zoned_device_info *zinfo = device->zone_info;
 		unsigned int nofs_flags;
 
+		if (!device->bdev)
+			continue;
+
 		if (zinfo->max_active_zones == 0)
 			continue;
 
Signature · 1 line
2.43.0
Reviewed-by on the v1 series
#3 lore raw
In reply to Johannes Thumshirn
Quoted 5 lines · Johannes Thumshirn

Two fixes around ZONE FINISH and ZONE ACTIVATE for multi device filesystems in degraded mode.

Both times we're dereferencing the btrfs_device::zone_info pointer without prior checking if the device is present.

At first, I thought, we should not write into a block group containing a missing device. But, yeah, in the degraded mode, we are allowed to make un-synced writing.

So, for the series

Quoted 7 lines

Johannes Thumshirn (2):
btrfs: zoned: fix zone activation with missing devices
btrfs: zoned: fix zone finishing with missing devices

 fs/btrfs/zoned.c | 6 ++++++
 1 file changed, 6 insertions(+)
Reviewed-by on the v1 series
#4 lore raw
In reply to Johannes Thumshirn
Quoted 6 lines · Johannes Thumshirn

Two fixes around ZONE FINISH and ZONE ACTIVATE for multi device filesystems in degraded mode.

Both times we're dereferencing the btrfs_device::zone_info pointer without prior checking if the device is present.

Quoted 7 lines

Johannes Thumshirn (2):
btrfs: zoned: fix zone activation with missing devices
btrfs: zoned: fix zone finishing with missing devices

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

Looks good for now.

PS:
We have been using either of these methods to identify the missing device.

test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)

or

device->bdev == NULL

IMO, it's a good idea to consolidate to the BTRFS_DEV_STATE_MISSING flag. I have some incomplete patches for that. Also, I think we should discuss how to handle reappearing devices;

Thanks, Anand