linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zonefs: add sanity check for aggregated conventional zones
@ 2022-11-03 10:32 Johannes Thumshirn
  2022-11-04  0:26 ` Damien Le Moal
  2022-11-07  7:58 ` Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2022-11-03 10:32 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: linux-fsdevel, Johannes Thumshirn

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@wdc.com>
---
 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;
+		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;
 		}
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-07  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-03 10:32 [PATCH] zonefs: add sanity check for aggregated conventional zones Johannes Thumshirn
2022-11-04  0:26 ` Damien Le Moal
2022-11-04  9:47   ` Johannes Thumshirn
2022-11-04 12:06     ` Damien Le Moal
2022-11-04 12:36       ` Johannes Thumshirn
2022-11-07  7:58 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).