public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: linux-xfs@vger.kernel.org, Andrey Albershteyn <aalbersh@kernel.org>
Cc: "Darrick J . Wong" <djwong@kernel.org>,
	Christoph Hellwig <hch@lst.de>, Carlos Maiolino <cem@kernel.org>
Subject: [PATCH v3 6/6] libfrog: enable cached report zones
Date: Sat, 20 Dec 2025 11:53:26 +0900	[thread overview]
Message-ID: <20251220025326.209196-7-dlemoal@kernel.org> (raw)
In-Reply-To: <20251220025326.209196-1-dlemoal@kernel.org>

Modify the function xfrog_report_zones() to default to always trying
first a cached report zones using the BLKREPORTZONEV2 ioctl.
If the kernel does not support BLKREPORTZONEV2, fall back to the
(slower) regular report zones BLKREPORTZONE ioctl.

TO enable this feature even if xfsprogs is compiled on a system where
linux/blkzoned.h does not define BLKREPORTZONEV2, this ioctl is defined
in libfrog/zones.h, together with the BLK_ZONE_REP_CACHED flag and the
BLK_ZONE_COND_ACTIVE zone condition.

Since a cached report zone  always return the condition
BLK_ZONE_COND_ACTIVE for any zone that is implicitly open, explicitly
open or closed, the function xfs_zone_validate_seq() is modified to
handle this new condition as being equivalent to the implicit open,
explicit open or closed conditions.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 libfrog/zones.c    | 11 ++++++++++-
 libfrog/zones.h    |  9 +++++++++
 libxfs/xfs_zones.c |  3 ++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/libfrog/zones.c b/libfrog/zones.c
index 0187edce5fa4..8b45066de176 100644
--- a/libfrog/zones.c
+++ b/libfrog/zones.c
@@ -27,10 +27,19 @@ _("Failed to allocate memory for reporting zones.\n"));
 		return NULL;
 	}
 
+	/*
+	 * Try cached report zones first. If this fails, fallback to the regular
+	 * (slower) report zones.
+	 */
 	rep->sector = sector;
 	rep->nr_zones = ZONES_PER_REPORT;
+	rep->flags = BLK_ZONE_REP_CACHED;
 
-	ret = ioctl(fd, BLKREPORTZONE, rep);
+	ret = ioctl(fd, BLKREPORTZONEV2, rep);
+	if (ret < 0 && errno == ENOTTY) {
+		rep->flags = 0;
+		ret = ioctl(fd, BLKREPORTZONE, rep);
+	}
 	if (ret) {
 		fprintf(stderr,
 _("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
diff --git a/libfrog/zones.h b/libfrog/zones.h
index 66df7a426a27..4605aea93114 100644
--- a/libfrog/zones.h
+++ b/libfrog/zones.h
@@ -8,6 +8,15 @@
 #include <stdint.h>
 #include <linux/blkzoned.h>
 
+/*
+ * Cached report ioctl (/usr/include/linux/blkzoned.h)
+ */
+#ifndef BLKREPORTZONEV2
+#define BLKREPORTZONEV2		_IOWR(0x12, 142, struct blk_zone_report)
+#define BLK_ZONE_REP_CACHED	(1U << 31)
+#define BLK_ZONE_COND_ACTIVE	0xff
+#endif
+
 struct blk_zone_report	*xfrog_report_zones(int	fd, uint64_t sector);
 
 #endif /* __LIBFROG_ZONE_H__ */
diff --git a/libxfs/xfs_zones.c b/libxfs/xfs_zones.c
index 7a81d83f5b3e..3c89a89ca21e 100644
--- a/libxfs/xfs_zones.c
+++ b/libxfs/xfs_zones.c
@@ -3,7 +3,7 @@
  * Copyright (c) 2023-2025 Christoph Hellwig.
  * Copyright (c) 2024-2025, Western Digital Corporation or its affiliates.
  */
-#include <linux/blkzoned.h>
+#include <libfrog/zones.h>
 #include "libxfs_priv.h"
 #include "xfs.h"
 #include "xfs_fs.h"
@@ -97,6 +97,7 @@ xfs_zone_validate_seq(
 	case BLK_ZONE_COND_IMP_OPEN:
 	case BLK_ZONE_COND_EXP_OPEN:
 	case BLK_ZONE_COND_CLOSED:
+	case BLK_ZONE_COND_ACTIVE:
 		return xfs_zone_validate_wp(zone, rtg, write_pointer);
 	case BLK_ZONE_COND_FULL:
 		return xfs_zone_validate_full(zone, rtg, write_pointer);
-- 
2.52.0


  parent reply	other threads:[~2025-12-20  2:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-20  2:53 [PATCH v3 0/6] Enable cached zone report Damien Le Moal
2025-12-20  2:53 ` [PATCH v3 1/6] libxfs: add missing forward declaration in xfs_zones.h Damien Le Moal
2026-01-06 16:16   ` Darrick J. Wong
2026-01-07  6:20   ` Christoph Hellwig
2025-12-20  2:53 ` [PATCH v3 2/6] mkfs: remove unnecessary return value affectation Damien Le Moal
2026-01-06 16:17   ` Darrick J. Wong
2026-01-07  6:20   ` Christoph Hellwig
2025-12-20  2:53 ` [PATCH v3 3/6] libfrog: introduce xfrog_report_zones Damien Le Moal
2026-01-06 16:29   ` Darrick J. Wong
2025-12-20  2:53 ` [PATCH v3 4/6] mkfs: use xfrog_report_zones() Damien Le Moal
2026-01-06 16:31   ` Darrick J. Wong
2025-12-20  2:53 ` [PATCH v3 5/6] repair: " Damien Le Moal
2025-12-20  2:53 ` Damien Le Moal [this message]
2026-01-06 16:34   ` [PATCH v3 6/6] libfrog: enable cached report zones Darrick J. Wong
2026-01-07  6:22   ` Christoph Hellwig

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=20251220025326.209196-7-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --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