btrfs: zoned: two independent fixes for zoned btrfs
cover btrfs: zoned: two independent fixes for zoned btrfs
Two small and independent fixes for problems found while debugging other issues on zoned btrfs.
The first one is a possible deadlock and the second one is for removing leftover ASSERT()s.
Johannes Thumshirn (2):
btrfs: zoned: use rcu list in btrfs_can_activate_zone
btrfs: zoned: remove left over ASSERT()
fs/btrfs/zoned.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/2 btrfs: zoned: use rcu list in btrfs_can_activate_zone
btrfs_can_activate_zone() can be called with the device_list_mutex already held, which will lead to a deadlock.
As we're only traversing the list for reads we can switch from the device_list_mutex to an rcu traversal of the list.
--- fs/btrfs/zoned.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/zoned.c +3 -3
@@ -1986,8 +1986,8 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)ASSERT ((flags &BTRFS_BLOCK_GROUP_PROFILE_MASK ) ==0 );/* Check if there is a device with active zones left */ -mutex_lock (&fs_devices->device_list_mutex); -list_for_each_entry (device, &fs_devices->devices, dev_list) { +rcu_read_lock (); +list_for_each_entry_rcu (device, &fs_devices->devices, dev_list) {struct btrfs_zoned_device_info *zinfo = device->zone_info;if (!device->bdev)
@@ -1999,7 +1999,7 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)break ; } } -mutex_unlock (&fs_devices->device_list_mutex); +rcu_read_unlock ();return ret; }
Signature · 1 line
2.35.1
PATCH 2/2 btrfs: zoned: remove left over ASSERT()
In reply to Johannes ThumshirnWith commit dcf5652291f6 ("btrfs: zoned: allow DUP on meta-data block groups") we started allowing DUP on meta-data block-groups, so the ASSERT()s in btrfs_can_activate_zone() and btrfs_zoned_get_device() are no longer valid and in fact even harmful.
--- fs/btrfs/zoned.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +32 -4
@@ -1801,7 +1801,6 @@ struct btrfs_device *btrfs_zoned_get_device(struct btrfs_fs_info *fs_info, map = em->map_lookup;/* We only support single profile for now */ -ASSERT (map->num_stripes ==1 ); device = map->stripes[0 ].dev;free_extent_map (em);
@@ -1982,9 +1981,6 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)if (!btrfs_is_zoned (fs_devices->fs_info))return true; -/* Non-single profiles are not supported yet */ -ASSERT ((flags &BTRFS_BLOCK_GROUP_PROFILE_MASK ) ==0 ); -/* Check if there is a device with active zones left */ rcu_read_lock ();list_for_each_entry_rcu (device, &fs_devices->devices, dev_list) {
@@ -2055,6 +2051,38 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 lenbtrfs_put_block_group (block_group); } +static void btrfs_zone_finish_endio_workfn (struct work_struct *work) +{ +struct btrfs_block_group *bg = + container_of(work, struct btrfs_block_group, zone_finish_work); + +wait_on_extent_buffer_writeback (bg->last_eb); +free_extent_buffer (bg->last_eb); +btrfs_zone_finish_endio (bg->fs_info, bg->start, bg->length); +btrfs_put_block_group (bg); +} + +void btrfs_schedule_zone_finish_bg (struct btrfs_block_group *bg, +struct extent_buffer *eb) +{ +if (!bg->seq_zone || + eb->start + eb->len *2 <= bg->start + bg->zone_capacity) +return ; + +if (WARN_ON (bg->zone_finish_work.func == + btrfs_zone_finish_endio_workfn)) { +pr_info ("double scheduling BG %llu\n" , bg->start); +return ; + } + +/* For the work */ +btrfs_get_block_group (bg); +atomic_inc (&eb->refs); + bg->last_eb = eb; +INIT_WORK (&bg->zone_finish_work, btrfs_zone_finish_endio_workfn); +queue_work (system_unbound_wq, &bg->zone_finish_work); +} +void btrfs_clear_data_reloc_bg (struct btrfs_block_group *bg) {struct btrfs_fs_info *fs_info = bg->fs_info;
Signature · 1 line
2.35.1
Quoted 6 lines · Johannes Thumshirn
Two small and independent fixes for problems found while debugging other issues on zoned btrfs.
The first one is a possible deadlock and the second one is for removing leftover ASSERT()s.
Quoted 7 lines
Johannes Thumshirn (2):
btrfs: zoned: use rcu list inbtrfs_can_activate_zone
btrfs: zoned: remove left overASSERT()fs/btrfs/zoned.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
Please disregard, the 2nd patch contains changes not belonging there.