Skip to content

Commit cac5c44

Browse files
kawasakikdave
authored andcommitted
btrfs: zoned: set pseudo max append zone limit in zone emulation mode
The commit 7d7672b ("btrfs: convert count_max_extents() to use fs_info->max_extent_size") introduced a division by fs_info->max_extent_size. This max_extent_size is initialized with max zone append limit size of the device btrfs runs on. However, in zone emulation mode, the device is not zoned then its zone append limit is zero. This resulted in zero value of fs_info->max_extent_size and caused zero division error. Fix the error by setting non-zero pseudo value to max append zone limit in zone emulation mode. Set the pseudo value based on max_segments as suggested in the commit c2ae7b7 ("btrfs: zoned: revive max_zone_append_bytes"). Fixes: 7d7672b ("btrfs: convert count_max_extents() to use fs_info->max_extent_size") CC: [email protected] # 5.12+ Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Naohiro Aota <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d5b81ce commit cac5c44

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/btrfs/zoned.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,19 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
421421
* since btrfs adds the pages one by one to a bio, and btrfs cannot
422422
* increase the metadata reservation even if it increases the number of
423423
* extents, it is safe to stick with the limit.
424+
*
425+
* With the zoned emulation, we can have non-zoned device on the zoned
426+
* mode. In this case, we don't have a valid max zone append size. So,
427+
* use max_segments * PAGE_SIZE as the pseudo max_zone_append_size.
424428
*/
425-
zone_info->max_zone_append_size =
426-
min_t(u64, (u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
427-
(u64)bdev_max_segments(bdev) << PAGE_SHIFT);
429+
if (bdev_is_zoned(bdev)) {
430+
zone_info->max_zone_append_size = min_t(u64,
431+
(u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
432+
(u64)bdev_max_segments(bdev) << PAGE_SHIFT);
433+
} else {
434+
zone_info->max_zone_append_size =
435+
(u64)bdev_max_segments(bdev) << PAGE_SHIFT;
436+
}
428437
if (!IS_ALIGNED(nr_sectors, zone_sectors))
429438
zone_info->nr_zones++;
430439

0 commit comments

Comments
 (0)