zonefs: fix zone report size in __zonefs_io_error()
authorDamien Le Moal <damien.lemoal@opensource.wdc.com>
Tue, 25 Oct 2022 04:39:31 +0000 (13:39 +0900)
committerDamien Le Moal <damien.lemoal@opensource.wdc.com>
Wed, 16 Nov 2022 07:08:28 +0000 (16:08 +0900)
commit7dd12d65ac646046a3fe0bbf9a4e86f4514207b3
tree87bdb6b3eb3647d8595274785f59b74f04dd8519
parent094226ad94f471a9f19e8f8e7140a09c2625abaa
zonefs: fix zone report size in __zonefs_io_error()

When an IO error occurs, the function __zonefs_io_error() is used to
issue a zone report to obtain the latest zone information from the
device. This function gets a zone report for all zones used as storage
for a file, which is always 1 zone except for files representing
aggregated conventional zones.

The number of zones of a zone report for a file is calculated in
__zonefs_io_error() by doing a bit-shift of the inode i_zone_size field,
which is equal to or larger than the device zone size. However, this
calculation does not take into account that the last zone of a zoned
device may be smaller than the zone size reported by bdev_zone_sectors()
(which is used to set the bit shift size). As a result, if an error
occurs for an IO targetting such last smaller zone, the zone report will
ask for 0 zones, leading to an invalid zone report.

Fix this by using the fact that all files require a 1 zone report,
except if the inode i_zone_size field indicates a zone size larger than
the device zone size. This exception case corresponds to a mount with
aggregated conventional zones.

A check for this exception is added to the file inode initialization
during mount. If an invalid setup is detected, emit an error and fail
the mount (check contributed by Johannes Thumshirn).

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
fs/zonefs/super.c