Getting Started#

Here you will be taken through the process of Building and installing xNVMe, which includes retrieving the xNVMe source, installing a C compiler / toolchain, libraries, and then building and installing xNVMe itself. With xNVMe in place on your system, an Example Program is provided for you to Compile, link, and run!.

Building and installing#

Below are examples of building and installing xNVMe on different operating systems. Additional examples and detailed information can be found in the Toolchain section, covering numerous Linux distributions, as well as FreeBSD, macOS, and Windows versions.

# Clone the xNVMe repos
git clone https://github.com/xnvme/xnvme.git
cd xnvme

# Install toolchain and libraries on Linux (Debian Bookworm)
sudo ./toolbox/pkgs/debian-bookworm.sh

# configure xNVMe and build meson subprojects(SPDK)
meson setup builddir

# build xNVMe
meson compile -C builddir

# install xNVMe
sudo meson install -C builddir

# uninstall xNVMe
# cd builddir && meson --internal uninstall

Building system software can be challenging. If you encounter errors when following the steps above, and if meson is new to you, a couple of pointers are provided to help you out. You can also look at the Troubleshooting section for known issues.

Build-errors

Details on the build errors can be seen by inspecting the log file at builddir/meson-logs/meson-log.txt.

Rebuilding

In case rebuilding fails, e.g., due to errors during meson setup or missing toolchain/dependencies, remove the builddir folder. If errors persist, try also removing the SPDK subproject at subprojects/spdk.

Customizing-the-build

If you want to customize the build, e.g., install into a different location, this is handled by meson built-in options. In addition, you can inspect meson_options.txt which contains options specific to xNVMe.

Example Program#

This example code illustrates how to use the xNVMe library (libxnvme) in C to perform the following tasks with an NVMe device: open the device, probe and retrieve device information, print device information, and finally close the device.

#include <errno.h>
#include <libxnvme.h>

int
main(int argc, char **argv)
{
	struct xnvme_opts opts = xnvme_opts_default();
	struct xnvme_dev *dev;

	if (argc < 2) {
		xnvme_cli_perr("Usage: %s <identifer>", EINVAL);
		return 1;
	}

	dev = xnvme_dev_open(argv[1], &opts);
	if (!dev) {
		xnvme_cli_perr("xnvme_dev_open()", errno);
		return 1;
	}

	if (xnvme_dev_derive_geo(dev)) {
		printf("Failed deriving geometry, check your permissions.");
	}
	xnvme_dev_pr(dev, XNVME_PR_DEF);
	xnvme_dev_close(dev);

	return 0;
}

Additional examples of using the xNVMe C API can be found in the xNVMe repository. This includes explicit example code, the source for the command-line tools, and tests. For examples of efficient and high-performance integration, refer to the fio xNVMe I/O engine and the SPDK xNVMe bdev module.

Furthermore, while the example given above is written in C, bindings for the xNVMe C API are also available for other languages. These include Python ( Pypi ) bindings and Rust ( crates.io ) bindings.

Troubleshooting#

This section is here to give you pointers to troubleshoot whether xNVMe or your system is misbehaving. First off ensure that you are you have the setup your system, please refer to the Toolchain section for details on installing compilers, libraries etc. and the Backends section on notes on system configuration and runtime instrumentation of the library backends.

Should you not find the answers you are looking here, then please reach out by raising an issue or go to Discord for synchronous interaction.

Build Errors#

xNVMe adheres to best practices and conventions for system software. It links with other libraries available on the system and downgrades functionality to disable dependent modules if a library is unavailable. However, xNVMe diverges in one area: the subproject build of SPDK. In this case, xNVMe retrieves the SPDK repository, patches the source, and builds it for linkage with xNVMe. Consequently, most reported issues are related to this process and are addressed accordingly.

Shallow source-archive#

If you are getting errors while attempting to configure and build xNVMe then it is likely due to one of the following:

  • You are building in an offline environment and only have a shallow source-archive or a git-repository without subprojects.

The full source-archive is made available with each release and downloadable from the GitHUB Release page release page. It contains the xNVMe source code along with all the third-party subproject source of SPDK.

Missing dependencies / toolchain#

  • You are missing dependencies, see the Toolchain for installing these on FreeBSD and a handful of different Linux Distributions

Once you have the full source of xNVMe, third-party library dependencies, and setup the toolchain then run the following to ensure that the xNVMe repository is clean from any artifacts left behind by previous build failures:

make clobber

And then go back to the Building and installing and follow the steps there.

Note

When running make clobber then everything not comitted is “lost”. Thus, if you are developing/modifying xNVMe, then make you commit of stash your changes before running it.