Re: [PATCH] zonefs: add sanity check for aggregated conventional zones

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/3/22 19:32, Johannes Thumshirn wrote:
> 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 an error in case this case happens and fail the mount.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>
> ---
>  fs/zonefs/super.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index 860f0b1032c6..605364638720 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -1407,6 +1407,14 @@ 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 (zi->i_zone_size > bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT &&
> +	    !sbi->s_features & ZONEFS_F_AGGRCNV) {
> +		zonefs_err(sb,
> +			   "zone size %llu doesn't match device's zone sectors %llu\n",
> +			   zi->i_zone_size,
> +			   bdev_zone_sectors(sb->s_bdev) << SECTOR_SHIFT);
> +		return -EINVAL;
> +	}
>  
>  	zi->i_max_size = min_t(loff_t, MAX_LFS_FILESIZE,
>  			       zone->capacity << SECTOR_SHIFT);
> @@ -1485,7 +1493,7 @@ static struct dentry *zonefs_create_inode(struct dentry *parent,
>  dput:
>  	dput(dentry);
>  
> -	return NULL;
> +	return ERR_PTR(ret);
>  }
>  
>  struct zonefs_zone_data {
> @@ -1505,7 +1513,7 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd,
>  	struct blk_zone *zone, *next, *end;
>  	const char *zgroup_name;
>  	char *file_name;
> -	struct dentry *dir;
> +	struct dentry *dir, *ret2;
>  	unsigned int n = 0;
>  	int ret;
>  
> @@ -1523,8 +1531,11 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd,
>  		zgroup_name = "seq";
>  
>  	dir = zonefs_create_inode(sb->s_root, zgroup_name, NULL, type);
> -	if (!dir) {
> -		ret = -ENOMEM;
> +	if (IS_ERR_OR_NULL(dir)) {
> +		if (!dir)
> +			ret = -ENOMEM;

It would be cleaner to return ERR_PTR(-ENOMEM) instead of NULL in
zonefs_create_inode(). This way, this can simply be:
		if (IS_ERR(dir)) {
			ret = PTR_ERR(dir);
			goto free;
		}

And the hunk below would be similar too.

> +		else
> +			ret = PTR_ERR(dir);
>  		goto free;
>  	}
>  
> @@ -1570,8 +1581,12 @@ static int zonefs_create_zgroup(struct zonefs_zone_data *zd,
>  		 * Use the file number within its group as file name.
>  		 */
>  		snprintf(file_name, ZONEFS_NAME_MAX - 1, "%u", n);
> -		if (!zonefs_create_inode(dir, file_name, zone, type)) {
> -			ret = -ENOMEM;
> +		ret2 = zonefs_create_inode(dir, file_name, zone, type);
> +		if (IS_ERR_OR_NULL(ret2)) {
> +			if (!ret2)
> +				ret = -ENOMEM;
> +			else
> +				ret = PTR_ERR(ret2);
>  			goto free;
>  		}
>  

-- 
Damien Le Moal
Western Digital Research




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux