From nobody Mon Oct 19 06:24:40 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4j7QWF1rd3z6vsXb for ; Mon, 19 Oct 2026 06:24:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4j7QWD5xZqz3Pth for ; Mon, 19 Oct 2026 06:24:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792391080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GytbD2YBUXCNVkaE/KJZChlm60eMpa+K4TiFmOCGacI=; b=s/RvsqInsruwC3nZ9eiRxmkDm6oURWSq8ygpjK7ig7/1Ukipxh5EHwN98n419yGjOPOx5+ +Wcp3hOcXTqD6M9U1QWxfCHUXRPKuLgnN3Jq8YZbEJIisw7zyQxkumJZiKN44svrpPHV47 JQDrgx6u6KB2JaUTNldt9mxRUIUqCvKvPncHD07kac/4bWqr16r70mAdi2lhERJh9BNlsu 3NnUOLjfio4HhXSD2Vp4nAYxCty9GjyUo7nlvDvoBEPeTAY6s+/4XvPRbrynpjLBsLDvDn E7V0Hhcf3RjhrOLrpFqL2ZdcgHkiRmwgfhJqnK+s7ymIDck/E1rfDwYR7yZ7WQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792391080; b=WnU5uz6rVc28la0B+b1dfqTke+JGzPFDx/MrzXMbR6yYwto191ktevkF+F3iI9rlVrmBS3 fZ6bPZjayBd0xFq/cd6tG9yotMKDA76Zy5KiK18yCheThezEOwgQtXdfQOOJjhBVW0lZ0k yROkBPN1Omx02thidj/xhCsVPE6XttaqEmyahf4iVC98nvSVIL6iN0kVl8H8ZzRMaaTS2u vo/2jSbwa567xqIjpi3a8njbCLS3i7YIE0jeC0g4gx9pIHCwRQm8Slg/GCUZhCYEnzgizf eK6c35Oq99+Ai1L4fHbwWfjD7bcmF8qxQ3yQgu+lqT95+I5iZ1BEMALRsjglPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792391080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GytbD2YBUXCNVkaE/KJZChlm60eMpa+K4TiFmOCGacI=; b=hQOletVDHEoHP4rqv2aS8VHQH29a2EsWLQC31zbwhR0D9AoCKrRNNitLkFmsa3naGtDoT8 UNLchWuZxOQCADipZd9s0GGCsum4j/157yDwuO3IsR4+8RwxEOc74iY9uKb4ZyyWwxlRrm kUxHwwhBkADjYnLSP9HOUyOr6RcxZc4cTjq/stLuME7pSInhzMo04mku5qrMC/YYZA1/+9 vdAlq8OWlJA1lMteNftatb58bwD7pna04lRbzetePd7pdLaD/Jy4uV0kucVy5Wp2Mqvmwi QwiVjLfLicqP+x0R+bcrZXAzsYg37R+ug3Mtz0L3dZv45EZnIa7EW0h1/CRgOw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j7QWD5ZpGz1NqL for ; Mon, 19 Oct 2026 06:24:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 335db by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 19 Oct 2026 06:24:40 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 4623bbfe7bfc - main - nvmecontrol: select format by sector size List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4623bbfe7bfc81d2626a5c2a7a5cfb2ff15c0360 Auto-Submitted: auto-generated Date: Mon, 19 Oct 2026 06:24:40 +0000 Message-Id: <6ad5b7a8.335db.49cd49d0@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4623bbfe7bfc81d2626a5c2a7a5cfb2ff15c0360 commit 4623bbfe7bfc81d2626a5c2a7a5cfb2ff15c0360 Author: Warner Losh AuthorDate: 2026-10-19 04:42:12 +0000 Commit: Warner Losh CommitDate: 2026-10-19 06:22:51 +0000 nvmecontrol: select format by sector size Add automatic selection of lbaf value based on a single sector size. The lbas (the data sector size) is selected based on the power of 2 in the sector size, and the metadata size is selected by the remainder. If an lbaf matches these values is used, otherwise we exit with an error. When there's a tie, we prefer the higher performance. Manual selection of these values remains as well for times when we select incorrectly. Reviewed by: seuros, chuck Differential Revision: https://reviews.freebsd.org/D59833 --- sbin/nvmecontrol/format.c | 43 ++++++++++++++++++++++++++++++++++++++++-- sbin/nvmecontrol/nvmecontrol.8 | 11 +++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/sbin/nvmecontrol/format.c b/sbin/nvmecontrol/format.c index f339acc6e305..53f2f0a1bb0a 100644 --- a/sbin/nvmecontrol/format.c +++ b/sbin/nvmecontrol/format.c @@ -55,6 +55,7 @@ static struct options { uint32_t ms; uint32_t pi; uint32_t pil; + uint32_t sector_size; uint32_t ses; bool Eflag; bool Cflag; @@ -64,6 +65,7 @@ static struct options { .ms = NONE, .pi = NONE, .pil = NONE, + .sector_size = NONE, .ses = SES_NONE, .Eflag = false, .Cflag = false, @@ -84,7 +86,9 @@ static const struct opts format_opts[] = { "Protective information"), OPT("pil", 'l', arg_uint32, opt, pil, "Protective information location"), - OPT("ses", 's', arg_uint32, opt, ses, + OPT("sector-size", 's', arg_uint32, opt, sector_size, + "Sector size"), + OPT("ses", 0, arg_uint32, opt, ses, "Secure erase settings"), { NULL, 0, arg_none, NULL, NULL } }; @@ -118,18 +122,25 @@ format(const struct cmd *f, int argc, char *argv[]) const char *target; uint32_t nsid; int lbaf, ms, pi, pil, ses, fd; + int best_rp, i, lbads; + uint32_t sector_size; if (arg_parse(argc, argv, f)) return; if ((int)opt.Eflag + opt.Cflag + (opt.ses != SES_NONE) > 1) { fprintf(stderr, - "Only one of -E, -C or -s may be specified\n"); + "Only one of -E, -C or --ses may be specified\n"); arg_help(argc, argv, f); } target = opt.dev; lbaf = opt.lbaf; + sector_size = opt.sector_size; + if (lbaf >= 0 && sector_size != NONE) { + fprintf(stderr, "Only one of -f or -s may be specified\n"); + arg_help(argc, argv, f); + } ms = opt.ms; pi = opt.pi; pil = opt.pil; @@ -155,6 +166,8 @@ format(const struct cmd *f, int argc, char *argv[]) open_dev(path, &fd, 1, 1); } free(path); + if (sector_size != NONE && nsid == NVME_GLOBAL_NAMESPACE_TAG) + errx(EX_USAGE, "sector size requires a namespace target"); /* Check that controller can execute this command. */ if (read_controller_data(fd, &cd)) @@ -176,6 +189,32 @@ format(const struct cmd *f, int argc, char *argv[]) /* Try to keep previous namespace parameters. */ if (read_namespace_data(fd, nsid, &nsd)) errx(EX_IOERR, "Identify request failed"); + if (sector_size != NONE) { + if (sector_size == 0) + errx(EX_USAGE, "sector size must be non-zero"); + lbads = fls(sector_size) - 1; + lbaf = -1; + best_rp = 4; + for (i = 0; i <= nsd.nlbaf; i++) { + uint32_t format; + int rp; + + format = nsd.lbaf[i]; + if (NVMEV(NVME_NS_DATA_LBAF_LBADS, format) != lbads || + NVMEV(NVME_NS_DATA_LBAF_MS, format) != + sector_size % (1U << lbads)) + continue; + rp = NVMEV(NVME_NS_DATA_LBAF_RP, format); + if (rp < best_rp) { + lbaf = i; + best_rp = rp; + } + } + if (lbaf < 0) + errx(EX_USAGE, + "namespace does not support sector size %u", + sector_size); + } if (lbaf < 0) lbaf = nvme_ns_data_format_index(&nsd); if (lbaf > nsd.nlbaf) diff --git a/sbin/nvmecontrol/nvmecontrol.8 b/sbin/nvmecontrol/nvmecontrol.8 index 97e995967269..c80dac444774 100644 --- a/sbin/nvmecontrol/nvmecontrol.8 +++ b/sbin/nvmecontrol/nvmecontrol.8 @@ -154,6 +154,7 @@ .Nm .Ic format .Op Fl f Ar fmt +.Op Fl s Ar sector-size .Op Fl m Ar mset .Op Fl p Ar pi .Op Fl l Ar pil @@ -511,6 +512,16 @@ of the parameters to use. LBA Format #, as specified in the identification of the namespace using .Dq nvmecontrol identify command with a namespace specified maps this index into these parameters. +.It Fl s Ar sector-size +Select the LBA format matching the specified total sector size. +The data size is the largest power of two not greater than +.Ar sector-size , +and any remainder is the metadata size. +If multiple LBA formats match, the one with the best relative performance is +selected, with the lowest format index used to break ties. +This option may only be used when formatting a namespace and is mutually +exclusive with +.Fl f . .It Fl m Ar mset Metadata Setting. .Ar mset