public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mkfs: fix zone capacity check for sequential zones
@ 2025-11-12 12:33 cem
  2025-11-12 12:50 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: cem @ 2025-11-12 12:33 UTC (permalink / raw)
  To: aalbersh; +Cc: linux-xfs, hch

From: Carlos Maiolino <cem@kernel.org>

Sequential zones can have a different, smaller capacity than
conventional zones.

Currently mkfs assumes both sequential and conventional zones will have
the same capacity and and set the zone_info to the capacity of the first
found zone and use that value to validate all the remaining zones's
capacity.

Because conventional zones can't have a different capacity than its
size, the first zone always have the largest possible capacity, so, mkfs
will fail to validate any consecutive sequential zone if its capacity is
smaller than the conventional zones.

What we should do instead, is set the zone info capacity accordingly to
the settings of first zone found of the respective type and validate
the capacity based on that instead of assuming all zones will have the
same capacity.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---

FWIS, writing the patch description I'm assuming that the conventional zones
always come first and we can't have a zoned device starting with
sequential zones followed by conventional zones.

 mkfs/xfs_mkfs.c | 50 +++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index cd4f3ba4a549..1378e788eb95 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2545,6 +2545,28 @@ struct zone_topology {
 /* random size that allows efficient processing */
 #define ZONES_PER_IOCTL			16384
 
+static void
+zone_validate_capacity(
+	struct zone_info	*zi,
+	__u64			capacity,
+	bool			conventional)
+{
+	if (conventional && (zi->zone_capacity != zi->zone_size)) {
+		fprintf(stderr, _("Zone capacity equal to Zone size required for conventional zones.\n"));
+		exit(1);
+	}
+
+	if (zi->zone_capacity > zi->zone_size) {
+		fprintf(stderr, _("Zone capacity larger than zone size!\n"));
+		exit(1);
+	}
+
+	if (zi->zone_capacity != capacity) {
+		fprintf(stderr, _("Inconsistent zone capacity!\n"));
+		exit(1);
+	}
+}
+
 static void
 report_zones(
 	const char		*name,
@@ -2621,6 +2643,11 @@ _("Inconsistent zone size!\n"));
 
 			switch (zones[i].type) {
 			case BLK_ZONE_TYPE_CONVENTIONAL:
+				if (!zi->zone_capacity)
+					zi->zone_capacity = zones[i].capacity;
+				zone_validate_capacity(zi, zones[i].capacity,
+						       true);
+
 				/*
 				 * We can only use the conventional space at the
 				 * start of the device for metadata, so don't
@@ -2632,6 +2659,11 @@ _("Inconsistent zone size!\n"));
 					zi->nr_conv_zones++;
 				break;
 			case BLK_ZONE_TYPE_SEQWRITE_REQ:
+				if (!found_seq)
+					zi->zone_capacity = zones[i].capacity;
+				zone_validate_capacity(zi, zones[i].capacity,
+						       false);
+
 				found_seq = true;
 				break;
 			case BLK_ZONE_TYPE_SEQWRITE_PREF:
@@ -2644,19 +2676,6 @@ _("Unknown zone type (0x%x) found.\n"), zones[i].type);
 				exit(1);
 			}
 
-			if (!n) {
-				zi->zone_capacity = zones[i].capacity;
-				if (zi->zone_capacity > zi->zone_size) {
-					fprintf(stderr,
-_("Zone capacity larger than zone size!\n"));
-					exit(1);
-				}
-			} else if (zones[i].capacity != zi->zone_capacity) {
-				fprintf(stderr,
-_("Inconsistent zone capacity!\n"));
-				exit(1);
-			}
-
 			n++;
 		}
 		sector = zones[rep->nr_zones - 1].start +
@@ -2683,11 +2702,6 @@ validate_zoned(
 _("Data devices requires conventional zones.\n"));
 				usage();
 			}
-			if (zt->data.zone_capacity != zt->data.zone_size) {
-				fprintf(stderr,
-_("Zone capacity equal to Zone size required for conventional zones.\n"));
-				usage();
-			}
 
 			cli->sb_feat.zoned = true;
 			cfg->rtstart =
-- 
2.51.0


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

* Re: [PATCH] mkfs: fix zone capacity check for sequential zones
  2025-11-12 12:33 [PATCH] mkfs: fix zone capacity check for sequential zones cem
@ 2025-11-12 12:50 ` Christoph Hellwig
  2025-11-12 13:25   ` Carlos Maiolino
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2025-11-12 12:50 UTC (permalink / raw)
  To: cem; +Cc: aalbersh, linux-xfs, hch

On Wed, Nov 12, 2025 at 01:33:16PM +0100, cem@kernel.org wrote:
> FWIS, writing the patch description I'm assuming that the conventional zones
> always come first and we can't have a zoned device starting with
> sequential zones followed by conventional zones.

XFS kinda assumes this by not counting counting conventional zones found
after sequential zones, so we'll error out due to the lack of conventional
space later unless a separate device is used.

> +static void
> +zone_validate_capacity(
> +	struct zone_info	*zi,
> +	__u64			capacity,
> +	bool			conventional)
> +{
> +	if (conventional && (zi->zone_capacity != zi->zone_size)) {

No need for the inner braces.

Otherwise this looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Note that we should also verify that if a device is used purely as
RT device (aka no internal RT device), that there are either no
conventional zones, or zone capacity == zone_size.  I can look into
that as an incremental patch.

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

* Re: [PATCH] mkfs: fix zone capacity check for sequential zones
  2025-11-12 12:50 ` Christoph Hellwig
@ 2025-11-12 13:25   ` Carlos Maiolino
  2025-11-12 14:36     ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Maiolino @ 2025-11-12 13:25 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: aalbersh, linux-xfs

On Wed, Nov 12, 2025 at 01:50:56PM +0100, Christoph Hellwig wrote:
> On Wed, Nov 12, 2025 at 01:33:16PM +0100, cem@kernel.org wrote:
> > FWIS, writing the patch description I'm assuming that the conventional zones
> > always come first and we can't have a zoned device starting with
> > sequential zones followed by conventional zones.
> 
> XFS kinda assumes this by not counting counting conventional zones found
> after sequential zones, so we'll error out due to the lack of conventional
> space later unless a separate device is used.
> 
> > +static void
> > +zone_validate_capacity(
> > +	struct zone_info	*zi,
> > +	__u64			capacity,
> > +	bool			conventional)
> > +{
> > +	if (conventional && (zi->zone_capacity != zi->zone_size)) {
> 
> No need for the inner braces.
> 
> Otherwise this looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Note that we should also verify that if a device is used purely as
> RT device (aka no internal RT device), that there are either no
> conventional zones, or zone capacity == zone_size.  I can look into
> that as an incremental patch.

Your call. I can add it to the V2, giving I'll rewrite the above to
remove the unneeded braces.

Couldn't we leverage this check in validate_zoned() for that?

if (cli->xi->rt.name && !cli->xi->rt.isfile) {
	[...]

I'm not sure though if just detecting a rtdev was passed on the CLI
would suffice to cover what you proposed.



> 

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

* Re: [PATCH] mkfs: fix zone capacity check for sequential zones
  2025-11-12 13:25   ` Carlos Maiolino
@ 2025-11-12 14:36     ` Christoph Hellwig
  2025-11-12 15:02       ` Carlos Maiolino
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2025-11-12 14:36 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: Christoph Hellwig, aalbersh, linux-xfs

On Wed, Nov 12, 2025 at 02:25:11PM +0100, Carlos Maiolino wrote:
> Your call. I can add it to the V2, giving I'll rewrite the above to
> remove the unneeded braces.

Nah, let's do one thing at a time.


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

* Re: [PATCH] mkfs: fix zone capacity check for sequential zones
  2025-11-12 14:36     ` Christoph Hellwig
@ 2025-11-12 15:02       ` Carlos Maiolino
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2025-11-12 15:02 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: aalbersh, linux-xfs

On Wed, Nov 12, 2025 at 03:36:59PM +0100, Christoph Hellwig wrote:
> On Wed, Nov 12, 2025 at 02:25:11PM +0100, Carlos Maiolino wrote:
> > Your call. I can add it to the V2, giving I'll rewrite the above to
> > remove the unneeded braces.
> 
> Nah, let's do one thing at a time.
> 

okie!

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

end of thread, other threads:[~2025-11-12 15:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 12:33 [PATCH] mkfs: fix zone capacity check for sequential zones cem
2025-11-12 12:50 ` Christoph Hellwig
2025-11-12 13:25   ` Carlos Maiolino
2025-11-12 14:36     ` Christoph Hellwig
2025-11-12 15:02       ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox