From 0bc0c325b121d6f0f3764f884b8861b726feb9a2 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 12 Dec 2024 07:54:55 +0100 Subject: [PATCH] xfs_mkfs: limit user capacity to explicitly requested size When rounding up the size specified on the command line to the zone capacity, the extra blocks are currently added to the user capacity. Switch to adding them to the reserved blocks instead so that the user capacity exactly matches what the user requested. Signed-off-by: Christoph Hellwig --- mkfs/xfs_mkfs.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 795657ff4..a2255bcad 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -4168,6 +4168,7 @@ adjust_nr_zones( struct zone_topology *zt) { struct libxfs_init *xi = cli->xi; + uint64_t new_rtblocks, slack; unsigned int max_zones; if (zt->rt.nr_zones) @@ -4183,8 +4184,18 @@ _("Warning: not enough zones for backing requested rt size due to\n" "over-provisioning needs, writeable size will be less than %s\n"), cli->rtsize); } - cfg->rtblocks = (cfg->rgcount * cfg->rgsize); + new_rtblocks = (cfg->rgcount * cfg->rgsize); + slack = (new_rtblocks - cfg->rtblocks) % cfg->rgsize; + + cfg->rtblocks = new_rtblocks; cfg->rtextents = cfg->rtblocks / cfg->rtextblocks; + + /* + * Add the slack to the end of the last zone to the reserved blocks. + * This ensures the visible user capacity is exactly the one that the + * user asked for. + */ + cfg->rtreserved += (slack * cfg->blocksize); } static void -- 2.50.1