[PATCH] btrfs: zoned: use alloc_list instead of rcu locked device_list

Johannes Thumshirn
2022-03-14T14:16:56Z

Anand pointed out, that instead of using the rcu locked version of
fs_devices->device_list we cab use fs_devices->alloc_list, prrotected by
the chunk_mutex to traverse the list of active deviices in
btrfs_can_activate_zone().

Suggested-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/zoned.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 49446bb5a5d1..7da630ff5708 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1975,15 +1975,16 @@ int btrfs_zone_finish(struct btrfs_block_group *block_group)

bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
{
+ struct btrfs_fs_info *fs_info = fs_devices->fs_info;
struct btrfs_device *device;
bool ret = false;

- if (!btrfs_is_zoned(fs_devices->fs_info))
+ if (!btrfs_is_zoned(fs_info))
return true;

/* Check if there is a device with active zones left */
- rcu_read_lock();
- list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) {
+ mutex_lock(&fs_info->chunk_mutex);
+ list_for_each_entry(device, &fs_devices->alloc_list, dev_list) {
struct btrfs_zoned_device_info *zinfo = device->zone_info;

if (!device->bdev)
@@ -1995,7 +1996,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
break;
}
}
- rcu_read_unlock();
+ mutex_unlock(&fs_info->chunk_mutex);

return ret;
}
--
2.35.1