Expand description
Safe, idiomatic Rust bindings for the Linux libnvme C library.
libnvme is the userspace library that backs nvme-cli. This crate exposes
a memory-safe wrapper over its handle tree:
Root → Host → Subsystem → Controller → NamespaceEvery handle borrows from the Root via the 'r lifetime, so dropping
the Root cascades-frees the entire tree.
§Example
use libnvme::Root;
let root = Root::scan()?;
for host in root.hosts() {
for subsys in host.subsystems() {
for ctrl in subsys.controllers() {
println!("{} {}", ctrl.name()?, ctrl.model()?);
let id = ctrl.identify()?;
println!(" NVMe spec: {}", id.nvme_version());
for ns in ctrl.namespaces() {
println!(" {} ({} bytes)", ns.name()?, ns.size_bytes());
}
}
}
}Structs§
- Compare
- Builder returned by
Namespace::compare. - Connect
- Builder for an NVMe-oF Connect operation.
- Controller
- An NVMe controller.
- Controllers
- Iterator over
Controllerentries, returned bycrate::Subsystem::controllers. - Copy
- Builder returned by
Namespace::copy. - Copy
Range - One source range for the NVMe Copy command (format 0).
- Directive
Recv - Builder returned by
Namespace::directive_recv. - Directive
Send - Builder returned by
Namespace::directive_send. - Discovery
Log - Discovery-log header + entries returned by a discovery controller’s log page (LID 0x70).
- Discovery
LogEntry - One entry from the discovery log page.
- Dsm
- Builder returned by
Namespace::dsm. - DsmAttr
- DSM attribute bits (CDW11). Combine with
|. - DsmRange
- One DSM range entry. NVMe spec: each entry covers up to 4 GiB of LBAs.
- Error
LogEntry - One entry from the Error Information log page (LID 01h).
- Features
- Get/Set Features accessor for a controller.
- Firmware
Slot Log - Firmware Slot Information log page (LID 03h).
- Format
- Builder for the Format NVM admin command.
- GetLba
Status Args - Parameters for Get LBA Status (NVMe 1.4+).
- Host
- A host entry in the libnvme tree.
- Hosts
- Iterator over
Hostentries, returned byRoot::hosts. - Identify
Controller - Decoded Identify Controller (CNS 01h) data structure.
- Identify
Namespace - Decoded Identify Namespace (CNS 00h) data structure.
- LbaFormat
- One LBA format entry from Identify Namespace.
- Lockdown
Args - Parameters for the Lockdown admin command (NVMe 2.0+).
- Namespace
- An NVMe namespace.
- Namespaces
- Iterator over
Namespaceentries reachable through acrate::Controller. - Nvme
Version - Decoded NVMe specification version, as reported by the controller’s
VERregister and thevsfield of Identify Controller. - Passthru
Args - Parameters for
Controller::admin_passthru/Controller::io_passthru. - Path
- A single multipath route to a namespace.
- Paths
- Iterator over
Pathentries reachable through aControllerorNamespace. - Read
- Builder returned by
Namespace::read. - Reservation
Acquire - Builder returned by
Namespace::reservation_acquire. - Reservation
Register - Builder returned by
Namespace::reservation_register. - Reservation
Release - Builder returned by
Namespace::reservation_release. - Reservation
Report - Builder returned by
Namespace::reservation_report. - Root
- The owning handle to the libnvme tree.
- Sanitize
- Builder for the Sanitize NVM admin command.
- Smart
Log - Decoded SMART / Health Information log page (LID 02h).
- Subsystem
- An NVMe subsystem.
- Subsystems
- Iterator over
Subsystementries, returned bycrate::Host::subsystems. - Verify
- Builder returned by
Namespace::verify. - Write
- Builder returned by
Namespace::write. - Write
Uncorrectable - Builder returned by
Namespace::write_uncorrectable. - Write
Zeroes - Builder returned by
Namespace::write_zeroes. - ZnsAppend
- Builder returned by
Namespace::zns_append. - ZnsMgmt
Recv - Builder returned by
Namespace::zns_mgmt_recv. - ZnsMgmt
Send - Builder returned by
Namespace::zns_mgmt_send.
Enums§
- Directive
Recv Op - Directive Receive Operation (doper).
- Directive
Send Op - Directive Send Operation (doper).
- Directive
Type - Directive Type (dtype).
- Error
- Errors returned by this crate.
- Feature
Select - Which “view” of a feature value the Get Features command should return.
- Firmware
Action - What the firmware-commit admin command should do with the slot it targets.
- Metadata
Settings - How metadata is transferred relative to LBA data.
- Protection
Info - End-to-end Data Protection type to apply when formatting.
- Protection
Location - Where the PI guard bytes sit within each LBA.
- Ptpl
Change - Change-Persist-Through-Power-Loss (cptpl) for Reservation Register.
- Reservation
Acquire Action - Reservation Acquire action (racqa).
- Reservation
Register Action - Reservation Register action (rrega).
- Reservation
Release Action - Reservation Release action (rrela).
- Reservation
Type - Reservation type (rtype) — sets the access semantics for the reservation holder vs. registered hosts vs. non-registered hosts.
- Sanitize
Action - Sanitize action — what the Sanitize admin command should do to the drive’s user data area.
- Secure
Erase - How user data should be erased during a Format NVM operation.
- Self
Test Action - Self-test action for the Device Self-Test admin command.
- Transport
- NVMe-oF transport selector. The
Othervariant is an escape hatch for transports added to libnvme after this crate was released. - Zone
Recv Action - Zone Receive Action (zra).
- Zone
Report Filter - Report-zones filter (ZRASF, zone-receive action-specific field).
- Zone
Send Action - Zone Send Action (zsa).
Functions§
- generate_
hostid - Generate a fresh HostID (random UUID, formatted as a hex string).
- generate_
hostnqn - Generate a fresh HostNQN (NVMe spec format, embeds a freshly-generated UUID).
Equivalent to libnvme’s
nvmf_hostnqn_generate. Returned string is owned. - hostid_
from_ file - Read the local HostID from
/etc/nvme/hostidif it exists. - hostnqn_
from_ file - Read the local HostNQN from
/etc/nvme/hostnqnif it exists.
Type Aliases§
- AutoPst
- Host
Behavior - Host
MemBuf Attrs - LbaRange
Type - PlmConfig
- Result
- Result type alias for fallible operations in this crate.
- Timestamp