btrfs: zoned: calculate max_extent_size properly on non-zoned setup
PATCH 1/1 btrfs: zoned: calculate max_extent_size properly on non-zoned setup
Since commit 559218d43ec9 ("block: pre-calculate max_zone_append_sectors"), queue_limits's max_zone_append_sectors is default to be 0 and it is only updated when there is a zoned device. So, we have lim->max_zone_append_sectors = 0 when there is no zoned device in the filesystem.
That leads to fs_info->max_zone_append_size and thus fs_info->max_extent_size to be 0, which is wrong and can for example lead to a divide by zero in count_max_extents().
Fix this by only capping fs_info->max_extent_size to fs_info->max_zone_append_size when it is non-zero.
Based on a patch from Naohiro Aota <[email protected]>, from which much of this commit message is stolen as well.
--- fs/btrfs/zoned.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/btrfs/zoned.c +3 -2
@@ -748,8 +748,9 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info) (u64)lim->max_segments << PAGE_SHIFT), fs_info->sectorsize); fs_info->fs_devices->chunk_alloc_policy =BTRFS_CHUNK_ALLOC_ZONED ; -if (fs_info->max_zone_append_size < fs_info->max_extent_size) - fs_info->max_extent_size = fs_info->max_zone_append_size; + + fs_info->max_extent_size =min_not_zero (fs_info->max_extent_size, + fs_info->max_zone_append_size);/* * Check mount options here, because we might change fs_info->zoned
Signature · 1 line
2.45.2
Quoted 16 lines · Christoph Hellwig
Since commit
559218d43ec9("block: pre-calculatemax_zone_append_sectors"), queue_limits'smax_zone_append_sectorsis default to be 0 and it is only updated when there is a zoned device. So, we havelim->max_zone_append_sectors= 0 when there is no zoned device in the filesystem.That leads to
fs_info->max_zone_append_sizeand thusfs_info->max_extent_sizeto be 0, which is wrong and can for example lead to a divide by zero incount_max_extents().Fix this by only capping
fs_info->max_extent_sizetofs_info->max_zone_append_sizewhen it is non-zero.Based on a patch from Naohiro Aota <[email protected]>, from which much of this commit message is stolen as well.
Quoted 7 lines
Reported-by Shinichiro Kawasaki <[email protected]>Fixes 559218d43ec9 ("block: pre-calculate max_zone_append_sectors")Tested-by Shinichiro Kawasaki <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- fs/btrfs/zoned.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines · Christoph Hellwig
Since commit
559218d43ec9("block: pre-calculatemax_zone_append_sectors"), queue_limits'smax_zone_append_sectorsis default to be 0 and it is only updated when there is a zoned device. So, we havelim->max_zone_append_sectors= 0 when there is no zoned device in the filesystem.That leads to
fs_info->max_zone_append_sizeand thusfs_info->max_extent_sizeto be 0, which is wrong and can for example lead to a divide by zero incount_max_extents().Fix this by only capping
fs_info->max_extent_sizetofs_info->max_zone_append_sizewhen it is non-zero.
Quoted 7 lines
Based on a patch from Naohiro Aota <[email protected]>, from which much of this commit message is stolen as well.
Reported-by Shinichiro Kawasaki <[email protected]>Fixes 559218d43ec9 ("block: pre-calculate max_zone_append_sectors")Tested-by Shinichiro Kawasaki <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Added to for-next, thanks.