Skip to content

Port to libnvme3 - #1213

Open
igaw wants to merge 4 commits into
storaged-project:masterfrom
igaw:libnvme3
Open

igaw wants to merge 4 commits into
storaged-project:masterfrom
igaw:libnvme3

Conversation

@igaw

@igaw igaw commented Oct 11, 2026 •

Copy link
Copy Markdown

nvme-cli 3.0 merged libnvme into its tree and ships it as the new libnvme3 library (libnvme3.so.1) with a reworked API. libnvme-1.x is no longer developed, so this series ports the NVMe plugin over.

  • Port to libnvme3: devices are accessed through libnvme3 transport handles, commands are built with the nvme_init_*() helpers and connecting uses libnvmf_connect(). The "dhchap_key" and "dhchap_ctrl_key" extra arguments are renamed to "kxchap_secret" and "kxchap_ctrl_secret" following the KX-HMAC-CHAP rename in nvme-cli, the old names are kept as deprecated aliases. The test helpers now read sysfs as the nvme list JSON output changed.
  • Fabrics configuration: the "config" extra argument now reads the new INI based /etc/nvme/nvme-fabrics.conf. Legacy JSON files are no longer supported (nvme-cli converts them with nvme config-convert).
  • Controller ownership: connections made by bd_nvme_connect() are registered as owned by "libblockdev" (or the new "owner" extra argument) in the libnvme ownership registry. bd_nvme_disconnect() and bd_nvme_disconnect_by_path() only remove controllers owned by libblockdev, so e.g. NBFT boot volumes are left alone. The new bd_nvme_disconnect_full() disconnects controllers of another owner or, with BD_NVME_DISCONNECT_FORCE, regardless of the owner.

Behaviour changes: a second identical connection now fails with BD_NVME_ERROR_CONNECT_ALREADY unless "duplicate_connect" is set, and bd_nvme_disconnect() no longer removes controllers connected by others (BD_NVME_ERROR_OWNED).

Tested on Debian 12 (kernel 6.12) with nvme-cli 3.1 and the nvmet loop target: all 18 NVMe tests pass. The duplicate-connect test needs the libnvme topology scan fix from linux-nvme/nvme-cli (to be linked).

Fixes: #1211

Summary by CodeRabbit

  • New Features
    • Added ownership-aware NVMe disconnect options, including a force option and selection by subsystem or device path.
    • NVMe connections can now use INI configuration files and drop-ins, with connection options able to override configured values.
  • Improvements
    • NVMe device information retrieval and operations now use updated handling for device access and command errors.
  • Compatibility
    • Legacy JSON NVMe connection configuration is no longer supported.

igaw and others added 4 commits October 11, 2026 17:40
nvme-cli 3.0 merged libnvme into its tree and ships it as the new
libnvme3 library with a reworked API, libnvme-1.x is no longer
developed. Devices are now accessed through transport handles,
commands are built with the nvme_init_*() helpers and errors are
returned as negative errno values.

libnvme3 dropped support for the JSON configuration file, the "config"
extra argument is ignored for now.

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.

Note that libnvme3 refuses a second identical connection to an already
connected controller unless "duplicate_connect" is set. The tests now
look up controllers and namespaces in sysfs as the 'nvme list' JSON
output changed in nvme-cli 3.0.

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 anymore.

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

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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: storaged-project/libblockdev/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5c301c8a-1dab-4778-b477-921e4ae1ef9f

📥 Commits

Reviewing files that changed from the base of the PR and between fc8cfc5 and a84c869.


⛔ Files ignored due to path filters (1)
  • dist/libblockdev.spec.in is excluded by !**/dist/**

📒 Files selected for processing (11)
  • configure.ac
  • docs/libblockdev-sections.txt
  • src/lib/plugin_apis/nvme.api
  • src/plugins/nvme/nvme-error.c
  • src/plugins/nvme/nvme-fabrics.c
  • src/plugins/nvme/nvme-info.c
  • src/plugins/nvme/nvme-op.c
  • src/plugins/nvme/nvme-private.h
  • src/plugins/nvme/nvme.h
  • tests/nvme_test.py
  • tests/utils.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.



📝 Walkthrough

Walkthrough

The NVMe plugin now uses libnvme3 for device commands and fabrics connections. It adds owner-aware disconnect options and an API, updates NVMe configuration handling, and changes tests and documentation to cover the new behavior.

Changes

NVMe libnvme integration and controller ownership

Layer / File(s) Summary
libnvme device command handling
configure.ac, src/plugins/nvme/nvme-private.h, src/plugins/nvme/nvme-error.c, src/plugins/nvme/nvme-info.c, src/plugins/nvme/nvme-op.c
The build check now requires libnvme3 >= 1.0. Device information, self-test, format, and sanitize operations use libnvme handles and commands.
Fabrics configuration and connection
src/plugins/nvme/nvme-fabrics.c, src/lib/plugin_apis/nvme.api
Connection setup reads libnvme INI configuration, applies matching values and extra-argument overrides, and registers owners for new controllers. Topology and host identity helpers use libnvme global contexts.
Owner-aware disconnect API and validation
src/plugins/nvme/nvme-fabrics.c, src/plugins/nvme/nvme.h, src/lib/plugin_apis/nvme.api, docs/libblockdev-sections.txt, tests/nvme_test.py, tests/utils.py
The new full disconnect API selects controllers by subsystem or path and checks ownership unless forced. Tests cover ownership, argument validation, and sysfs-based NVMe device discovery.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to a84c8

The NVMe plugin is ported to libnvme3 with owner-aware disconnect support. The review found no concrete defect that should block merging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 59.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 8 files. (3 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: porting the NVMe plugin to libnvme3.
Linked Issues check Passed Issue [#1211] requires libblockdev to build with nvme-cli 3.0's libnvme3. The change updates configure.ac to require libnvme3 >= 1.0 and ports NVMe implementation code to libnvme3 APIs. The change…
Out of Scope Changes check Passed The changes stay within the libnvme3 port requested by [#1211]. Configuration, transport, command handling, ownership behavior, public API documentation, and supporting tests all implement or validate…

Full details: Docstring Coverage

Explanation

Docstring coverage is 59.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 8 files. (3 skipped: 3 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@igaw

igaw commented Oct 11, 2026

Copy link
Copy Markdown
Author

Depends on linux-nvme/nvme-cli#4157

This branch has not been deployed

No deployments
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.

fails to build with libnvme3 (nvme-cli 3.0)

1 participant