btrfs: zoned: fix zone management on degraded filesystems
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
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.
--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/zoned.c +3 -0
@@ -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
PATCH 2/2 btrfs: zoned: fix zone finishing with missing devices
In reply to Johannes ThumshirnFrom: 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.
--- fs/btrfs/zoned.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/zoned.c +3 -0
@@ -2274,6 +2274,9 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writstruct 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
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_infopointer 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 devicesfs/btrfs/zoned.c | 6 ++++++ 1 file changed, 6 insertions(+)
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_infopointer 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 devicesfs/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