wzcheng99 e00d725cb5 T2 ckpt 8 follow-up: enforce --nvme-ns + --nvme-subsysnqn on the wire
Two architect-review findings (round-7) closed:

Finding 1: --nvme-ns was a dead flag.
  cmd/blockvolume accepted --nvme-ns N but built TargetConfig with
  zero-value Handler, so the IOHandler always defaulted to NSID=1.
  An operator running --nvme-ns 7 got a target that still rejected
  every command targeting NSID=7.

  Fix (cmd/blockvolume/main.go):
    Handler: nvme.HandlerConfig{NSID: uint32(f.nvmeNS)}
    threaded through TargetConfig so the configured value reaches
    the per-session handler.

Finding 2: --nvme-subsysnqn was advertised but not enforced.
  Target.SubsysNQN was metadata-only; the wire-level Fabric Connect
  accepted any host's SubNQN. A host could connect with an
  arbitrary subsystem name and still get IO service — multi-target
  routing and operator intent ambiguous.

  Fix (core/frontend/nvme/session.go + target.go + errors.go):
    - Session.expectedSubNQN field, plumbed via newSession().
    - Target.handleConn passes t.cfg.SubsysNQN into newSession.
    - handleFabric rejects mismatched SubNQN with
      SCT=Command Specific (1) + SC=ConnectInvalidParameters (0x80)
      per NVMe-oF spec §3.3.1. New SC constants in errors.go:
      SCConnectInvalidParameters / SCConnectControllerBusy /
      SCConnectInvalidHost.
    - Empty Session.expectedSubNQN preserves "no enforcement"
      contract for in-process L1 tests that don't pin a subsystem
      identity. cmd/blockvolume always sets SubsysNQN (already
      required at startup), so production is always enforced.

core/frontend/nvme/identity_enforcement_test.go (NEW, sw regression)
  4 tests pin both fixes:
    - TestT2NVMe_HandlerHonorsConfiguredNSID:
        handler-level — IOHandler with NSID=7 rejects NSID=1
        commands with Generic/InvalidField, backend not invoked.
    - TestT2Process_NVMe_TargetHandlerNSIDConfigPropagates:
        wire-level — Target with HandlerConfig.NSID=7 rejects
        client Write at NSID=1; status decode confirms wire bits
        SCT=0 SC=0x02. Backend not invoked.
    - TestT2Process_NVMe_ConnectWithWrongSubNQN_Rejected:
        low-level capsule write with wrong SubNQN; assert
        wire status SCT=1 SC=0x80 (ConnectInvalidParameters).
    - TestT2NVMe_EmptySubsysNQN_AcceptsAnyConnect:
        regression for the in-process L1 path — empty target
        SubsysNQN admits any Connect (preserves L1 test setup).

Tests green (no regressions):
  core/frontend/nvme: 26 tests (was 22; +4 enforcement regressions)
  All other packages: unchanged.

Sign-off impact: T2B-NVMe-provisional unchanged (still QA + sw lead);
follow-up tightens identity wiring per architect feedback before
T2-closed L2-OS work begins.
2026-04-21 21:28:26 -07:00
Languages
Go 84.6%
Rust 7.8%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%