Skip to content

[CI only] nvme: libnvme3 backends - #1

Draft
dwsuse wants to merge 7 commits into
masterfrom
libnvme3-backends
Draft

dwsuse wants to merge 7 commits into
masterfrom
libnvme3-backends

Conversation

@dwsuse

@dwsuse dwsuse commented Oct 19, 2026

Copy link
Copy Markdown
Owner

CI run on the fork for storaged-project#1216, the upstream workflows need maintainer approval there. Not for merging.

🤖 Generated with Claude Code

dwsuse and others added 7 commits October 19, 2026 14:03
Command dwords of passthru commands are passed in CPU byte order,
the kernel takes care of the conversion. Converting the pattern
to little endian beforehand swapped it twice on big endian
architectures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 'nvme list' JSON output differs between nvme-cli versions and
changed again in nvme-cli 3.0. Read the controllers and namespaces
of a subsystem from sysfs instead, which works independent of the
installed nvme-cli version.

The kernel scans namespaces asynchronously after the controller went
live, allow waiting for the expected number of namespaces to show up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libnvme-1.x is replaced by libnvme3 shipped with nvme-cli 3.x, which
comes with a reworked API. As libblockdev is often backported to
older distributions, both libraries need to be supported for a while.

Instead of sprinkling #ifdefs over the plugin, introduce an internal
backend API (nvme-backend.h) and move all the libnvme calls to a
libnvme-1.x implementation of it (nvme-libnvme1.c). The generic code
only uses the NVMe specification types, constants and static inline
helpers from the libnvme headers, which are compatible between both
libraries. The few constants renamed in libnvme3 to follow the NVMe
specification are mapped in nvme-libnvme1.h.

The backend returns negative errno values on failure, as libnvme3
does, instead of -1 with errno set. The extra arguments of
bd_nvme_connect() are parsed by the generic code, and the topology
is passed as a snapshot to the generic lookup functions.

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nvme-cli 3.0 merged libnvme into its tree and ships it as the new
libnvme3 library with a reworked API. Devices are accessed through
transport handles, commands are built with the nvme_init_*() helpers
and errors are returned as negative errno values.

Add a libnvme3 implementation of the backend API. The libnvme flavour
is selected at build time with the new --with-libnvme configure
option, by default libnvme3 is used when available.

libnvme3 requires 3.2 or later. The Identify Controller bit field
constants use the NVMe spec names since nvme-cli 3.2, e.g.
NVME_CTRL_MEC_TWPME, NVME_CTRL_OACS_FNVMS, NVME_CTRL_OACS_NMS and
NVME_CTRL_OACS_DSTS. Since 3.2, libnvme3.pc reports the nvme-cli
release version, earlier releases report 1.0.0, the library ABI
version.

Following the DH-HMAC-CHAP to KX-HMAC-CHAP rename in nvme-cli, the
"dhchap_key" and "dhchap_ctrl_key" extra arguments are now called
"kxchap_secret" and "kxchap_ctrl_secret". The old names are kept as
deprecated aliases.

The configuration file is not supported with libnvme3 yet, libnvme3
dropped support for the JSON configuration file. Also note libnvme3
refuses a second identical connection to an already connected
controller unless "duplicate_connect" is set.

Resolves: storaged-project#1211

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libnvme3 replaced the JSON configuration with an INI based
/etc/nvme/nvme-fabrics.conf. Parameters of the first connection
entry matching the bd_nvme_connect() arguments are applied, extra
arguments still take precedence. Legacy JSON configuration files
are not supported with libnvme3.

nvme-cli converts an existing /etc/nvme/config.json to the INI
format on its first fabrics command, but libnvme3 doesn't, and
libblockdev doesn't either. Log a warning pointing to
'nvme config-convert' when the default configuration is used and
an unconverted legacy file is found, as its options and keys would
be silently ignored otherwise. A JSON file specified via the "config"
extra argument fails to parse, mention the conversion in the error.

libnvme3 treats a missing configuration file as an empty one, which
is fine for the default file only. A missing file specified via the
"config" extra argument is reported as an error.

The libnvme-1.x backend keeps reading the JSON configuration file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libnvme3 keeps track of the owner of each connected NVMe-oF
controller, e.g. boot volumes connected from the NBFT are owned
by "nbft". Previously bd_nvme_disconnect() removed all matching
controllers, including the ones other components depend on.

With libnvme3, controllers connected by bd_nvme_connect() are now
registered as owned by "libblockdev" (or by the new "owner" extra
argument) and bd_nvme_disconnect() and bd_nvme_disconnect_by_path()
only remove controllers owned by libblockdev. An already connected
controller is never claimed.

The new bd_nvme_disconnect_full() function allows to disconnect
controllers of a different owner or, with BD_NVME_DISCONNECT_FORCE,
regardless of their owner.

libnvme-1.x has no ownership registry, the libnvme-1.x backend keeps
disconnecting all matching controllers and ignores the owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bd_nvme_disconnect() and bd_nvme_disconnect_by_path() called with
NULL matched every NVMe-oF controller and disconnected all of them,
including boot volumes or the root filesystem. This is how the code
always behaved, but neither argument is nullable and disconnecting
everything is the worst possible reaction to a programming error.

Require exactly one of the subsystem NQN and the controller path for
all disconnect functions, as bd_nvme_disconnect_full() already does.
Bindings like PyGObject reject NULL for these arguments anyway, only
C callers are affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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