zonefs fixes
Subsystems (2)
cover zonefs fixes
The first patch fixes a bug with the execution of zone report after an IO error. The second patch removes unused code (not technically a bug but this removes a warning when compiling with clang).
Damien Le Moal (2):
zonefs: fix zone report size in __zonefs_io_error()
zonefs: Remove to_attr() helper function
fs/zonefs/super.c | 12 ++++++++++-- fs/zonefs/sysfs.c | 5 ----- 2 files changed, 10 insertions(+), 7 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/2 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 aggregated conventional zone files.
--- fs/zonefs/super.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/zonefs/super.c +10 -2
@@ -478,14 +478,22 @@ static void __zonefs_io_error(struct inode *inode, bool write)struct super_block *sb = inode->i_sb;struct zonefs_sb_info *sbi =ZONEFS_SB (sb);unsigned int noio_flag; -unsigned int nr_zones = - zi->i_zone_size >> (sbi->s_zone_sectors_shift +SECTOR_SHIFT ); +unsigned int nr_zones =1 ;struct zonefs_ioerr_data err = { .inode = inode, .write = write, };int ret; +/* +* The only files that have more than one zone are conventional zone +* files with aggregated conventional zones, for which the inode zone +* size is always larger than the device zone size. +*/ +if (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift +SECTOR_SHIFT ); +/* * Memory allocations in blkdev_report_zones() can trigger a memory * reclaim which may in turn cause a recursion into zonefs as well as
Signature · 1 line
2.38.1
Re: [PATCH 1/2] zonefs: fix zone report size in __zonefs_io_error()
fs/zonefs/super.c static void __zonefs_io_error(struct inode *inode, bool write) · line 496
Quoted 9 lines · Damien Le Moal
fs/zonefs/super.c +9
-0+/* +* The only files that have more than one zone are conventional zone +* files with aggregated conventional zones, for which the inode zone +* size is always larger than the device zone size. +*/ +if (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift +SECTOR_SHIFT ); +
I wonder if we should also have a check/assertion like this somewhere:
WARN_ON_ONCE(zi->i_zone_size > bdev_zone_sectors(sb->sbdev) &&
!sbi->s_features & ZONEFS_F_AGGRCNV)
Re: [PATCH 1/2] zonefs: fix zone report size in __zonefs_io_error()
Quoted 13 lines · Johannes Thumshirn
fs/zonefs/super.c static void __zonefs_io_error(struct inode *inode, bool write) · line 496
Quoted 9 lines · Damien Le Moal
fs/zonefs/super.c +9
-0+/* +* The only files that have more than one zone are conventional zone +* files with aggregated conventional zones, for which the inode zone +* size is always larger than the device zone size. +*/ +if (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift +SECTOR_SHIFT ); +I wonder if we should also have a check/assertion like this somewhere:
WARN_ON_ONCE(zi->i_zone_size >bdev_zone_sectors(sb->sbdev)&&
Quoted 1 line
!sbi->s_features & ZONEFS_F_AGGRCNV)
Well, this is set when the inode is created on mount. So we could add the check there, but I do not really see the point since we would be checking exactly what we are doing. So the only chance warn ever showing would be memory corruption, but then we'll likely have bigger problems anyway. No ?
Quoted 1 line
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 1/2] zonefs: fix zone report size in __zonefs_io_error()
Quoted 16 lines · Damien Le Moal
Quoted 13 lines · Johannes Thumshirn
Review
Quoted 9 lines · Damien Le Moal
(quoted diff) +9
-0+ /* + * The only files that have more than one zone are conventional zone + * files with aggregated conventional zones, for which the inode zone + * size is always larger than the device zone size. + */ + if (zi->i_zone_size > bdev_zone_sectors(sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift + SECTOR_SHIFT); +I wonder if we should also have a check/assertion like this somewhere:
WARN_ON_ONCE(zi->i_zone_size >bdev_zone_sectors(sb->sbdev)&&Quoted 1 line
!sbi->s_features & ZONEFS_F_AGGRCNV)
Quoted 4 lines
Well, this is set when the inode is created on mount. So we could add the check there, but I do not really see the point since we would be checking exactly what we are doing. So the only chance warn ever showing would be memory corruption, but then we'll likely have bigger problems anyway. No ?
Something like this:
From f90acf1ca3f84d37a3bdb570abf89e186697c0d4 Mon Sep 17 00:00:00 2001
Message-Id: <f90acf1ca3f84d37a3bdb570abf89e186697c0d4.1667383842.git.johannes.thumshirn@wdc.com>
From: Johannes Thumshirn <[email protected]>
Date: Wed, 2 Nov 2022 02:57:35 -0700
Subject: [PATCH] zonefs: add sanity check for aggregated conventional zones
When initializing a file inode, check if the zone's size if bigger than the number of device zone sectors. This can only be the case if we mount the filesystem with the -oaggr_cnv mount option.
Emit a warning if this case happens and we do not have the mount option set. Also if the -oerror=read-only mount option is set, mark the filesystem as read-only.
--- fs/zonefs/super.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/zonefs/super.c +9 -0
@@ -1407,6 +1407,15 @@ static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, zi->i_ztype = type; zi->i_zsector = zone->start; zi->i_zone_size = zone->len <<SECTOR_SHIFT ; +if (WARN_ON (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev) && + !sbi->s_features &ZONEFS_F_AGGRCNV )) { +if ((sbi->s_mount_opts &ZONEFS_MNTOPT_ERRORS_RO ) && + !sb_rdonly (sb)) { +zonefs_warn (sb,"remounting filesystem read-only\n" ); + sb->s_flags |=SB_RDONLY ; + } +return -EINVAL ; + } zi->i_max_size =min_t (loff_t,MAX_LFS_FILESIZE , zone->capacity <<SECTOR_SHIFT );
Signature · 1 line
2.37.3
Re: [PATCH 1/2] zonefs: fix zone report size in __zonefs_io_error()
Quoted 48 lines · Johannes Thumshirn
Quoted 16 lines · Damien Le Moal
Quoted 13 lines · Johannes Thumshirn
Review
Quoted 9 lines · Damien Le Moal
(quoted diff) +9
-0+ /* + * The only files that have more than one zone are conventional zone + * files with aggregated conventional zones, for which the inode zone + * size is always larger than the device zone size. + */ + if (zi->i_zone_size > bdev_zone_sectors(sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift + SECTOR_SHIFT); +I wonder if we should also have a check/assertion like this somewhere:
WARN_ON_ONCE(zi->i_zone_size >bdev_zone_sectors(sb->sbdev)&&Quoted 1 line
!sbi->s_features & ZONEFS_F_AGGRCNV)Quoted 4 lines
Well, this is set when the inode is created on mount. So we could add the check there, but I do not really see the point since we would be checking exactly what we are doing. So the only chance warn ever showing would be memory corruption, but then we'll likely have bigger problems anyway. No ?
Something like this:
From
f90acf1ca3f84d37a3bdb570abf89e186697c0d4Mon Sep 17 00:00:00 2001
Message-Id: <f90acf1ca3f84d37a3bdb570abf89e186697c0d4.1667383842.git.johannes.thumshirn@wdc.com>
From: Johannes Thumshirn <[email protected]>
Date: Wed, 2 Nov 2022 02:57:35 -0700
Subject: [PATCH] zonefs: add sanity check for aggregated conventional zonesWhen initializing a file inode, check if the zone's size if bigger than the number of device zone sectors. This can only be the case if we mount the filesystem with the -oaggr_cnv mount option.
Emit a warning if this case happens and we do not have the mount option set. Also if the -oerror=read-only mount option is set, mark the filesystem as read-only.
Signed-off-by Johannes Thumshirn <[email protected]>--- fs/zonefs/super.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/zonefs/super.c +0
-0
fs/zonefs/super.c static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, · line 1415
Quoted 9 lines
fs/zonefs/super.c +6
-0@@ -1407,6 +1407,15 @@ static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, zi->i_ztype = type; zi->i_zsector = zone->start; zi->i_zone_size = zone->len <<SECTOR_SHIFT ; +if (WARN_ON (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev) && + !sbi->s_features &ZONEFS_F_AGGRCNV )) { +if ((sbi->s_mount_opts &ZONEFS_MNTOPT_ERRORS_RO ) && + !sb_rdonly (sb)) { +zonefs_warn (sb,"remounting filesystem read-only\n" ); + sb->s_flags |=SB_RDONLY ;
This is during mount. So let's fail the mount...
Quoted 6 lines
fs/zonefs/super.c +3
-0+ } +return -EINVAL ; + } zi->i_max_size =min_t (loff_t,MAX_LFS_FILESIZE , zone->capacity <<SECTOR_SHIFT );
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 1/2] zonefs: fix zone report size in __zonefs_io_error()
In reply to Johannes ThumshirnQuoted 13 lines · Johannes Thumshirn
fs/zonefs/super.c static void __zonefs_io_error(struct inode *inode, bool write) · line 496
Quoted 9 lines · Damien Le Moal
fs/zonefs/super.c +9
-0+/* +* The only files that have more than one zone are conventional zone +* files with aggregated conventional zones, for which the inode zone +* size is always larger than the device zone size. +*/ +if (zi->i_zone_size >bdev_zone_sectors (sb->s_bdev)) + nr_zones = zi->i_zone_size >> + (sbi->s_zone_sectors_shift +SECTOR_SHIFT ); +I wonder if we should also have a check/assertion like this somewhere:
WARN_ON_ONCE(zi->i_zone_size >bdev_zone_sectors(sb->sbdev)&&
Quoted 2 lines
!sbi->s_features & ZONEFS_F_AGGRCNV)
I think It would be good to squash your patch checking zi->i_zone_size on mount with this one. Can you send that or do you want me to do it ?
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH 2/2 zonefs: Remove to_attr() helper function
In reply to Damien Le Moalto_attr() in zonefs sysfs code is unused. Remove this function code.
--- fs/zonefs/sysfs.c | 5 ----- 1 file changed, 5 deletions(-)
fs/zonefs/sysfs.c +0 -5
@@ -15,11 +15,6 @@ struct zonefs_sysfs_attr {ssize_t (*show)(struct zonefs_sb_info *sbi,char *buf); }; -static inline struct zonefs_sysfs_attr *to_attr (struct attribute *attr) -{ - return container_of(attr, struct zonefs_sysfs_attr, attr); -} -#define ZONEFS_SYSFS_ATTR_RO (name) \ static struct zonefs_sysfs_attr zonefs_sysfs_attr_##name = __ATTR_RO(name)
Signature · 1 line
2.38.1
Re: [PATCH 2/2] zonefs: Remove to_attr() helper function
Looks good,