* [PATCH v3 1/6] libxfs: add missing forward declaration in xfs_zones.h
2025-12-20 2:53 [PATCH v3 0/6] Enable cached zone report Damien Le Moal
@ 2025-12-20 2:53 ` 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
` (4 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
Add the missing forward declaration for struct blk_zone in xfs_zones.h.
This avoids headaches with the order of header file inclusion to avoid
compilation errors.
Fixes: 48ccc2459039 ("xfs: parse and validate hardware zone information")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
libxfs/xfs_zones.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libxfs/xfs_zones.h b/libxfs/xfs_zones.h
index c4f1367b2cca..6376bb0e6da6 100644
--- a/libxfs/xfs_zones.h
+++ b/libxfs/xfs_zones.h
@@ -2,6 +2,7 @@
#ifndef _LIBXFS_ZONES_H
#define _LIBXFS_ZONES_H
+struct blk_zone;
struct xfs_rtgroup;
/*
--
2.52.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v3 1/6] libxfs: add missing forward declaration in xfs_zones.h
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
1 sibling, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2026-01-06 16:16 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:21AM +0900, Damien Le Moal wrote:
> Add the missing forward declaration for struct blk_zone in xfs_zones.h.
> This avoids headaches with the order of header file inclusion to avoid
> compilation errors.
>
> Fixes: 48ccc2459039 ("xfs: parse and validate hardware zone information")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
> libxfs/xfs_zones.h | 1 +
We don't normally merge changes to xfsprogs' libxfs that haven't already
gone into the kernel libxfs. If Andrey's ok with this then I am too.
(alternate suggestion: can the forward declaration go in
platform_defs.h?)
--D
> 1 file changed, 1 insertion(+)
>
> diff --git a/libxfs/xfs_zones.h b/libxfs/xfs_zones.h
> index c4f1367b2cca..6376bb0e6da6 100644
> --- a/libxfs/xfs_zones.h
> +++ b/libxfs/xfs_zones.h
> @@ -2,6 +2,7 @@
> #ifndef _LIBXFS_ZONES_H
> #define _LIBXFS_ZONES_H
>
> +struct blk_zone;
> struct xfs_rtgroup;
>
> /*
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v3 1/6] libxfs: add missing forward declaration in xfs_zones.h
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
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2026-01-07 6:20 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Darrick J . Wong,
Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:21AM +0900, Damien Le Moal wrote:
> Add the missing forward declaration for struct blk_zone in xfs_zones.h.
> This avoids headaches with the order of header file inclusion to avoid
> compilation errors.
>
> Fixes: 48ccc2459039 ("xfs: parse and validate hardware zone information")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
This needs to go into the kernel first. And yes, I can't blame new
contributors for not knowing what files are shared..
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3 2/6] mkfs: remove unnecessary return value affectation
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
@ 2025-12-20 2:53 ` 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
` (3 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
The function report_zones() in mkfs/xfs_mkfs.c is a void function. So
there is no need to set the variable ret to -EIO before returning if
fstat() fails.
Fixes: 2e5a737a61d3 ("xfs_mkfs: support creating file system with zoned RT devices")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
mkfs/xfs_mkfs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index bc6a28b63c24..550fc011b614 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2589,10 +2589,8 @@ report_zones(
exit(1);
}
- if (fstat(fd, &st) < 0) {
- ret = -EIO;
+ if (fstat(fd, &st) < 0)
goto out_close;
- }
if (!S_ISBLK(st.st_mode))
goto out_close;
--
2.52.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v3 2/6] mkfs: remove unnecessary return value affectation
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
1 sibling, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2026-01-06 16:17 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:22AM +0900, Damien Le Moal wrote:
> The function report_zones() in mkfs/xfs_mkfs.c is a void function. So
> there is no need to set the variable ret to -EIO before returning if
> fstat() fails.
>
> Fixes: 2e5a737a61d3 ("xfs_mkfs: support creating file system with zoned RT devices")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
LGTM,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> mkfs/xfs_mkfs.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index bc6a28b63c24..550fc011b614 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -2589,10 +2589,8 @@ report_zones(
> exit(1);
> }
>
> - if (fstat(fd, &st) < 0) {
> - ret = -EIO;
> + if (fstat(fd, &st) < 0)
> goto out_close;
> - }
> if (!S_ISBLK(st.st_mode))
> goto out_close;
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v3 2/6] mkfs: remove unnecessary return value affectation
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
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2026-01-07 6:20 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Darrick J . Wong,
Christoph Hellwig, Carlos Maiolino
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3 3/6] libfrog: introduce xfrog_report_zones
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
2025-12-20 2:53 ` [PATCH v3 2/6] mkfs: remove unnecessary return value affectation Damien Le Moal
@ 2025-12-20 2:53 ` 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
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
Define the new helper function xfrog_report_zones() to report zones of
a zoned block device. This function is implemented in the new file
libfrog/zones.c and defined in the header file libfrog/zones.h.
xfrog_report_zones() allocates and returns a struct blk_zone_report
structure. It is the responsibility of the caller to free this
structure after use.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
libfrog/Makefile | 6 ++++--
libfrog/zones.c | 42 ++++++++++++++++++++++++++++++++++++++++++
libfrog/zones.h | 13 +++++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)
create mode 100644 libfrog/zones.c
create mode 100644 libfrog/zones.h
diff --git a/libfrog/Makefile b/libfrog/Makefile
index 268fa26638d7..9f405ffe3475 100644
--- a/libfrog/Makefile
+++ b/libfrog/Makefile
@@ -35,7 +35,8 @@ radix-tree.c \
randbytes.c \
scrub.c \
util.c \
-workqueue.c
+workqueue.c \
+zones.c
HFILES = \
avl64.h \
@@ -65,7 +66,8 @@ radix-tree.h \
randbytes.h \
scrub.h \
statx.h \
-workqueue.h
+workqueue.h \
+zones.h
GETTEXT_PY = \
gettext.py
diff --git a/libfrog/zones.c b/libfrog/zones.c
new file mode 100644
index 000000000000..0187edce5fa4
--- /dev/null
+++ b/libfrog/zones.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Western Digital Corporation or its affiliates.
+ */
+#include "platform_defs.h"
+#include "zones.h"
+#include <sys/ioctl.h>
+
+/* random size that allows efficient processing */
+#define ZONES_PER_REPORT 16384
+
+struct blk_zone_report *
+xfrog_report_zones(
+ int fd,
+ uint64_t sector)
+{
+ struct blk_zone_report *rep;
+ size_t rep_size;
+ int ret;
+
+ rep_size = sizeof(struct blk_zone_report) +
+ sizeof(struct blk_zone) * ZONES_PER_REPORT;
+ rep = calloc(1, rep_size);
+ if (!rep) {
+ fprintf(stderr,
+_("Failed to allocate memory for reporting zones.\n"));
+ return NULL;
+ }
+
+ rep->sector = sector;
+ rep->nr_zones = ZONES_PER_REPORT;
+
+ ret = ioctl(fd, BLKREPORTZONE, rep);
+ if (ret) {
+ fprintf(stderr,
+_("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
+ free(rep);
+ return NULL;
+ }
+
+ return rep;
+}
diff --git a/libfrog/zones.h b/libfrog/zones.h
new file mode 100644
index 000000000000..66df7a426a27
--- /dev/null
+++ b/libfrog/zones.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025, Western Digital Corporation or its affiliates.
+ */
+#ifndef __LIBFROG_ZONE_H__
+#define __LIBFROG_ZONE_H__
+
+#include <stdint.h>
+#include <linux/blkzoned.h>
+
+struct blk_zone_report *xfrog_report_zones(int fd, uint64_t sector);
+
+#endif /* __LIBFROG_ZONE_H__ */
--
2.52.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v3 3/6] libfrog: introduce xfrog_report_zones
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
0 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2026-01-06 16:29 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:23AM +0900, Damien Le Moal wrote:
> Define the new helper function xfrog_report_zones() to report zones of
> a zoned block device. This function is implemented in the new file
> libfrog/zones.c and defined in the header file libfrog/zones.h.
>
> xfrog_report_zones() allocates and returns a struct blk_zone_report
> structure. It is the responsibility of the caller to free this
> structure after use.
>
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
> libfrog/Makefile | 6 ++++--
> libfrog/zones.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> libfrog/zones.h | 13 +++++++++++++
> 3 files changed, 59 insertions(+), 2 deletions(-)
> create mode 100644 libfrog/zones.c
> create mode 100644 libfrog/zones.h
>
> diff --git a/libfrog/Makefile b/libfrog/Makefile
> index 268fa26638d7..9f405ffe3475 100644
> --- a/libfrog/Makefile
> +++ b/libfrog/Makefile
> @@ -35,7 +35,8 @@ radix-tree.c \
> randbytes.c \
> scrub.c \
> util.c \
> -workqueue.c
> +workqueue.c \
> +zones.c
>
> HFILES = \
> avl64.h \
> @@ -65,7 +66,8 @@ radix-tree.h \
> randbytes.h \
> scrub.h \
> statx.h \
> -workqueue.h
> +workqueue.h \
> +zones.h
>
> GETTEXT_PY = \
> gettext.py
> diff --git a/libfrog/zones.c b/libfrog/zones.c
> new file mode 100644
> index 000000000000..0187edce5fa4
> --- /dev/null
> +++ b/libfrog/zones.c
> @@ -0,0 +1,42 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2025, Western Digital Corporation or its affiliates.
> + */
> +#include "platform_defs.h"
> +#include "zones.h"
Nit:
#include "libfrog/zones.h"
to make it more obvious that we're looking for the libfrog version (on
the off chance /usr/include ever end up with a zones.h).
> +#include <sys/ioctl.h>
> +
> +/* random size that allows efficient processing */
> +#define ZONES_PER_REPORT 16384
> +
> +struct blk_zone_report *
> +xfrog_report_zones(
> + int fd,
> + uint64_t sector)
> +{
> + struct blk_zone_report *rep;
> + size_t rep_size;
> + int ret;
> +
> + rep_size = sizeof(struct blk_zone_report) +
> + sizeof(struct blk_zone) * ZONES_PER_REPORT;
> + rep = calloc(1, rep_size);
> + if (!rep) {
> + fprintf(stderr,
> +_("Failed to allocate memory for reporting zones.\n"));
> + return NULL;
> + }
> +
> + rep->sector = sector;
> + rep->nr_zones = ZONES_PER_REPORT;
> +
> + ret = ioctl(fd, BLKREPORTZONE, rep);
> + if (ret) {
> + fprintf(stderr,
> +_("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
Note that eventually gcc & friends will start warning about non-constant
formatting strings because i18n catalogue attacks are a thing now.
<start rant>
aka the Rigellian translation pack maps that string to "Hork fubzzz %s
%s %s %s" and now fprintf walks right off the varargs list and kaboom.
Annoyingly this makes output even worse because the canonical form of
that becomes this monstrosity:
fprintf(stderr, "%s: %s\n", _("BLKREPORTZONE failed"),
strerror(-errno));
This also fails because the Rigellians use jack-o-lantern emoji to
separate fields instead of colon-space so I don't know what to do :P
<end rant>
That said, xfsprogs is full of potential i18n catalogue attacks so if
Andrey's cool with it, then I'll go along with it.
(Though I'll at least try to remember not to type out the familiar old
way even though I've been doing it for 30 years.)
> + free(rep);
> + return NULL;
> + }
> +
> + return rep;
The logic in here looks good, though.
> +}
> diff --git a/libfrog/zones.h b/libfrog/zones.h
> new file mode 100644
> index 000000000000..66df7a426a27
> --- /dev/null
> +++ b/libfrog/zones.h
> @@ -0,0 +1,13 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2025, Western Digital Corporation or its affiliates.
> + */
> +#ifndef __LIBFROG_ZONE_H__
> +#define __LIBFROG_ZONE_H__
> +
> +#include <stdint.h>
> +#include <linux/blkzoned.h>
Don't put includes in header files, please. uint64_t should be covered
by platform_defs.h and you can just have a forward declaration of struct
blk_zone_report.
--D
> +
> +struct blk_zone_report *xfrog_report_zones(int fd, uint64_t sector);
> +
> +#endif /* __LIBFROG_ZONE_H__ */
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3 4/6] mkfs: use xfrog_report_zones()
2025-12-20 2:53 [PATCH v3 0/6] Enable cached zone report Damien Le Moal
` (2 preceding siblings ...)
2025-12-20 2:53 ` [PATCH v3 3/6] libfrog: introduce xfrog_report_zones Damien Le Moal
@ 2025-12-20 2:53 ` 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 ` [PATCH v3 6/6] libfrog: enable cached report zones Damien Le Moal
5 siblings, 1 reply; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
Use the function xfrog_report_zones() to obtain zone information from
a zoned device instead of directly issuing a BLKREPORTZONE ioctl.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
mkfs/xfs_mkfs.c | 35 +++++++++--------------------------
1 file changed, 9 insertions(+), 26 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 550fc011b614..ac7ad0661805 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -6,7 +6,6 @@
#include "libfrog/util.h"
#include "libxfs.h"
#include <ctype.h>
-#include <linux/blkzoned.h>
#include "libxfs/xfs_zones.h"
#include "xfs_multidisk.h"
#include "libxcmd.h"
@@ -15,6 +14,7 @@
#include "libfrog/crc32cselftest.h"
#include "libfrog/dahashselftest.h"
#include "libfrog/fsproperties.h"
+#include "libfrog/zones.h"
#include "proto.h"
#include <ini.h>
@@ -2566,20 +2566,16 @@ struct zone_topology {
struct zone_info log;
};
-/* random size that allows efficient processing */
-#define ZONES_PER_IOCTL 16384
-
static void
report_zones(
const char *name,
struct zone_info *zi)
{
- struct blk_zone_report *rep;
+ struct blk_zone_report *rep = NULL;
bool found_seq = false;
- int fd, ret = 0;
+ int fd;
uint64_t device_size;
uint64_t sector = 0;
- size_t rep_size;
unsigned int i, n = 0;
struct stat st;
@@ -2606,31 +2602,18 @@ report_zones(
zi->nr_zones = device_size / zi->zone_size;
zi->nr_conv_zones = 0;
- rep_size = sizeof(struct blk_zone_report) +
- sizeof(struct blk_zone) * ZONES_PER_IOCTL;
- rep = malloc(rep_size);
- if (!rep) {
- fprintf(stderr,
-_("Failed to allocate memory for zone reporting.\n"));
- exit(1);
- }
-
while (n < zi->nr_zones) {
- struct blk_zone *zones = (struct blk_zone *)(rep + 1);
+ struct blk_zone *zones;
- memset(rep, 0, rep_size);
- rep->sector = sector;
- rep->nr_zones = ZONES_PER_IOCTL;
-
- ret = ioctl(fd, BLKREPORTZONE, rep);
- if (ret) {
- fprintf(stderr,
-_("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
+ free(rep);
+ rep = xfrog_report_zones(fd, sector);
+ if (!rep)
exit(1);
- }
+
if (!rep->nr_zones)
break;
+ zones = (struct blk_zone *)(rep + 1);
for (i = 0; i < rep->nr_zones; i++) {
if (n >= zi->nr_zones)
break;
--
2.52.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v3 4/6] mkfs: use xfrog_report_zones()
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
0 siblings, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2026-01-06 16:31 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:24AM +0900, Damien Le Moal wrote:
> Use the function xfrog_report_zones() to obtain zone information from
> a zoned device instead of directly issuing a BLKREPORTZONE ioctl.
>
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
> mkfs/xfs_mkfs.c | 35 +++++++++--------------------------
> 1 file changed, 9 insertions(+), 26 deletions(-)
>
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 550fc011b614..ac7ad0661805 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -6,7 +6,6 @@
> #include "libfrog/util.h"
> #include "libxfs.h"
> #include <ctype.h>
> -#include <linux/blkzoned.h>
> #include "libxfs/xfs_zones.h"
> #include "xfs_multidisk.h"
> #include "libxcmd.h"
> @@ -15,6 +14,7 @@
> #include "libfrog/crc32cselftest.h"
> #include "libfrog/dahashselftest.h"
> #include "libfrog/fsproperties.h"
> +#include "libfrog/zones.h"
> #include "proto.h"
> #include <ini.h>
>
> @@ -2566,20 +2566,16 @@ struct zone_topology {
> struct zone_info log;
> };
>
> -/* random size that allows efficient processing */
> -#define ZONES_PER_IOCTL 16384
> -
> static void
> report_zones(
> const char *name,
> struct zone_info *zi)
> {
> - struct blk_zone_report *rep;
> + struct blk_zone_report *rep = NULL;
> bool found_seq = false;
> - int fd, ret = 0;
> + int fd;
> uint64_t device_size;
> uint64_t sector = 0;
> - size_t rep_size;
> unsigned int i, n = 0;
> struct stat st;
>
> @@ -2606,31 +2602,18 @@ report_zones(
> zi->nr_zones = device_size / zi->zone_size;
> zi->nr_conv_zones = 0;
>
> - rep_size = sizeof(struct blk_zone_report) +
> - sizeof(struct blk_zone) * ZONES_PER_IOCTL;
> - rep = malloc(rep_size);
> - if (!rep) {
> - fprintf(stderr,
> -_("Failed to allocate memory for zone reporting.\n"));
> - exit(1);
> - }
> -
> while (n < zi->nr_zones) {
> - struct blk_zone *zones = (struct blk_zone *)(rep + 1);
> + struct blk_zone *zones;
>
> - memset(rep, 0, rep_size);
> - rep->sector = sector;
> - rep->nr_zones = ZONES_PER_IOCTL;
> -
> - ret = ioctl(fd, BLKREPORTZONE, rep);
> - if (ret) {
> - fprintf(stderr,
> -_("ioctl(BLKREPORTZONE) failed: %d!\n"), -errno);
> + free(rep);
> + rep = xfrog_report_zones(fd, sector);
Now that I see the actual usage patterns I wonder if this would be more
efficient if you had a separate allocator function to avoid repeatedly
freeing and re-allocating the buffer?
Also this could be combined with the previous patch since you're really
just hoisting code from mkfs to libfrog.
--D
> + if (!rep)
> exit(1);
> - }
> +
> if (!rep->nr_zones)
> break;
>
> + zones = (struct blk_zone *)(rep + 1);
> for (i = 0; i < rep->nr_zones; i++) {
> if (n >= zi->nr_zones)
> break;
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v3 5/6] repair: use xfrog_report_zones()
2025-12-20 2:53 [PATCH v3 0/6] Enable cached zone report Damien Le Moal
` (3 preceding siblings ...)
2025-12-20 2:53 ` [PATCH v3 4/6] mkfs: use xfrog_report_zones() Damien Le Moal
@ 2025-12-20 2:53 ` Damien Le Moal
2025-12-20 2:53 ` [PATCH v3 6/6] libfrog: enable cached report zones Damien Le Moal
5 siblings, 0 replies; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
Use the function xfrog_report_zones() to obtain zones information from
a zoned device instead of directly issuing a BLKREPORTZONE ioctl.
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
repair/zoned.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/repair/zoned.c b/repair/zoned.c
index 206b0158f95f..c211e02448da 100644
--- a/repair/zoned.c
+++ b/repair/zoned.c
@@ -3,7 +3,7 @@
* Copyright (c) 2024 Christoph Hellwig.
*/
#include <ctype.h>
-#include <linux/blkzoned.h>
+#include "libfrog/zones.h"
#include "libxfs_priv.h"
#include "libxfs.h"
#include "xfs_zones.h"
@@ -51,8 +51,7 @@ check_zones(
uint64_t sector = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rtstart);
unsigned int zone_size, zone_capacity;
uint64_t device_size;
- size_t rep_size;
- struct blk_zone_report *rep;
+ struct blk_zone_report *rep = NULL;
unsigned int i, n = 0;
if (ioctl(fd, BLKGETSIZE64, &device_size))
@@ -67,30 +66,18 @@ check_zones(
return;
}
- rep_size = sizeof(struct blk_zone_report) +
- sizeof(struct blk_zone) * ZONES_PER_IOCTL;
- rep = malloc(rep_size);
- if (!rep) {
- do_warn(_("malloc failed for zone report\n"));
- return;
- }
-
while (n < mp->m_sb.sb_rgcount) {
- struct blk_zone *zones = (struct blk_zone *)(rep + 1);
- int ret;
+ struct blk_zone *zones;
- memset(rep, 0, rep_size);
- rep->sector = sector;
- rep->nr_zones = ZONES_PER_IOCTL;
+ free(rep);
+ rep = xfrog_report_zones(fd, sector);
+ if (!rep)
+ return;
- ret = ioctl(fd, BLKREPORTZONE, rep);
- if (ret) {
- do_error(_("ioctl(BLKREPORTZONE) failed: %d!\n"), ret);
- goto out_free;
- }
if (!rep->nr_zones)
break;
+ zones = (struct blk_zone *)(rep + 1);
for (i = 0; i < rep->nr_zones; i++) {
if (n >= mp->m_sb.sb_rgcount)
break;
--
2.52.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v3 6/6] libfrog: enable cached report zones
2025-12-20 2:53 [PATCH v3 0/6] Enable cached zone report Damien Le Moal
` (4 preceding siblings ...)
2025-12-20 2:53 ` [PATCH v3 5/6] repair: " Damien Le Moal
@ 2025-12-20 2:53 ` Damien Le Moal
2026-01-06 16:34 ` Darrick J. Wong
2026-01-07 6:22 ` Christoph Hellwig
5 siblings, 2 replies; 15+ messages in thread
From: Damien Le Moal @ 2025-12-20 2:53 UTC (permalink / raw)
To: linux-xfs, Andrey Albershteyn
Cc: Darrick J . Wong, Christoph Hellwig, Carlos Maiolino
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
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v3 6/6] libfrog: enable cached report zones
2025-12-20 2:53 ` [PATCH v3 6/6] libfrog: enable cached report zones Damien Le Moal
@ 2026-01-06 16:34 ` Darrick J. Wong
2026-01-07 6:22 ` Christoph Hellwig
1 sibling, 0 replies; 15+ messages in thread
From: Darrick J. Wong @ 2026-01-06 16:34 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:26AM +0900, Damien Le Moal wrote:
> 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
Of these three definitions, only BLK_ZONE_COND_ACTIVE is actually used
outside of libfrog/zones.c, right? I suggest defining BLKREPORTZONEV2
and BLK_ZONE_REP_CACHED there instead of zones.h to reduce the number of
symbols floating around.
(The rest of the code changes look ok to me)
--D
> +#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
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v3 6/6] libfrog: enable cached report zones
2025-12-20 2:53 ` [PATCH v3 6/6] libfrog: enable cached report zones Damien Le Moal
2026-01-06 16:34 ` Darrick J. Wong
@ 2026-01-07 6:22 ` Christoph Hellwig
1 sibling, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2026-01-07 6:22 UTC (permalink / raw)
To: Damien Le Moal
Cc: linux-xfs, Andrey Albershteyn, Darrick J . Wong,
Christoph Hellwig, Carlos Maiolino
On Sat, Dec 20, 2025 at 11:53:26AM +0900, Damien Le Moal wrote:
> 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
This file is shared with the kernel, so we'll need to get the changes
from a libxfs sync as well.
> @@ -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>
.. and we'll need this include to be hidden in the xfsprogs-wide
headers.
^ permalink raw reply [flat|nested] 15+ messages in thread