git: 38c1b30fdb59 - releng/15.2 - ctld: Fix namespace IDs for exported NVMe namespaces

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Thu, 19 Nov 2026 16:04:59 UTC
The branch releng/15.2 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=38c1b30fdb59d062984d7aacfaf5a7da76ebb9c9

commit 38c1b30fdb59d062984d7aacfaf5a7da76ebb9c9
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2026-10-08 15:24:45 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-11-19 16:04:28 +0000

    ctld: Fix namespace IDs for exported NVMe namespaces
    
    NVMe namespace IDs are 1-based, but CTL LUN IDs are 0-based.  The
    in-kernel NVMe ctl(4) target accounts for this by adding one to the
    LUN ID to compute a namespace ID.  ctld was attempting to handle this
    by translating namespace IDs from config files to internal LUN IDs,
    but it did this incorrectly resulting in the namespace configured for
    as namespace N actually showing up as namespace N + 1.
    
    Approved by:    re (cperciva)
    Fixes:          66b5296f1b29 ("ctld: Add support for NVMe over Fabrics")
    Sponsored by:   Chelsio Communications
    (cherry picked from commit 9c8be6518e2e5f396055ecdab8098ce19c4b2218)
    (cherry picked from commit 033c0cd3e89ba87f3d66ceea6436cf2a37148051)
---
 usr.sbin/ctld/nvmf.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/ctld/nvmf.cc b/usr.sbin/ctld/nvmf.cc
index e1ecf8ccc552..a596d32d660c 100644
--- a/usr.sbin/ctld/nvmf.cc
+++ b/usr.sbin/ctld/nvmf.cc
@@ -371,8 +371,8 @@ nvmf_controller::add_namespace(u_int id, const char *lun_name)
 		return false;
 	}
 
-	std::string lun_label = "namespace ID " + std::to_string(id - 1);
-	return target::add_lun(id, lun_label.c_str(), lun_name);
+	std::string lun_label = "namespace ID " + std::to_string(id);
+	return target::add_lun(id - 1, lun_label.c_str(), lun_name);
 }
 
 bool