#include "libfrog/util.h"
#include "libxfs.h"
#include <ctype.h>
+#include <linux/blkzoned.h>
#include "xfs_multidisk.h"
#include "libxcmd.h"
#include "libfrog/fsgeom.h"
R_RTGROUPS,
R_RGCOUNT,
R_RGSIZE,
+ R_ZONED,
R_MAX_OPTS,
};
[R_RTGROUPS] = "rtgroups",
[R_RGCOUNT] = "rgcount",
[R_RGSIZE] = "rgsize",
+ [R_ZONED] = "zoned",
[R_MAX_OPTS] = NULL,
},
.subopt_params = {
.maxval = (unsigned long long)XFS_MAX_RGBLOCKS << XFS_MAX_BLOCKSIZE_LOG,
.defaultval = SUBOPT_NEEDS_VAL,
},
+ { .index = R_ZONED,
+ .conflicts = { { &ropts, R_EXTSIZE },
+ { NULL, LAST_CONFLICT } },
+ .minval = 0,
+ .maxval = 1,
+ .defaultval = 0,
+ },
},
};
bool nrext64;
bool exchrange; /* XFS_SB_FEAT_INCOMPAT_EXCHRANGE */
bool rtgroups; /* XFS_SB_FEAT_INCOMPAT_RTGROUPS */
+ bool zoned;
};
struct cli_params {
printf("Done.\n");
}
+static void
+reset_zones(int fd, uint64_t nsectors, int quiet)
+{
+ struct blk_zone_range range = {
+ .nr_sectors = nsectors,
+ };
+
+ if (!quiet) {
+ printf("Discarding blocks...");
+ fflush(stdout);
+ }
+
+ if (ioctl(fd, BLKRESETZONE, &range) < 0) {
+ if (!quiet)
+ printf(" FAILED\n");
+ exit(1);
+ }
+
+ if (!quiet)
+ printf("Done.\n");
+}
+
static __attribute__((noreturn)) void
illegal_option(
const char *value,
case R_RGSIZE:
cli->rgsize = getstr(value, opts, subopt);
break;
+ case R_ZONED:
+ cli->sb_feat.zoned = getnum(value, opts, subopt);
+ break;
default:
return -EINVAL;
}
_("log stripe unit specified, using v2 logs\n"));
cli->sb_feat.log_version = 2;
}
+}
+
+struct zone_info {
+ unsigned int nr_zones;
+ unsigned int zone_capacity;
+};
+
+struct zone_topology {
+ struct zone_info data;
+ struct zone_info rt;
+ struct zone_info log;
+};
+
+#define ZONES_PER_IOCTL 16384
+static int report_zones(const char *name, struct zone_info *zi)
+{
+ struct blk_zone_report *rep;
+ size_t rep_size;
+ struct stat st;
+ unsigned int i, n = 0;
+ unsigned int zone_size = 0;
+ uint64_t device_size;
+ uint64_t sector = 0;
+ int ret = 0;
+ int fd;
+
+ fd = open(name, O_RDONLY);
+ if (fd < 0)
+ return -EIO;
+
+ if (fstat(fd, &st) < 0) {
+ ret = -EIO;
+ goto out_close;
+ }
+ if (!S_ISBLK(st.st_mode))
+ goto out_close;
+
+ if (ioctl(fd, BLKGETSIZE64, &device_size)) {
+ ret = -EIO;
+ goto out_close;
+ }
+ if (ioctl(fd, BLKGETZONESZ, &zone_size) || !zone_size)
+ goto out_close; /* not zoned */
+
+ device_size /= 512; /* BLKGETSIZE64 reports a byte value */
+ zi->nr_zones = device_size / zone_size;
+
+ rep_size = sizeof(struct blk_zone_report) +
+ sizeof(struct blk_zone) * min(zi->nr_zones, ZONES_PER_IOCTL);
+ rep = malloc(rep_size);
+ if (!rep) {
+ ret = -ENOMEM;
+ goto out_close;
+ }
+
+ while (n < zi->nr_zones) {
+ struct blk_zone *zones = (struct blk_zone *)(rep + 1);
+
+ 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"), ret);
+ goto out_free;
+ }
+ if (!rep->nr_zones)
+ break;
+
+ for (i = 0; i < rep->nr_zones; i++) {
+ if (n >= zi->nr_zones)
+ break;
+
+ switch (zones[i].type) {
+ case BLK_ZONE_TYPE_CONVENTIONAL:
+ break;
+ case BLK_ZONE_TYPE_SEQWRITE_REQ:
+ break;
+ case BLK_ZONE_TYPE_SEQWRITE_PREF:
+ fprintf(stderr,
+_("Sequential write preferred zones not supported!\n"));
+ ret = -EIO;
+ goto out_free;
+ }
+
+ if (zones[i].len != zone_size) {
+ fprintf(stderr,
+_("Inconsistent zone size!\n"));
+ ret = -EIO;
+ goto out_free;
+ }
+
+ if (!n) {
+ zi->zone_capacity = zones[i].capacity;
+ if (zi->zone_capacity > zone_size) {
+ fprintf(stderr,
+_("Zone capacity larger than zone size!\n"));
+ ret = -EIO;
+ }
+ } else if (zones[i].capacity != zi->zone_capacity) {
+ fprintf(stderr,
+_("Inconsistent zone capacity!\n"));
+ ret = -EIO;
+ goto out_free;
+ }
+
+ n++;
+ }
+ sector = zones[rep->nr_zones - 1].start +
+ zones[rep->nr_zones - 1].len;
+ }
+
+out_free:
+ free(rep);
+out_close:
+ close(fd);
+ return ret;
+}
+
+static void
+validate_zoned(
+ struct mkfs_params *cfg,
+ struct cli_params *cli,
+ struct mkfs_default_params *dft,
+ struct zone_topology *zt)
+{
+ if (!cli->xi->data.isfile) {
+ report_zones(cli->xi->data.name, &zt->data);
+ if (zt->data.nr_zones) {
+ fprintf(stderr,
+_("Zoned devices not supported as main device!\n"));
+ usage();
+ }
+ }
+
+ if (cli->xi->rt.name && !cli->xi->rt.isfile) {
+ report_zones(cli->xi->rt.name, &zt->rt);
+ if (zt->rt.nr_zones && !cli->sb_feat.zoned)
+ cli->sb_feat.zoned = true;
+ }
+
+ if (cli->xi->log.name && !cli->xi->log.isfile) {
+ report_zones(cli->xi->log.name, &zt->log);
+ if (zt->log.nr_zones) {
+ fprintf(stderr,
+_("Zoned devices not supported as log device!\n"));
+ usage();
+ }
+ }
}
/*
}
if (cli->xi->rt.name) {
+ if (cli->sb_feat.zoned && !cli->sb_feat.rtgroups) {
+ if (cli_opt_set(&ropts, R_RTGROUPS)) {
+ fprintf(stderr,
+_("zoned mode not supported without rtgroups support\n"));
+ usage();
+ }
+ cli->sb_feat.rtgroups = true;
+ }
+ if (cli->sb_feat.zoned && cli->rtextsize) {
+ if (cli_opt_set(&ropts, R_EXTSIZE)) {
+ fprintf(stderr,
+_("rt extent size not supported on realtime devices with zoned mode specified\n"));
+ usage();
+ }
+ cli->rtextsize = 0;
+ }
if (cli->rtextsize && cli->sb_feat.reflink) {
if (cli_opt_set(&mopts, M_REFLINK)) {
fprintf(stderr,
static void
discard_devices(
struct libxfs_init *xi,
+ struct zone_topology *zt,
int quiet)
{
/*
if (!xi->data.isfile)
discard_blocks(xi->data.fd, xi->data.size, quiet);
- if (xi->rt.dev && !xi->rt.isfile)
- discard_blocks(xi->rt.fd, xi->rt.size, quiet);
+ if (xi->rt.dev && !xi->rt.isfile) {
+ if (zt->rt.nr_zones)
+ reset_zones(xi->rt.fd, xi->rt.size, quiet);
+ else
+ discard_blocks(xi->rt.fd, xi->rt.size, quiet);
+ }
if (xi->log.dev && xi->log.dev != xi->data.dev && !xi->log.isfile)
discard_blocks(xi->log.fd, xi->log.size, quiet);
}
static void
validate_rtdev(
struct mkfs_params *cfg,
- struct cli_params *cli)
+ struct cli_params *cli,
+ struct zone_topology *zt)
{
struct libxfs_init *xi = cli->xi;
unsigned int rbmblocksize = cfg->blocksize;
reported by the device (%u).\n"),
cfg->sectorsize, xi->rt.bsize);
}
+ } else if (zt->rt.nr_zones) {
+ cfg->rtblocks = DTOBT(zt->rt.nr_zones * zt->rt.zone_capacity,
+ cfg->blocklog);
} else {
/* grab volume size */
cfg->rtblocks = DTOBT(xi->rt.size, cfg->blocklog);
return 0;
}
+#define XFS_MIN_ZONES 3 /* XXX: move to header */
+
static void
calculate_rtgroup_geometry(
struct mkfs_params *cfg,
- struct cli_params *cli)
+ struct cli_params *cli,
+ struct zone_topology *zt)
{
- if (!cli->sb_feat.rtgroups) {
- cfg->rgcount = 0;
- cfg->rgsize = 0;
- return;
- }
+ if (zt->rt.nr_zones) {
+ cfg->rgsize = zt->rt.zone_capacity * 512;
+ } else {
+ if (!cli->sb_feat.rtgroups) {
+ cfg->rgcount = 0;
+ cfg->rgsize = 0;
+ return;
+ }
- if (cli->rgsize) { /* User-specified rtgroup size */
- cfg->rgsize = getnum(cli->rgsize, &ropts, R_RGSIZE);
+ if (cli->rgsize) /* User-specified rtgroup size */
+ cfg->rgsize = getnum(cli->rgsize, &ropts, R_RGSIZE);
+ }
+ if (cfg->rgsize) {
/*
* Check specified agsize is a multiple of blocksize.
*/
XFS_MAX_RGNUMBER);
usage();
}
+ if (cfg->sb_feat.zoned && cfg->rgcount < XFS_MIN_ZONES) {
+ fprintf(stderr,
+_("realtime group count (%llu) must be greater than the minimum (%u)\n"),
+ (unsigned long long)cfg->rgcount,
+ XFS_MIN_ZONES);
+ usage();
+ }
}
static void
sbp->sb_rgcount = cfg->rgcount;
sbp->sb_rgblocks = cfg->rgsize;
}
+
+ if (fp->zoned)
+ sbp->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_ZONED;
}
/*
(xfs_extlen_t)XFS_FSB_TO_BB(mp, cfg->logblocks),
&sbp->sb_uuid, cfg->sb_feat.log_version,
lsunit, XLOG_FMT, XLOG_INIT_CYCLE, false);
-
/* finally, check we can write the last block in the realtime area */
- if (mp->m_rtdev_targp->bt_bdev && cfg->rtblocks > 0) {
+ if (mp->m_rtdev_targp->bt_bdev && cfg->rtblocks > 0 &&
+ !xfs_has_zoned(mp)) {
buf = alloc_write_buf(mp->m_rtdev_targp,
XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
BTOBB(cfg->blocksize));
*/
},
};
-
+ struct zone_topology zt = {};
struct list_head buffer_list;
int error;
sectorsize = cfg.sectorsize;
validate_log_sectorsize(&cfg, &cli, &dft, &ft);
+ validate_zoned(&cfg, &cli, &dft, &zt);
validate_sb_features(&cfg, &cli);
/*
validate_overwrite(xi.data.name, force_overwrite);
validate_datadev(&cfg, &cli);
validate_logdev(&cfg, &cli);
- validate_rtdev(&cfg, &cli);
+ validate_rtdev(&cfg, &cli, &zt);
calc_stripe_factors(&cfg, &cli, &ft);
/*
*/
calculate_initial_ag_geometry(&cfg, &cli, &xi);
align_ag_geometry(&cfg);
- calculate_rtgroup_geometry(&cfg, &cli);
+ calculate_rtgroup_geometry(&cfg, &cli, &zt);
calculate_imaxpct(&cfg, &cli);
* All values have been validated, discard the old device layout.
*/
if (discard && !dry_run)
- discard_devices(&xi, quiet);
+ discard_devices(&xi, &zt, quiet);
/*
* we need the libxfs buffer cache from here on in.