linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: cem@kernel.org
To: aalbersh@redhat.com
Cc: linux-xfs@vger.kernel.org, hch@lst.de
Subject: [PATCH V2] mkfs: fix zone capacity check for sequential zones
Date: Thu, 13 Nov 2025 14:46:13 +0100	[thread overview]
Message-ID: <20251113134632.754351-1-cem@kernel.org> (raw)

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.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---

Changelog:
	v2:
	 - remove unnecessary braces
	 - add hch's RwB

 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..8f5a6fa56764 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


             reply	other threads:[~2025-11-13 13:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 13:46 cem [this message]
2025-11-17  9:27 ` [PATCH V2] mkfs: fix zone capacity check for sequential zones Hans Holmberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251113134632.754351-1-cem@kernel.org \
    --to=cem@kernel.org \
    --cc=aalbersh@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).