Skip to contentSkip to conversation

mkfs: adjust_nr_zones for zoned file system on conventional devices

PATCH In review Christoph Hellwig 2 participants 3 messages Dec 18, 2025 – Dec 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs: adjust_nr_zones for zoned file system on conventional devices

When creating zoned file systems on conventional devices, mkfs doesn't currently align the RT device size to the zone size, which can create unmountable file systems. Fix this by moving the rgcount modification to account for reserved zoned and then calling adjust_nr_zones unconditionally, and thus ensuring that the rtblocks and rtextents values are guaranteed to always be a multiple of the zone size.

---
 mkfs/xfs_mkfs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
mkfs/xfs_mkfs.c +3 -5
index 8db51217016e..b34407725f76 100644
@@ -4558,8 +4558,6 @@ adjust_nr_zones(
 		max_zones = DTOBT(cli->xi->rt.size, cfg->blocklog) /
 				cfg->rgsize;
 
-	if (!cli->rgcount)
-		cfg->rgcount += XFS_RESERVED_ZONES;
 	if (cfg->rgcount > max_zones) {
 		fprintf(stderr,
 _("Warning: not enough zones (%lu/%u) for backing requested rt size due to\n"
@@ -4652,9 +4650,9 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"),
 		}
 	}
 
-	if (cli->rtsize || cli->rgcount)
-		adjust_nr_zones(cfg, cli, zt);
-
+	if (cli->rtsize)
+		cfg->rgcount += XFS_RESERVED_ZONES;
+	adjust_nr_zones(cfg, cli, zt);
 	if (cfg->rgcount < XFS_MIN_ZONES)  {
 		fprintf(stderr,
 _("realtime group count (%llu) must be greater than the minimum zone count (%u)\n"),
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · Christoph Hellwig

When creating zoned file systems on conventional devices, mkfs doesn't currently align the RT device size to the zone size, which can create unmountable file systems. Fix this by moving the rgcount modification to account for reserved zoned and then calling adjust_nr_zones unconditionally, and thus ensuring that the rtblocks and rtextents values are guaranteed to always be a multiple of the zone size.

---
 mkfs/xfs_mkfs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
mkfs/xfs_mkfs.c +0 -2
index 8db51217016e..b34407725f76 100644
@@ -4558,8 +4558,6 @@ adjust_nr_zones(
 		max_zones = DTOBT(cli->xi->rt.size, cfg->blocklog) /
 				cfg->rgsize;
 
-	if (!cli->rgcount)
-		cfg->rgcount += XFS_RESERVED_ZONES;
 	if (cfg->rgcount > max_zones) {
 		fprintf(stderr,
 _("Warning: not enough zones (%lu/%u) for backing requested rt size due to\n"

mkfs/xfs_mkfs.c _("rgsize (%s) not a multiple of fs blk size (%d)\n"), · line 4654

Quoted 8 lines
mkfs/xfs_mkfs.c +2 -3
@@ -4652,9 +4650,9 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"),
 		}
 	}
 
-	if (cli->rtsize || cli->rgcount)
-		adjust_nr_zones(cfg, cli, zt);
-
+	if (cli->rtsize)
+		cfg->rgcount += XFS_RESERVED_ZONES;

Hrm. So we're moving the XFS_RESERVED_ZONES addition code out of adjust_nr_zones to here. The conditional changes to rtsize because previously the only way we'd do the addition is if !rgcount, which means we were really only doing it if rtsize != 0.

And now that we always call adjust_nr_zones that part needed to be moved up.

I think I understand what's going on here, so

--D

Quoted 8 lines
mkfs/xfs_mkfs.c +1 -0
+	adjust_nr_zones(cfg, cli, zt);
 	if (cfg->rgcount < XFS_MIN_ZONES)  {
 		fprintf(stderr,
 _("realtime group count (%llu) must be greater than the minimum zone count (%u)\n"),
Signature · 1 line
2.47.3
#2 lore raw
Quoted 9 lines · Darrick J. Wong

Hrm. So we're moving the XFS_RESERVED_ZONES addition code out of adjust_nr_zones to here. The conditional changes to rtsize because previously the only way we'd do the addition is if !rgcount, which means we were really only doing it if rtsize != 0.

And now that we always call adjust_nr_zones that part needed to be moved up.

I think I understand what's going on here, so

Yes.