From: Christoph Hellwig Date: Wed, 28 Jan 2026 04:32:59 +0000 (+0100) Subject: libfrog: enable cached report zones X-Git-Tag: v6.19.0~21 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b7c900385985463b1b73e2b3def9435f7782561a;p=xfsprogs-dev.git libfrog: enable cached report zones 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 [hch: don't try cached reporting again if not supported] Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- diff --git a/include/platform_defs.h b/include/platform_defs.h index 1a9f401f..09129e0f 100644 --- a/include/platform_defs.h +++ b/include/platform_defs.h @@ -312,6 +312,12 @@ struct kvec { * Local definitions for the new cached report zones added in Linux 6.19 in case * the system 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 diff --git a/libfrog/zones.c b/libfrog/zones.c index 2276c56b..c088d324 100644 --- a/libfrog/zones.c +++ b/libfrog/zones.c @@ -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 /* 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));