]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
libfrog: enable cached report zones
authorChristoph Hellwig <hch@lst.de>
Wed, 28 Jan 2026 04:32:59 +0000 (05:32 +0100)
committerAndrey Albershteyn <aalbersh@kernel.org>
Wed, 28 Jan 2026 09:54:36 +0000 (10:54 +0100)
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>
[hch: don't try cached reporting again if not supported]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
include/platform_defs.h
libfrog/zones.c

index 1a9f401fc11c965738717cdc9542949681dff873..09129e0f22dcba985f04dbc5c1ec29f04e330d03 100644 (file)
@@ -312,6 +312,12 @@ struct kvec {
  * Local definitions for the new cached report zones added in Linux 6.19 in case
  * the system <linux/blkzoned.h> doesn't provide them yet.
  */
+#ifndef BLKREPORTZONEV2
+#define BLKREPORTZONEV2                _IOWR(0x12, 142, struct blk_zone_report)
+#endif
+#ifndef BLK_ZONE_REP_CACHED
+#define BLK_ZONE_REP_CACHED    (1U << 31)
+#endif
 #ifndef BLK_ZONE_COND_ACTIVE
 #define BLK_ZONE_COND_ACTIVE   0xff
 #endif
index 2276c56bec9cf5b2d963768458bc808fe8d1356f..c088d32405458d721ae4d11d6354d0e02fa4cf3b 100644 (file)
@@ -3,12 +3,15 @@
  * Copyright (c) 2025, Western Digital Corporation or its affiliates.
  */
 #include "platform_defs.h"
+#include "atomic.h"
 #include "libfrog/zones.h"
 #include <sys/ioctl.h>
 
 /* random size that allows efficient processing */
 #define ZONES_PER_REPORT               16384
 
+static atomic_t cached_reporting_disabled;
+
 struct xfrog_zone_report *
 xfrog_report_zones(
        int                     fd,
@@ -24,10 +27,27 @@ _("Failed to allocate memory for reporting zones."));
                }
        }
 
+       /*
+        * Try cached report zones first. If this fails, fallback to the regular
+        * (slower) report zones.
+        */
        rep->rep.sector = sector;
        rep->rep.nr_zones = ZONES_PER_REPORT;
 
-       if (ioctl(fd, BLKREPORTZONE, &rep->rep)) {
+       if (atomic_read(&cached_reporting_disabled))
+               goto uncached;
+
+       rep->rep.flags = BLK_ZONE_REP_CACHED;
+       if (ioctl(fd, BLKREPORTZONEV2, &rep->rep)) {
+               atomic_inc(&cached_reporting_disabled);
+               goto uncached;
+       }
+
+       return rep;
+
+uncached:
+       rep->rep.flags = 0;
+       if (ioctl(fd, BLKREPORTZONE, rep)) {
                fprintf(stderr, "%s %s\n",
 _("ioctl(BLKREPORTZONE) failed:\n"),
                        strerror(-errno));