diff mbox series

btrfs: zoned: calculate max_extent_size properly on non-zoned setup

Message ID 20241213064343.1498094-1-hch@lst.de (mailing list archive)
State New
Headers show
Series btrfs: zoned: calculate max_extent_size properly on non-zoned setup | expand

Commit Message

Christoph Hellwig Dec. 13, 2024, 6:43 a.m. UTC
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 <naohiro.aota@wdc.com>, from which
much of this commit message is stolen as well.

Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fixes: 559218d43ec9 ("block: pre-calculate max_zone_append_sectors")
Tested-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/zoned.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn Dec. 13, 2024, 7:28 a.m. UTC | #1
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Naohiro Aota Dec. 13, 2024, 2:56 p.m. UTC | #2
On Fri, Dec 13, 2024 at 07:43:43AM +0100, Christoph Hellwig wrote:
> 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 <naohiro.aota@wdc.com>, from which
> much of this commit message is stolen as well.
> 
> Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Fixes: 559218d43ec9 ("block: pre-calculate max_zone_append_sectors")
> Tested-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/btrfs/zoned.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 11ed523e528e..27f4472fb559 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -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