Skip to content

cli/libnvme: add --idempotent and --devid-file to nvme connect#3573

Open
martin-belanger wants to merge 3 commits into
linux-nvme:masterfrom
martin-belanger:nvme-connect-idempotent-devid
Open

cli/libnvme: add --idempotent and --devid-file to nvme connect#3573
martin-belanger wants to merge 3 commits into
linux-nvme:masterfrom
martin-belanger:nvme-connect-idempotent-devid

Conversation

@martin-belanger

Copy link
Copy Markdown

Prep patch for nvme-discoverd (not yet upstreamed). discoverd manages each fabrics connection as a systemd transient unit whose ExecStart= is nvme connect:

  • --idempotent exits 0 when the target is already connected, instead of 1 — otherwise a harmless race with an existing connection fails the unit.
  • --devid-file FILE names a file libnvmf_connect() writes the kernel-assigned device name (e.g. nvme0) to on success, so the unit's ExecStop= can find it again to disconnect.

Three commits:

  1. libnvme/fabrics: write the connected device name to a file on request — devid_file is sanitized and confined to a reserved RUNDIR "/nvme/devid" subdirectory for security.
  2. cli/fabrics: add --idempotent and --devid-file to nvme connect — the CLI options themselves.
  3. meson: stop deriving RUNDIR from --prefix — found while testing: RUNDIR was join_paths(prefix, get_option('rundir')), so any build silently got <prefix>/run instead of the real /run tmpfs. /run isn't an install path, so it's now hardcoded, the same way systemd does it.

Martin Belanger added 3 commits July 10, 2026 15:39
Give a caller that manages a fabrics connection as a supervised
process (e.g. a systemd transient unit) a way to recover the
kernel-assigned device name later, e.g. to disconnect. Writing it
from inside libnvmf_connect() means every path out with a live
controller -- freshly connected, found already connected in the
topology already scanned, or found already connected only after a
kernel-race rescan -- reuses the same controller-matching logic
libnvme already relies on, rather than a caller re-deriving it.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
nvme-discoverd manages each fabrics connection as a systemd transient
unit whose ExecStart is "nvme connect". Without --idempotent, a
connect that races with an existing connection exits 1 and fails the
unit even though the target is reachable. --devid-file names the file
libnvmf_connect() writes the kernel-assigned device name to, so the
unit's ExecStop can find it again to disconnect.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
RUNDIR was join_paths(prefix, get_option('rundir')), so any build
without an explicit -Drundir=/run override (this project's own
scripts/build.sh included) silently got <prefix>/run instead of the
real /run tmpfs -- e.g. /usr/local/run on a stock local build. /run is
not an install path: its location is fixed system-wide by the kernel
and the FHS, the same reason systemd hardcodes it rather than deriving
it from --prefix. Test isolation is a separate, already-solved runtime
concern (libnvme_set_test_base_dir()/LIBNVME_TEST_BASE_DIR), so the
build option bought nothing but a second way to get this wrong.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
@martin-belanger martin-belanger force-pushed the nvme-connect-idempotent-devid branch from 6c87db5 to 2d9774a Compare July 10, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant