btrfs: zoned: set pseudo max append zone limit in zone emulation mode
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fri, 26 Aug 2022 07:42:15 +0000 (16:42 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 09:30:02 +0000 (11:30 +0200)
commit7da1afa444a19dec5ac49c2f8eae1838562a18f1
treee6298679696010e580ecdbbaa74317fd1e74601a
parent75082adeb414113ce1afa710c50f8dacdd8245b0
btrfs: zoned: set pseudo max append zone limit in zone emulation mode

commit cac5c44c48c9fb9cc31bea15ebd9ef0c6462314f upstream.

The commit 7d7672bc5d10 ("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 c2ae7b772ef4 ("btrfs: zoned: revive
max_zone_append_bytes").

Fixes: 7d7672bc5d10 ("btrfs: convert count_max_extents() to use fs_info->max_extent_size")
CC: stable@vger.kernel.org # 5.12+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/zoned.c