2025-02-15 08:44:15 +01:00
# libnvme
2025-02-16 10:12:19 +01:00


2025-02-15 08:44:15 +01:00
[](https://pypi.org/project/libnvme/)
[](https://pypi.org/project/libnvme/)

[](https://codecov.io/gh/linux-nvme/libnvme)
[](https://libnvme.readthedocs.io/en/latest/)
This is the libnvme development C library. libnvme provides type
definitions for NVMe specification structures, enumerations, and bit
fields, helper functions to construct, dispatch, and decode commands
and payloads, and utilities to connect, scan, and manage nvme devices
on a Linux system.
The public specification is the authority to resolve any protocol
2025-02-16 10:09:15 +01:00
discrepancies with this library. For more info on NVM Express, please
2025-02-15 08:44:15 +01:00
see:
2025-02-16 10:03:28 +01:00
https://nvmexpress.org
2025-02-15 08:44:15 +01:00
Subscribe to linux-nvme@lists .infradead.org for linux-nvme related
discussions and development for both kernel and userspace. The list is
archived here:
2025-02-16 10:03:28 +01:00
https://lists.infradead.org/mailman/listinfo/linux-nvme
2025-02-15 08:44:15 +01:00
# License
Except where otherwise stated, all software contained within this repo
2025-02-16 10:03:28 +01:00
is currently licensed LGPL-2.1-or-later, see COPYING for more
information.
2025-02-15 08:44:15 +01:00
Keith Busch 2020-02-06
------
2025-02-16 10:09:15 +01:00
# Dependency
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
libnvme depends on minimum Linux kernel version v4.15, which
introduced the /sys/class/nvme-subsystem.
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
# Build from source
## Prerequisite
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
A minimal build depends on a set of build tools
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
- gcc
- ninja
- meson
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
Not all feature will be present with such configuration, e.g.
the fabrics part of the library wont support authentication or
TLS over the nvme-tcp transport.
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
To enable the optional features install following libraries
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
`/etc/nvme/config.json` ` support:
- json-c (recommend)
2025-02-16 10:03:28 +01:00
2025-02-16 10:09:15 +01:00
Authentication and TLS over nvme-tcp:
- openssl
- keyutils
2025-02-16 10:03:28 +01:00
2025-02-16 10:09:15 +01:00
End point discovery for MI
- libdbus
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
Python bindings
- Python 3 interpreter
- Python 3 development libraries
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
## Minimal on embedded builds
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
The reference implemention of the Meson specification is in Python 3. Installing
or porting this dependency is not really feasible for embedded project. Though
there are two project which implement the Ninja and the Meson API in pure C99
2025-02-15 08:44:15 +01:00
2025-02-16 10:09:15 +01:00
- samurai: https://github.com/michaelforney/samurai.git
- muon: https://git.sr.ht/~lattis/muon
2025-02-15 08:44:15 +01:00
2025-02-16 10:16:49 +01:00
The CI build helper script `scripts/build.sh` is able to setup and build this
project in a minimal setup using samurai and muon and thus only depending on:
- gcc
- make
- git
`scripts/build.sh -m muon`
2025-02-15 08:44:15 +01:00
## To compile libnvme
To `configure` the project:
```
2025-02-16 10:07:22 +01:00
meson setup .build
2025-02-15 08:44:15 +01:00
```
Which will default to build a shared library. To configure for static libraries call
```
2025-02-16 10:09:15 +01:00
meson setup --default-library=static .build
2025-02-15 08:44:15 +01:00
```
One nice feature of meson is that it doesn't mix build artifacts
(e.g. `*.o` , `*.so` , etc.) with source code. In the above example,
"`.build` " is the name of the directory where the build configuration
as well as all the build artifacts will be saved. This directory can
be named anything as long as it's not an existing source directory. To
completely "clean" all the build artifacts, one need only delete the
`.build` directory.
To compile:
```
2025-02-16 10:12:19 +01:00
meson compile -C .build
2025-02-15 08:44:15 +01:00
```
## To install libnvme
To install `libnvme` :
```
2025-02-16 10:09:15 +01:00
meson install -C .build
2025-02-15 08:44:15 +01:00
```
## To run unit tests
To run unit tests:
```
2025-02-16 10:09:15 +01:00
meson test -C .build
2025-02-15 08:44:15 +01:00
```
## To purge everything
To completely clean all build artifacts, including the build configuration.
```
rm -rf .build
```
## Supported build options
A few build options can be specified on the command line when invoking meson.
2025-02-16 10:09:15 +01:00
| Option | Values [default] | Description |
| ----------- | ------------------------- | ------------------------------------------------------------ |
| version-tag | none | Overwrite the git version string in the binary |
| htmldir | none | Installation directory for the HTML documentation |
| rstdir | none | Installation directory for the RST documentation |
| docs | [false], html, man, rst, all | Install documentation |
| docs-build | [false], true | Enable build documentation |
2025-02-16 10:07:22 +01:00
| python | [auto], enabled, disabled | Whether to build the Python bindings. When set to `auto` , the default, meson will check for the presence of the tools and libraries (e.g. `swig` ) required to build the Python bindings. If found, meson will configure the project to build the Python bindings. If a tool or library is missing, then the Python bindings won't be built. Setting this to `enabled` , forces the Python bindings to be built. When set to `disabled` , meson will configure the project to not build the Python bindings.< br /> Example: `meson setup .build -Dpython=disabled` |
2025-02-16 10:12:19 +01:00
| openssl | [auto], enabled, disabled | Enables OpenSSL dependent features (e.g. TLS over TCP), adds build dependency on OpenSSL |
| libdbus | auto, enabled, [disabled] | Enables D-Bus dependent features (libnvme-mi: End point discovery), adds build dependency on libdbus |
2025-02-16 10:09:15 +01:00
| json-c | [auto], enabled, disabled | (recommended) Enables JSON-C dependend features (e.g. config.json parsing), adds build depdency on json-c |
2025-02-16 10:12:19 +01:00
| keyutils | [auto], enabled, disabled | Enables keyutils dependent features (e.g. authentication), adds build dependency on keyutils |
2025-02-16 10:09:15 +01:00
See the full configuration options with
```bash
meson configure .build
```
2025-02-15 08:44:15 +01:00
### Changing the build options from the command-line (i.e. w/o modifying any files)
To configure a build for debugging purposes (i.e. optimization turned
off and debug symbols enabled):
```bash
2025-02-16 10:07:22 +01:00
meson setup .build --buildtype=debug
2025-02-15 08:44:15 +01:00
```
To enable address sanitizer (advanced debugging of memory issues):
```bash
2025-02-16 10:07:22 +01:00
meson setup .build -Db_sanitize=address
2025-02-15 08:44:15 +01:00
```
2025-02-16 10:16:49 +01:00
This option adds `-fsanitize=address` to the gcc options. The tests can then be run normally (`meson test -C .build` ).
Note that when using the sanitize feature, the library `libasan.so` must be available and must be the very first library loaded when running an executable. If experiencing linking issues, you can ensure that `libasan.so` gets loaded first with the `LD_PRELOAD` environment variable as follows:
2025-02-15 08:44:15 +01:00
```
2025-02-16 10:09:15 +01:00
meson setup .build -Db_sanitize=address & & LD_PRELOAD=/lib64/libasan.so.6 ninja -C .build test
2025-02-15 08:44:15 +01:00
```
2025-02-16 10:16:49 +01:00
It's also possible to enable the undefined behavior sanitizer with `-Db_sanitize=undefined` . To enable both, use `-Db_sanitize=address,undefined` .