* 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
* 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,
}
}
+ /*
+ * 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));